rplusplus 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1f11712f1e2e7bfb1949089f363d8e99bd588125
4
- data.tar.gz: e21fa0e4daaf9185ea35878a74e3ee7905817f4e
3
+ metadata.gz: 446702f23e9654cb84e635114fa2b9d27fc3e2a2
4
+ data.tar.gz: bccd78bcfb59ba820bdebab6f61ca2652cf7b46a
5
5
  SHA512:
6
- metadata.gz: c14309834c20d92ca82239aba502400cc64e12ec74916a3c43c8a06484a8b141feb46aa550b58b2ff18282125043716e4a556b0695f5145769148e4cc6fe9662
7
- data.tar.gz: d6d06c50765b6a6078971ad2644b957bdc4558054bfbef4b33dd62998b776accd692bb9499c75ee77d3f1938c1ad662662977defafd509bb503f48d2ec980396
6
+ metadata.gz: 458624828a67224493f6023640750ecb14a78addd9cf6f3e1b6169f86bd1ec9afff3e0119268364c68386a4d870739e11174bd61e1bbe435a059b63e3fdf34ef
7
+ data.tar.gz: 9cbe6ac573fe8e1550cfe06bea6e5b3536bedf6fd8fa1029c70275d1d765d9d1dcb18b362a3b3e5807846d28da6486848943e308ebf54e2b305227829be477f6
data/README.md CHANGED
@@ -4,30 +4,55 @@ Making C++ slightly less painful.
4
4
 
5
5
  R++ aims to being a collection of command-line utilities and magical fairy dust to make all the C++ monsters go away and let you, as the awesome programmer, get to what's important.
6
6
 
7
- WARNING: I just started this project so functionality is super limited. You have been warned!
8
-
9
7
  ## Installation
10
8
 
11
- $ gem install rplusplus
9
+ ```
10
+ $ gem install rplusplus
11
+ ```
12
+
13
+ ## Usage
12
14
 
13
- ## Using it in your Rakefile
15
+ ### Create a new Project
14
16
 
15
- In your Rakefile, do this:
17
+ Make a new C++ app, with a Rakefile, gitignore, and some skeleton source files:
16
18
 
17
19
  ```
20
+ $ r++ new MyApp
21
+ ```
22
+
23
+ This creates a folder called `MyApp` with a main source file called `my_app.cpp` as well as accompanying `Rakefile` and `.gitignore` files to get you going.
24
+
25
+ ### Class Generator
26
+
27
+ Generate header and source file skeletons for a class:
28
+
29
+ ```
30
+ $ r++ generate class MyClass
31
+ ```
32
+
33
+ This generates a `my_class.h` and `my_class.cpp` file in the current directory.
34
+
35
+ ### In your Rakefile
36
+
37
+ **NOTE**: You still have to do some work yourself in the Rakefile at this point. Grab the example Rakefile in `examples/Rakefile` and modify it to your needs.
38
+
39
+ At the moment, all R++ can do is calculate the dependencies for you, a la `g++ -MM`. Just add this to your Rakefile:
40
+
41
+ ```ruby
18
42
  require 'rplusplus'
19
43
  env = RPlusPlus::Environment.new
20
44
  ```
21
45
 
22
- Now, env has some useful properties which you can make use of in your Rake tasks:
23
-
24
- * `env.objects` is a hash of the form `'foo.o' => ['foo.cpp', 'foo.h', ...]`
25
- * `env.builds` is a hash of the form `'main' => ['main.o', 'foo.o', ...]`
26
- * `env.erbs` is a hash of the form `'foo.cpp' => ['foo.cpp.erb']`
46
+ Now, `env` has some useful properties which you can make use of in your Rake tasks:
27
47
 
28
- `env.objects` and `env.builds` magically take into account any `*.erb` files in existence so you can just code away without any funny business.
48
+ * `env.objects` is a hash of `*.o` files to dependencies: e.g.
49
+ `'foo.o' => ['foo.cpp', 'foo.h', ...]`
50
+ * `env.builds` is a hash of executables to dependencies: e.g.
51
+ `'main' => ['main.o', 'foo.o', ...]`
52
+ * `env.erbs` is a hash of `*.erb` files to dependencies: e.g.
53
+ `'foo.cpp' => ['foo.cpp.erb']`
29
54
 
30
- I have used this in one of my own projects and it works like a charm, but I haven't come across any gotchas as of yet so YMMV.
55
+ The `env.objects` and `env.builds` hashes magically take into account any `*.erb` files in existence so you can just code away without any funny business.
31
56
 
32
57
  ## How does it work?
33
58
 
@@ -39,32 +64,29 @@ The ERB dependencies are simply computed by finding each erb file and then remov
39
64
 
40
65
  Go ahead and crack open that codebase and see for yourself!
41
66
 
42
- ## Ideas for the soon-to-exist command-line tool
67
+ ## Coming Soon
43
68
 
44
- Make a new C++ app, with a Rakefile, .gitignore, and some skeleton source files:
69
+ Generate a basic Rakefile, etc. for an existing C++ project:
45
70
 
46
71
  ```
47
- $ r++ new MyApp
48
- ```
49
-
50
- Generates a header and source file skeleton for a class:
51
- ```
52
- $ r++ generate class MyClass
72
+ $ r++ init
53
73
  ```
54
74
 
55
75
  ## More Ideas
56
76
 
57
- * Have `r++` act as a wrapper or superset of `g++` to allow users to drop `r++` straight into an existing project.
77
+ * Move all the boilerplate from the example Rakefile into R++ so there is less for developers to do to get started.
78
+ * Add support for a C++ test framework and add a `rake test` task.
79
+ * Do some kind of caching for the dependencies. I'm suspecting the Rakefile will take really long on a larger project.
58
80
  * Add some magical C++ code generating libraries to use with ERB.
59
81
  * Make it easy for people to package their library or app or whatever into a deb or an rpm or a pkg or a whatever using a config file called a "libspec" or something (a-la "gemspec").
60
82
  * On that note, make it easy for people to publish to a package repository (apt, yum, aur, etc).
61
- * Get a better name perhaps, I don't thing "R++" is the best name for this, since it's already been used by a past, failed project (we might pick up its bad luck or something).
83
+ * Have `r++` act as a wrapper or superset of `g++` to allow users to drop `r++` straight into an existing project.
62
84
 
63
85
  ## Disclaimer
64
86
 
65
- This has absolutely nothing to do with Bell labs R++.
87
+ This has absolutely nothing to do with [Bell labs R++](http://ect.bell-labs.com/who/pfps/rpp/index.html).
66
88
 
67
- ## Help me make R++ better for everyone! :)
89
+ ## Help make R++ better for everyone :)
68
90
 
69
91
  The easiest way to contribute is to try this thing out and submit an issue when it breaks.
70
92
 
data/examples/Rakefile ADDED
@@ -0,0 +1,58 @@
1
+ require 'rake/clean'
2
+ require 'rplusplus'
3
+ env = RPlusPlus::Environment.new
4
+
5
+ # TODO: move a lot of this stuff into R++ configuration
6
+ CC = 'g++'
7
+
8
+ LIBS = ['glew', 'glfw3'] # example libs for, e.g. and OpenGL application
9
+
10
+ # Grab flags from pkg-config. NOTE: this requres pkg-config to be installed AND your included libs to work with it
11
+ LIB_CFLAGS = LIBS.map { |lib|
12
+ %x[ pkg-config --cflags #{lib} ].gsub(/\n/,' ')
13
+ }.flatten.join(' ')
14
+ LDLIBS = LIBS.map {
15
+ |lib| %x[ pkg-config --static --libs #{lib} ].gsub(/\n/,' ')
16
+ }.flatten.join(' ')
17
+
18
+ # Some strict default CFLAGS
19
+ WARNING_FLAGS = [
20
+ 'all', 'extra', 'effc++', 'init-self', 'missing-include-dirs', 'switch-default', 'switch-enum', 'unused-parameter',
21
+ 'strict-overflow=5', 'float-equal', 'shadow', 'c++0x-compat', 'conversion', 'sign-conversion', 'missing-declarations',
22
+ 'overloaded-virtual', 'sign-promo'
23
+ ].map { |flag| "-W#{flag}"}.join ' '
24
+ FORMATTING_FLAGS = ['message-length=80', 'diagnostics-show-option'].map { |flag| "-f#{flag}"}.join ' '
25
+ EXTRA_CFLAGS = "-std=c++11 -pipe -pedantic"
26
+ CFLAGS = "#{WARNING_FLAGS} #{FORMATTING_FLAGS} #{LIB_CFLAGS} #{EXTRA_CFLAGS}"
27
+
28
+ EXTRA_LDFLAGS = ""
29
+ LDFLAGS = "#{LDLIBS} #{EXTRA_LDFLAGS}"
30
+
31
+ CLOBBER.include(*env.objects.keys, *env.builds.keys, *env.erbs.keys)
32
+
33
+ task :default => :all
34
+
35
+ task :all => ['main'] # if your main function is in a file called main.cpp
36
+
37
+ # TODO: do the following for you, so you don't have to put this in yourself
38
+
39
+ # compile ERBs into cpp/h files
40
+ env.erbs.each do |target, sources|
41
+ file target => sources do |t|
42
+ File.write(target, ERB.new(File.read(sources.first)).result)
43
+ end
44
+ end
45
+
46
+ # compile CPPs into O-files
47
+ env.objects.each do |object, sources|
48
+ file object => sources do |t|
49
+ sh "#{CC} #{CFLAGS} -c #{sources.first} -o #{object}"
50
+ end
51
+ end
52
+
53
+ # build executables from main CPPs
54
+ env.builds.each do |target, objects|
55
+ file target => objects do |t|
56
+ sh "#{CC} #{objects.join(' ')} -o #{target} #{LDFLAGS}"
57
+ end
58
+ end
@@ -0,0 +1,34 @@
1
+ module RPlusPlus
2
+ module Commands
3
+ class New
4
+ Command.register :new, self
5
+
6
+ def self.call project_name, *args
7
+ FileUtils.mkdir project_name
8
+
9
+ File.write("#{project_name}/#{project_name.underscore}.cpp", main_erb.result(binding))
10
+ File.write("#{project_name}/Rakefile", rakefile_erb.result(binding))
11
+ File.write("#{project_name}/.gitignore", gitignore_erb.result(binding))
12
+ end
13
+
14
+ class << self
15
+ private
16
+ def template_dir
17
+ File.join File.dirname(__FILE__), '../templates'
18
+ end
19
+
20
+ def main_erb
21
+ ERB.new(File.read(File.join(template_dir, 'main.erb')))
22
+ end
23
+
24
+ def rakefile_erb
25
+ ERB.new(File.read(File.join(template_dir, 'Rakefile.erb')))
26
+ end
27
+
28
+ def gitignore_erb
29
+ ERB.new(File.read(File.join(template_dir, 'gitignore.erb')))
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,53 @@
1
+ require 'rake/clean'
2
+ require 'rplusplus'
3
+ env = RPlusPlus::Environment.new
4
+
5
+ CC = 'g++'
6
+
7
+ LIBS = []
8
+
9
+ LIB_CFLAGS = LIBS.map { |lib|
10
+ %x[ pkg-config --cflags #{lib} ].gsub(/\n/,' ')
11
+ }.flatten.join(' ')
12
+ LDLIBS = LIBS.map {
13
+ |lib| %x[ pkg-config --static --libs #{lib} ].gsub(/\n/,' ')
14
+ }.flatten.join(' ')
15
+
16
+ WARNING_FLAGS = [
17
+ 'all', 'extra', 'effc++', 'init-self', 'missing-include-dirs', 'switch-default', 'switch-enum', 'unused-parameter',
18
+ 'strict-overflow=5', 'float-equal', 'shadow', 'c++0x-compat', 'conversion', 'sign-conversion', 'missing-declarations',
19
+ 'overloaded-virtual', 'sign-promo'
20
+ ].map { |flag| "-W#{flag}"}.join ' '
21
+ FORMATTING_FLAGS = ['message-length=80', 'diagnostics-show-option'].map { |flag| "-f#{flag}"}.join ' '
22
+ EXTRA_CFLAGS = "-std=c++11 -pipe -pedantic"
23
+ CFLAGS = "#{WARNING_FLAGS} #{FORMATTING_FLAGS} #{LIB_CFLAGS} #{EXTRA_CFLAGS}"
24
+
25
+ EXTRA_LDFLAGS = ""
26
+ LDFLAGS = "#{LDLIBS} #{EXTRA_LDFLAGS}"
27
+
28
+ CLOBBER.include(*env.objects.keys, *env.builds.keys, *env.erbs.keys)
29
+
30
+ task :default => :all
31
+
32
+ task :all => ['<%= project_name.underscore %>']
33
+
34
+ # compile ERBs into cpp/h files
35
+ env.erbs.each do |target, sources|
36
+ file target => sources do |t|
37
+ File.write(target, ERB.new(File.read(sources.first)).result)
38
+ end
39
+ end
40
+
41
+ # compile CPPs into O-files
42
+ env.objects.each do |object, sources|
43
+ file object => sources do |t|
44
+ sh "#{CC} #{CFLAGS} -c #{sources.first} -o #{object}"
45
+ end
46
+ end
47
+
48
+ # build executables from main CPPs
49
+ env.builds.each do |target, objects|
50
+ file target => objects do |t|
51
+ sh "#{CC} #{objects.join(' ')} -o #{target} #{LDFLAGS}"
52
+ end
53
+ end
@@ -0,0 +1,2 @@
1
+ *.o
2
+ <%= project_name.underscore %>
@@ -0,0 +1,4 @@
1
+ int main(int argc, char* argv[])
2
+ {
3
+ return 0;
4
+ }
@@ -1,3 +1,3 @@
1
1
  module Rplusplus
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
data/lib/rplusplus.rb CHANGED
@@ -5,6 +5,7 @@ require "rplusplus/environment"
5
5
  require "rplusplus/command"
6
6
  require "rplusplus/commands/generate"
7
7
  require "rplusplus/generators/class_generator"
8
+ require "rplusplus/commands/new"
8
9
 
9
10
  module RPlusPlus
10
11
  def self.call argv
@@ -0,0 +1,59 @@
1
+ require 'spec_helper'
2
+
3
+ describe RPlusPlus::Commands::New do
4
+ it 'registers itself with Command' do
5
+ expect(RPlusPlus::Command.commands).to include(:new => RPlusPlus::Commands::New)
6
+ end
7
+
8
+ describe '#call' do
9
+ before(:all) do
10
+ @pwd = Dir.pwd
11
+ Dir.chdir('spec/support/sandbox')
12
+ end
13
+
14
+ after(:all) do
15
+ Dir.chdir(@pwd)
16
+ end
17
+
18
+ after do
19
+ FileUtils.rm_rf 'my_project'
20
+ end
21
+
22
+ it 'creates a new folder with the project name' do
23
+ RPlusPlus::Commands::New.call('my_project')
24
+
25
+ expect(File).to be_directory('my_project')
26
+ end
27
+
28
+ it 'creates a starting main file with the project name' do
29
+ RPlusPlus::Commands::New.call('my_project')
30
+
31
+ expect(File).to exist('my_project/my_project.cpp')
32
+ main_cpp = File.read 'my_project/my_project.cpp'
33
+
34
+ expect(main_cpp).to include 'int main(int argc, char* argv[])'
35
+ expect(main_cpp).to include 'return 0;'
36
+ end
37
+
38
+ it 'creates a starting Rakefile with the executable as the default task' do
39
+ RPlusPlus::Commands::New.call('my_project')
40
+
41
+ expect(File).to exist('my_project/Rakefile')
42
+ rakefile = File.read 'my_project/Rakefile'
43
+
44
+ expect(rakefile).to include "require 'rplusplus'"
45
+ expect(rakefile).to include "env = RPlusPlus::Environment.new"
46
+ expect(rakefile).to include 'task :default => :all'
47
+ expect(rakefile).to include "task :all => ['my_project']"
48
+ end
49
+
50
+ it 'creates a .gitignore that ignores *.o files and the main executable' do
51
+ RPlusPlus::Commands::New.call('my_project')
52
+ expect(File).to exist('my_project/.gitignore')
53
+ gitignore = File.read 'my_project/.gitignore'
54
+
55
+ expect(gitignore).to include '*.o'
56
+ expect(gitignore).to include 'my_project'
57
+ end
58
+ end
59
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rplusplus
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Smith
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-10 00:00:00.000000000 Z
11
+ date: 2015-05-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -109,17 +109,23 @@ files:
109
109
  - README.md
110
110
  - Rakefile
111
111
  - bin/r++
112
+ - examples/Rakefile
112
113
  - lib/rplusplus.rb
113
114
  - lib/rplusplus/command.rb
114
115
  - lib/rplusplus/commands/generate.rb
116
+ - lib/rplusplus/commands/new.rb
115
117
  - lib/rplusplus/environment.rb
116
118
  - lib/rplusplus/generators/class_generator.rb
119
+ - lib/rplusplus/templates/Rakefile.erb
117
120
  - lib/rplusplus/templates/class.erb
118
121
  - lib/rplusplus/templates/class_header.erb
122
+ - lib/rplusplus/templates/gitignore.erb
123
+ - lib/rplusplus/templates/main.erb
119
124
  - lib/rplusplus/version.rb
120
125
  - rplusplus.gemspec
121
126
  - spec/command_spec.rb
122
127
  - spec/commands/generate_spec.rb
128
+ - spec/commands/new_spec.rb
123
129
  - spec/environment_spec.rb
124
130
  - spec/generators/class_generator_spec.rb
125
131
  - spec/rplusplus_spec.rb
@@ -166,6 +172,7 @@ summary: Making C++ slightly less painful.
166
172
  test_files:
167
173
  - spec/command_spec.rb
168
174
  - spec/commands/generate_spec.rb
175
+ - spec/commands/new_spec.rb
169
176
  - spec/environment_spec.rb
170
177
  - spec/generators/class_generator_spec.rb
171
178
  - spec/rplusplus_spec.rb