rplusplus 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +22 -0
- data/.rspec +2 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +85 -0
- data/Rakefile +2 -0
- data/lib/environment.rb +118 -0
- data/lib/rplusplus/version.rb +3 -0
- data/lib/rplusplus.rb +5 -0
- data/rplusplus.gemspec +26 -0
- data/spec/environment_spec.rb +46 -0
- data/spec/r++_spec.rb +5 -0
- data/spec/rplusplus_spec.rb +4 -0
- data/spec/spec_helper.rb +10 -0
- data/spec/support/load_file.rb +3 -0
- data/spec/support/samples/erb_class.cpp.erb +3 -0
- data/spec/support/samples/erb_class.h.erb +8 -0
- data/spec/support/samples/foo/bar.cpp +0 -0
- data/spec/support/samples/foo/bar.h +0 -0
- data/spec/support/samples/foo/baz.h +0 -0
- data/spec/support/samples/foo/qux.h +0 -0
- data/spec/support/samples/foo/quz.h +0 -0
- data/spec/support/samples/main.cpp +5 -0
- data/spec/support/samples/my_class.cpp +6 -0
- data/spec/support/samples/my_class.h +15 -0
- data/spec/support/samples/other_class.cpp +6 -0
- data/spec/support/samples/other_class.h +15 -0
- data/spec/support/samples/other_main.cpp +4 -0
- metadata +132 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: af2b70a8e4415e61ee91023a7d5d39aa2ad373e6
|
4
|
+
data.tar.gz: ad4ef2a7baf8ba17fd0b158ca765e424bd962cb7
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9a301b16027df9bb54809759621ef511dd35e9b4a02a7dc6208fb62c6d71035d29d54de146306998494e3c95f1af9c287b7a046a8f2d6547bba83caf255586bc
|
7
|
+
data.tar.gz: 9c02e6a66f19a2e2562d7ee014178931caaef0628a787971f9acb539a1539a595204f9e0f8dc2cf6597aada134d74204309219f2c153c8133c3a1ca562fc8a34
|
data/.gitignore
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
*.bundle
|
19
|
+
*.so
|
20
|
+
*.o
|
21
|
+
*.a
|
22
|
+
mkmf.log
|
data/.rspec
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Daniel Smith
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
# R++
|
2
|
+
|
3
|
+
Making C++ slightly less painful.
|
4
|
+
|
5
|
+
Of all the horrid languages to ever exist, C++ has to be the most widely used. 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
|
+
|
7
|
+
R++ also aims to bring some kind of order to the world of C++ by following the principle of convention over configuration.
|
8
|
+
|
9
|
+
WARNING: I just started this project so functionality is super limited. You have been warned!
|
10
|
+
|
11
|
+
## Installation
|
12
|
+
|
13
|
+
$ gem install rplusplus
|
14
|
+
|
15
|
+
## Using it in your Rakefile
|
16
|
+
|
17
|
+
This bit of functionality exists, and it's super useful (but still in BETA):
|
18
|
+
|
19
|
+
In your Rakefile, do this:
|
20
|
+
|
21
|
+
```
|
22
|
+
require 'rplusplus'
|
23
|
+
env = RPlusPlus::Environment.new
|
24
|
+
```
|
25
|
+
|
26
|
+
Now, env has some useful properties:
|
27
|
+
|
28
|
+
* `env.objects` contains a hash of the form `'foo.o' => ['foo.cpp', 'foo.h', ...]` which you can use for creating file tasks for all your o-files.
|
29
|
+
* `env.builds` contains a hash of the form `'main' => ['main.o', 'foo.o', ...]` which you can use for file tasks for all your executables.
|
30
|
+
* `env.erbs` contains a hash of the form `'foo.cpp' => ['foo.cpp.erb']` so you can make file tasks for generating source code from embedded ruby source files.
|
31
|
+
|
32
|
+
`env.objects` and `env.builds` magically take into account any `*.erb` files in existence so you can just code away without any funny business.
|
33
|
+
|
34
|
+
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.
|
35
|
+
|
36
|
+
## How does it work?
|
37
|
+
|
38
|
+
Object-file dependencies are calculated by going through each cpp file and reading each #include and following it recursively.
|
39
|
+
|
40
|
+
The builds are discovered by finding each cpp file with a main function, and then going through each of it's dependencies to build a list of o-files to link.
|
41
|
+
|
42
|
+
The ERB dependencies are simply computed by finding each erb file and then removing the erb extention.
|
43
|
+
|
44
|
+
## Ideas for the soon-to-exist command-line tool
|
45
|
+
|
46
|
+
Make a new C++ app, with a Rakefile, .gitignore, and some skeleton source files:
|
47
|
+
|
48
|
+
```
|
49
|
+
$ r++ new MyApp
|
50
|
+
```
|
51
|
+
|
52
|
+
Some other things I plan on including:
|
53
|
+
|
54
|
+
Work out the dependencies a-la `g++ -MM`, except in rake-friendly syntax instead of Make:
|
55
|
+
```
|
56
|
+
$ r++ -MM some_code.cpp
|
57
|
+
```
|
58
|
+
|
59
|
+
Generates a header and source file skeleton for a class:
|
60
|
+
```
|
61
|
+
$ r++ generate class MyClass
|
62
|
+
```
|
63
|
+
|
64
|
+
## More Ideas
|
65
|
+
|
66
|
+
* Have `r++` act as a wrapper or superset of `g++` to allow users to drop `r++` straight into an existing project.
|
67
|
+
* Add some magical C++ code generating libraries to use with ERB.
|
68
|
+
* 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").
|
69
|
+
* On that note, make it easy for people to publish to a package repository (apt, yum, aur, etc).
|
70
|
+
|
71
|
+
## Disclaimer
|
72
|
+
|
73
|
+
This has absolutely nothing to do with Bell labs R++.
|
74
|
+
|
75
|
+
## I want you to help make R++ better for everyone.
|
76
|
+
|
77
|
+
The easiest way to contribute is to try this thing out and submit an issue when it breaks.
|
78
|
+
|
79
|
+
Otherwise if you want to help me implement a super awesome idea then pull requests are easy, fun, and beneficial to all of society:
|
80
|
+
|
81
|
+
1. Fork it ( https://github.com/[my-github-username]/rplusplus/fork )
|
82
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
83
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
84
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
85
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/lib/environment.rb
ADDED
@@ -0,0 +1,118 @@
|
|
1
|
+
require 'pathname'
|
2
|
+
require 'erb'
|
3
|
+
|
4
|
+
module RPlusPlus
|
5
|
+
class Environment
|
6
|
+
|
7
|
+
def initialize path='.'
|
8
|
+
@path = path
|
9
|
+
end
|
10
|
+
|
11
|
+
def objects
|
12
|
+
@objects ||= objects_hash
|
13
|
+
end
|
14
|
+
|
15
|
+
def builds
|
16
|
+
@builds ||= builds_hash
|
17
|
+
end
|
18
|
+
|
19
|
+
def erbs
|
20
|
+
@erbs ||= erbs_hash
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def erbs_hash
|
26
|
+
hash = {}
|
27
|
+
Dir[Pathname(@path).join('**/*.erb')].each do |e|
|
28
|
+
hash[e[0..-5]] = [e]
|
29
|
+
end
|
30
|
+
hash
|
31
|
+
end
|
32
|
+
|
33
|
+
def objects_hash
|
34
|
+
@cpp_info ||= info_hash('cpp')
|
35
|
+
@header_info ||= info_hash('h')
|
36
|
+
|
37
|
+
hash = {}
|
38
|
+
@cpp_info.each do |cpp,info|
|
39
|
+
hash[objectify cpp] = [cpp] | deps_for(info)
|
40
|
+
end
|
41
|
+
hash
|
42
|
+
end
|
43
|
+
|
44
|
+
def deps_for info
|
45
|
+
info[:deps] | info[:deps].map do |d|
|
46
|
+
deps_for(@header_info[d])
|
47
|
+
end.flatten
|
48
|
+
end
|
49
|
+
|
50
|
+
def builds_hash
|
51
|
+
objects
|
52
|
+
hash = {}
|
53
|
+
@cpp_info.each do |cpp,info|
|
54
|
+
next unless info[:main]
|
55
|
+
|
56
|
+
hash[basename cpp] = obj_deps objectify(cpp)
|
57
|
+
end
|
58
|
+
hash
|
59
|
+
end
|
60
|
+
|
61
|
+
def obj_deps obj, visited=[]
|
62
|
+
deps = []
|
63
|
+
objects[obj].each do |d|
|
64
|
+
o = objectify(d)
|
65
|
+
next if visited.include?(o)
|
66
|
+
if objects.include?(o)
|
67
|
+
deps << o
|
68
|
+
deps |= obj_deps(o, [o,*visited])
|
69
|
+
end
|
70
|
+
end
|
71
|
+
deps
|
72
|
+
end
|
73
|
+
|
74
|
+
def info_hash type
|
75
|
+
hash = {}
|
76
|
+
Dir[Pathname(@path).join("**/*.#{type}")].each do |f|
|
77
|
+
hash[f] = info_for f
|
78
|
+
end
|
79
|
+
Dir[Pathname(@path).join("**/*.#{type}.erb")].each do |f|
|
80
|
+
hash[unerb(f)] = info_for f
|
81
|
+
end
|
82
|
+
hash
|
83
|
+
end
|
84
|
+
|
85
|
+
def info_for fn
|
86
|
+
main = false
|
87
|
+
deps = []
|
88
|
+
File.foreach(fn) do |l|
|
89
|
+
main ||= !!main_match(l)
|
90
|
+
dep = include_match l
|
91
|
+
deps << dep if dep
|
92
|
+
end
|
93
|
+
{main: main, deps: deps}
|
94
|
+
end
|
95
|
+
|
96
|
+
def unerb fn
|
97
|
+
fn.gsub(/\.erb$/,'')
|
98
|
+
end
|
99
|
+
|
100
|
+
def basename fn
|
101
|
+
fn.gsub(/\..*$/,'')
|
102
|
+
end
|
103
|
+
|
104
|
+
def main_match l
|
105
|
+
l =~ /^\W*int\W*main\(.*?\)/
|
106
|
+
end
|
107
|
+
|
108
|
+
def include_match l
|
109
|
+
m = /#include "(?<file>.*)"/.match(l)
|
110
|
+
m[:file] if m
|
111
|
+
end
|
112
|
+
|
113
|
+
def objectify filename
|
114
|
+
filename.gsub(/\.(cpp|cpp\.erb|h|h\.erb)$/,'.o')
|
115
|
+
end
|
116
|
+
|
117
|
+
end
|
118
|
+
end
|
data/lib/rplusplus.rb
ADDED
data/rplusplus.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'rplusplus/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "rplusplus"
|
8
|
+
spec.version = Rplusplus::VERSION
|
9
|
+
spec.authors = ["Daniel Smith"]
|
10
|
+
spec.email = ["jellymann@gmail.com"]
|
11
|
+
spec.summary = %q{Making C++ slightly less painful.}
|
12
|
+
spec.description = %q{A collection of command-line tools for making C++ development easier.}
|
13
|
+
spec.homepage = "https://github.com/jellymann/rplusplus"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.required_ruby_version = '>= 1.9.3'
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
24
|
+
spec.add_development_dependency "rake", "~> 10.3"
|
25
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
26
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe RPlusPlus::Environment do
|
4
|
+
let(:env) { RPlusPlus::Environment.new }
|
5
|
+
|
6
|
+
before(:all) do
|
7
|
+
Dir.chdir('spec/support/samples')
|
8
|
+
end
|
9
|
+
|
10
|
+
describe '#objects' do
|
11
|
+
it 'contains a list of objects with their dependencies' do
|
12
|
+
expect(env.objects).to include(
|
13
|
+
'my_class.o', 'other_class.o', 'foo/bar.o','erb_class.o')
|
14
|
+
expect(env.objects['my_class.o']).to contain_exactly(
|
15
|
+
'my_class.cpp', 'my_class.h', 'other_class.h', 'foo/bar.h', 'foo/baz.h', 'foo/quz.h',
|
16
|
+
'erb_class.h'
|
17
|
+
)
|
18
|
+
expect(env.objects['erb_class.o']).to contain_exactly(
|
19
|
+
'erb_class.cpp', 'erb_class.h'
|
20
|
+
)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe '#builds' do
|
25
|
+
it 'contains a list of builds and their dependencies' do
|
26
|
+
expect(env.builds).to include(
|
27
|
+
'main', 'other_main'
|
28
|
+
)
|
29
|
+
expect(env.builds['main']).to contain_exactly(
|
30
|
+
'my_class.o', 'other_class.o', 'erb_class.o', 'foo/bar.o', 'main.o'
|
31
|
+
)
|
32
|
+
expect(env.builds['other_main']).to contain_exactly(
|
33
|
+
'erb_class.o', 'other_main.o'
|
34
|
+
)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
describe '#erbs' do
|
39
|
+
it 'contains a list of files to be generated with erb' do
|
40
|
+
expect(env.erbs).to include(
|
41
|
+
'erb_class.cpp' => ['erb_class.cpp.erb'],
|
42
|
+
'erb_class.h' => ['erb_class.h.erb']
|
43
|
+
)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
data/spec/r++_spec.rb
ADDED
data/spec/spec_helper.rb
ADDED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
metadata
ADDED
@@ -0,0 +1,132 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rplusplus
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Daniel Smith
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-07-28 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.6'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.6'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.3'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.3'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
description: A collection of command-line tools for making C++ development easier.
|
56
|
+
email:
|
57
|
+
- jellymann@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- ".rspec"
|
64
|
+
- Gemfile
|
65
|
+
- LICENSE.txt
|
66
|
+
- README.md
|
67
|
+
- Rakefile
|
68
|
+
- lib/environment.rb
|
69
|
+
- lib/rplusplus.rb
|
70
|
+
- lib/rplusplus/version.rb
|
71
|
+
- rplusplus.gemspec
|
72
|
+
- spec/environment_spec.rb
|
73
|
+
- spec/r++_spec.rb
|
74
|
+
- spec/rplusplus_spec.rb
|
75
|
+
- spec/spec_helper.rb
|
76
|
+
- spec/support/load_file.rb
|
77
|
+
- spec/support/samples/erb_class.cpp.erb
|
78
|
+
- spec/support/samples/erb_class.h.erb
|
79
|
+
- spec/support/samples/foo/bar.cpp
|
80
|
+
- spec/support/samples/foo/bar.h
|
81
|
+
- spec/support/samples/foo/baz.h
|
82
|
+
- spec/support/samples/foo/qux.h
|
83
|
+
- spec/support/samples/foo/quz.h
|
84
|
+
- spec/support/samples/main.cpp
|
85
|
+
- spec/support/samples/my_class.cpp
|
86
|
+
- spec/support/samples/my_class.h
|
87
|
+
- spec/support/samples/other_class.cpp
|
88
|
+
- spec/support/samples/other_class.h
|
89
|
+
- spec/support/samples/other_main.cpp
|
90
|
+
homepage: https://github.com/jellymann/rplusplus
|
91
|
+
licenses:
|
92
|
+
- MIT
|
93
|
+
metadata: {}
|
94
|
+
post_install_message:
|
95
|
+
rdoc_options: []
|
96
|
+
require_paths:
|
97
|
+
- lib
|
98
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - ">="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: 1.9.3
|
103
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
104
|
+
requirements:
|
105
|
+
- - ">="
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
version: '0'
|
108
|
+
requirements: []
|
109
|
+
rubyforge_project:
|
110
|
+
rubygems_version: 2.3.0
|
111
|
+
signing_key:
|
112
|
+
specification_version: 4
|
113
|
+
summary: Making C++ slightly less painful.
|
114
|
+
test_files:
|
115
|
+
- spec/environment_spec.rb
|
116
|
+
- spec/r++_spec.rb
|
117
|
+
- spec/rplusplus_spec.rb
|
118
|
+
- spec/spec_helper.rb
|
119
|
+
- spec/support/load_file.rb
|
120
|
+
- spec/support/samples/erb_class.cpp.erb
|
121
|
+
- spec/support/samples/erb_class.h.erb
|
122
|
+
- spec/support/samples/foo/bar.cpp
|
123
|
+
- spec/support/samples/foo/bar.h
|
124
|
+
- spec/support/samples/foo/baz.h
|
125
|
+
- spec/support/samples/foo/qux.h
|
126
|
+
- spec/support/samples/foo/quz.h
|
127
|
+
- spec/support/samples/main.cpp
|
128
|
+
- spec/support/samples/my_class.cpp
|
129
|
+
- spec/support/samples/my_class.h
|
130
|
+
- spec/support/samples/other_class.cpp
|
131
|
+
- spec/support/samples/other_class.h
|
132
|
+
- spec/support/samples/other_main.cpp
|