rake-builder 0.0.17 → 0.0.18
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.
- data/examples/01_hello_world_cpp/vendor/bundle/gems/json-1.7.6/Rakefile +412 -0
- data/examples/01_hello_world_cpp/vendor/bundle/gems/json-1.7.6/ext/json/ext/fbuffer/fbuffer.h +185 -0
- data/examples/01_hello_world_cpp/vendor/bundle/gems/json-1.7.6/ext/json/ext/generator/generator.c +1427 -0
- data/examples/01_hello_world_cpp/vendor/bundle/gems/json-1.7.6/ext/json/ext/generator/generator.h +149 -0
- data/examples/01_hello_world_cpp/vendor/bundle/gems/json-1.7.6/ext/json/ext/parser/parser.c +2204 -0
- data/examples/01_hello_world_cpp/vendor/bundle/gems/json-1.7.6/ext/json/ext/parser/parser.h +77 -0
- data/examples/01_hello_world_cpp/vendor/bundle/gems/rake-10.0.3/Rakefile +374 -0
- data/examples/01_hello_world_cpp/vendor/bundle/gems/rake-10.0.3/doc/example/a.c +6 -0
- data/examples/01_hello_world_cpp/vendor/bundle/gems/rake-10.0.3/doc/example/b.c +6 -0
- data/examples/01_hello_world_cpp/vendor/bundle/gems/rake-10.0.3/doc/example/main.c +11 -0
- data/lib/rake/builder.rb +39 -70
- data/lib/rake/builder/presenters/makefile_am/builder_collection_presenter.rb +46 -0
- data/lib/rake/builder/presenters/makefile_am/builder_presenter.rb +40 -0
- data/lib/rake/builder/version.rb +1 -1
- data/spec/autoconf_spec.rb +1 -22
- data/spec/project_spec.rb +20 -0
- data/spec/unit/rake/builder/presenters/makefile_am/builder_collection_presenter_spec.rb +55 -0
- data/spec/unit/rake/builder/presenters/makefile_am/builder_presenter_spec.rb +71 -0
- data/spec/unit/rake/builder_spec.rb +46 -0
- metadata +24 -4
data/lib/rake/builder.rb
CHANGED
@@ -1,8 +1,10 @@
|
|
1
|
-
require 'rubygems' if RUBY_VERSION < '1.9'
|
2
1
|
require 'json'
|
3
2
|
require 'logger'
|
4
3
|
require 'rake'
|
5
4
|
require 'rake/tasklib'
|
5
|
+
|
6
|
+
require 'rake/builder/presenters/makefile_am/builder_presenter'
|
7
|
+
require 'rake/builder/presenters/makefile_am/builder_collection_presenter'
|
6
8
|
require 'rake/path'
|
7
9
|
require 'rake/local_config'
|
8
10
|
require 'rake/file_task_alias'
|
@@ -236,62 +238,12 @@ EOT
|
|
236
238
|
end
|
237
239
|
|
238
240
|
def self.create_makefile_am
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
entry = instance.makefile_am_entry
|
243
|
-
case entry[ :type ]
|
244
|
-
when :static_library, :shared_library
|
245
|
-
libraries << entry
|
246
|
-
else
|
247
|
-
binaries << entry
|
248
|
-
end
|
249
|
-
end
|
250
|
-
|
251
|
-
File.open( 'Makefile.am', 'w' ) do | f |
|
252
|
-
if libraries.size > 0
|
253
|
-
names = libraries.map { | lib | lib[ :name ] }.join( ' ' )
|
254
|
-
f.write "lib_LIBRARIES = #{ names }\n\n"
|
255
|
-
libraries.each do | lib |
|
256
|
-
f.write <<EOT
|
257
|
-
#{ lib[ :label ] }_SOURCES = #{ lib[ :sources ] }
|
258
|
-
#{ lib[ :label ] }_CPPFLAGS = #{ lib[ :compiler_flags ] }
|
259
|
-
|
260
|
-
EOT
|
261
|
-
end
|
262
|
-
end
|
263
|
-
if binaries.size > 0
|
264
|
-
names = binaries.map { | bin | bin[ :name ] }.join( ' ' )
|
265
|
-
f.write "bin_PROGRAMS = #{ names }\n\n"
|
266
|
-
binaries.each do | bin |
|
267
|
-
f.write <<EOT
|
268
|
-
#{ bin[ :label ] }_SOURCES = #{ bin[ :sources ] }
|
269
|
-
#{ bin[ :label ] }_CPPFLAGS = #{ bin[ :compiler_flags ] }
|
270
|
-
#{ bin[ :label ] }_LDFLAGS = -L.
|
271
|
-
#{ bin[ :label ] }_LDADD = #{ bin[ :libraries ] }
|
272
|
-
|
273
|
-
EOT
|
274
|
-
end
|
275
|
-
end
|
276
|
-
|
241
|
+
presenter = Rake::Builder::Presenters::MakefileAm::BuilderCollectionPresenter.new(instances)
|
242
|
+
File.open('Makefile.am', 'w') do |f|
|
243
|
+
f.write presenter.to_s
|
277
244
|
end
|
278
245
|
end
|
279
246
|
|
280
|
-
def makefile_am_entry
|
281
|
-
primary_name = Rake::Path.relative_path( target, rakefile_path, :initial_dot_slash => false )
|
282
|
-
sources = source_files.map{ | file | Rake::Path.relative_path( file, rakefile_path) }.join( ' ' )
|
283
|
-
sources_label = primary_name.gsub( %r(\.), '_' )
|
284
|
-
|
285
|
-
{
|
286
|
-
:type => @target_type,
|
287
|
-
:name => primary_name,
|
288
|
-
:label => sources_label,
|
289
|
-
:sources => sources,
|
290
|
-
:compiler_flags => compiler_flags,
|
291
|
-
:libraries => library_dependencies_list,
|
292
|
-
}
|
293
|
-
end
|
294
|
-
|
295
247
|
#########################################
|
296
248
|
# VERSION file
|
297
249
|
|
@@ -360,6 +312,34 @@ EOT
|
|
360
312
|
@header_files = find_files( @header_search_paths, @header_file_extension ).uniq
|
361
313
|
end
|
362
314
|
|
315
|
+
def is_library?
|
316
|
+
[:static_library, :shared_library].include?(target_type)
|
317
|
+
end
|
318
|
+
|
319
|
+
def primary_name
|
320
|
+
Rake::Path.relative_path(target, rakefile_path, :initial_dot_slash => false)
|
321
|
+
end
|
322
|
+
|
323
|
+
def label
|
324
|
+
primary_name.gsub(%r(\.), '_')
|
325
|
+
end
|
326
|
+
|
327
|
+
def source_paths
|
328
|
+
source_files.map{ |file| Rake::Path.relative_path(file, rakefile_path) }
|
329
|
+
end
|
330
|
+
|
331
|
+
def compiler_flags
|
332
|
+
flags = include_path
|
333
|
+
options = compilation_options.join( ' ' )
|
334
|
+
flags << ' ' + options if options != ''
|
335
|
+
flags << ' ' + architecture_option if RUBY_PLATFORM =~ /darwin/i
|
336
|
+
flags
|
337
|
+
end
|
338
|
+
|
339
|
+
def library_dependencies_list
|
340
|
+
@library_dependencies.map { |lib| "-l#{ lib }"}.join('')
|
341
|
+
end
|
342
|
+
|
363
343
|
private
|
364
344
|
|
365
345
|
def initialize_attributes
|
@@ -402,7 +382,7 @@ EOT
|
|
402
382
|
raise BuilderError.new( "The target name cannot be an empty string", task_namespace ) if @target == ''
|
403
383
|
@objects_path = Rake::Path.expand_with_root( @objects_path, @rakefile_path )
|
404
384
|
@target = File.expand_path( @target, @rakefile_path )
|
405
|
-
@target_type ||=
|
385
|
+
@target_type ||= to_target_type( @target )
|
406
386
|
raise BuilderError.new( "Building #{ @target_type } targets is not supported", task_namespace ) if ! TARGET_TYPES.include?( @target_type )
|
407
387
|
|
408
388
|
@install_path ||= default_install_path( @target_type )
|
@@ -572,7 +552,7 @@ EOT
|
|
572
552
|
begin
|
573
553
|
shell "rm '#{ destination }'", Logger::INFO
|
574
554
|
rescue Errno::EACCES => e
|
575
|
-
raise BuilderError.new( "You do not have
|
555
|
+
raise BuilderError.new( "You do not have permission to uninstall '#{ destination }'\nTry\n $ sudo rake #{ scoped_task( :uninstall ) }", task_namespace )
|
576
556
|
end
|
577
557
|
end
|
578
558
|
|
@@ -660,7 +640,8 @@ EOT
|
|
660
640
|
file object => [ source ] do |t|
|
661
641
|
@logger.add( Logger::DEBUG, "Compiling '#{ source }'" )
|
662
642
|
command = "#{ @compiler } -c #{ compiler_flags } -o #{ object } #{ source }"
|
663
|
-
shell
|
643
|
+
stdout, stderr = shell(command)
|
644
|
+
raise BuildFailure.new("Error: command '#{command}' failed: #{stderr} #{stdout}") if not $?.success?
|
664
645
|
end
|
665
646
|
end
|
666
647
|
|
@@ -676,7 +657,7 @@ EOT
|
|
676
657
|
end
|
677
658
|
end
|
678
659
|
|
679
|
-
def
|
660
|
+
def to_target_type(target)
|
680
661
|
case target
|
681
662
|
when /\.a/
|
682
663
|
:static_library
|
@@ -703,14 +684,6 @@ EOT
|
|
703
684
|
paths.map { |p| "-I#{ p }" }.join( ' ' )
|
704
685
|
end
|
705
686
|
|
706
|
-
def compiler_flags
|
707
|
-
flags = include_path
|
708
|
-
options = compilation_options.join( ' ' )
|
709
|
-
flags << ' ' + options if options != ''
|
710
|
-
flags << ' ' + architecture_option if RUBY_PLATFORM =~ /darwin/i
|
711
|
-
flags
|
712
|
-
end
|
713
|
-
|
714
687
|
def architecture_option
|
715
688
|
"-arch #{ @architecture }"
|
716
689
|
end
|
@@ -794,10 +767,6 @@ EOT
|
|
794
767
|
def library_paths_list
|
795
768
|
@library_paths.map { | path | "-L#{ path }" }.join( " " )
|
796
769
|
end
|
797
|
-
|
798
|
-
def library_dependencies_list
|
799
|
-
@library_dependencies.map { | lib | "-l#{ lib }" }.join( " " )
|
800
|
-
end
|
801
770
|
|
802
771
|
def install_headers
|
803
772
|
# TODO: make install_headers_path a configuration option
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module Rake; class Builder; module Presenters; module MakefileAm
|
2
|
+
class BuilderCollectionPresenter
|
3
|
+
attr_accessor :builders
|
4
|
+
|
5
|
+
def initialize(builders)
|
6
|
+
@builders = builders
|
7
|
+
end
|
8
|
+
|
9
|
+
def to_s
|
10
|
+
programs_list + program_sections + libraries_list + library_sections
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def programs
|
16
|
+
@builders.reject(&:is_library?)
|
17
|
+
end
|
18
|
+
|
19
|
+
def libraries
|
20
|
+
@builders.select(&:is_library?)
|
21
|
+
end
|
22
|
+
|
23
|
+
def programs_list
|
24
|
+
'bin_PROGRAMS = ' + programs.map(&:label).join(' ') + "\n\n"
|
25
|
+
end
|
26
|
+
|
27
|
+
def libraries_list
|
28
|
+
'lib_LIBRARIES = ' + libraries.map(&:label).join(' ') + "\n\n"
|
29
|
+
end
|
30
|
+
|
31
|
+
def program_sections
|
32
|
+
programs.map do |program|
|
33
|
+
presenter = Rake::Builder::Presenters::MakefileAm::BuilderPresenter.new(program)
|
34
|
+
presenter.to_s
|
35
|
+
end.join("\n")
|
36
|
+
end
|
37
|
+
|
38
|
+
def library_sections
|
39
|
+
libraries.map do |lib|
|
40
|
+
presenter = Rake::Builder::Presenters::MakefileAm::BuilderPresenter.new(lib)
|
41
|
+
presenter.to_s
|
42
|
+
end.join("\n")
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end; end; end; end
|
46
|
+
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module Rake; class Builder; module Presenters; module MakefileAm
|
2
|
+
class BuilderPresenter
|
3
|
+
attr_accessor :builder
|
4
|
+
|
5
|
+
def initialize(builder)
|
6
|
+
@builder = builder
|
7
|
+
end
|
8
|
+
|
9
|
+
def to_s
|
10
|
+
[sources, cpp_flags, ld_flags, libraries, ''].compact.join("/n")
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def sources
|
16
|
+
"#{builder.label}_SOURCES = #{builder.source_paths.join(' ')}"
|
17
|
+
end
|
18
|
+
|
19
|
+
def cpp_flags
|
20
|
+
"#{builder.label}_CPPFLAGS = #{builder.compiler_flags}"
|
21
|
+
end
|
22
|
+
|
23
|
+
def ld_flags
|
24
|
+
if builder.is_library?
|
25
|
+
nil
|
26
|
+
else
|
27
|
+
"#{builder.label}_LDFLAGS = -L."
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def libraries
|
32
|
+
if builder.is_library?
|
33
|
+
nil
|
34
|
+
else
|
35
|
+
"#{builder.label}_LDADD = #{builder.library_dependencies_list}"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end; end; end; end
|
40
|
+
|
data/lib/rake/builder/version.rb
CHANGED
data/spec/autoconf_spec.rb
CHANGED
@@ -159,32 +159,11 @@ describe 'autoconf' do
|
|
159
159
|
end
|
160
160
|
|
161
161
|
context 'Makefile.am' do
|
162
|
-
|
163
162
|
it 'is created' do
|
164
|
-
|
165
|
-
with('Makefile.am', 'w')
|
166
|
-
|
167
|
-
Rake::Task['autoconf'].execute(@args)
|
168
|
-
end
|
163
|
+
Rake::Builder.should_receive(:create_makefile_am)
|
169
164
|
|
170
|
-
it 'has sources' do
|
171
165
|
Rake::Task['autoconf'].execute(@args)
|
172
|
-
|
173
|
-
@output['Makefile.am']. should =~ /the_executable_SOURCES\s*=\s+cpp_project\/main\.cpp/
|
174
166
|
end
|
175
|
-
|
176
|
-
it 'has flags' do
|
177
|
-
Rake::Task['autoconf'].execute(@args)
|
178
|
-
|
179
|
-
@output['Makefile.am']. should =~ /the_executable_CPPFLAGS\s*=/
|
180
|
-
end
|
181
|
-
|
182
|
-
it 'has libraries' do
|
183
|
-
Rake::Task['autoconf'].execute(@args)
|
184
|
-
|
185
|
-
@output['Makefile.am']. should =~ /the_executable_LDADD\s*=/
|
186
|
-
end
|
187
|
-
|
188
167
|
end
|
189
168
|
|
190
169
|
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Rake::Builder do
|
4
|
+
include RakeBuilderHelper
|
5
|
+
|
6
|
+
def builder(type)
|
7
|
+
c_task(type)
|
8
|
+
end
|
9
|
+
|
10
|
+
[
|
11
|
+
[:static_library, true],
|
12
|
+
[:shared_library, true],
|
13
|
+
[:executable, false]
|
14
|
+
].each do |type, is_library|
|
15
|
+
example type do
|
16
|
+
expect(builder(type).is_library?).to eq(is_library)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Rake::Builder::Presenters::MakefileAm::BuilderCollectionPresenter do
|
4
|
+
context '.new' do
|
5
|
+
it 'takes one parameter' do
|
6
|
+
expect {
|
7
|
+
Rake::Builder::Presenters::MakefileAm::BuilderCollectionPresenter.new
|
8
|
+
}.to raise_error(ArgumentError, 'wrong number of arguments (0 for 1)')
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
context '#to_s' do
|
13
|
+
let(:program_builder) { stub('Rake::Builder', :label => 'the_program', :is_library? => false) }
|
14
|
+
let(:library_builder) { stub('Rake::Builder', :label => 'the_library', :is_library? => true) }
|
15
|
+
let(:builders) { [program_builder, library_builder] }
|
16
|
+
|
17
|
+
subject { Rake::Builder::Presenters::MakefileAm::BuilderCollectionPresenter.new(builders) }
|
18
|
+
|
19
|
+
before do
|
20
|
+
Rake::Builder::Presenters::MakefileAm::BuilderPresenter.
|
21
|
+
stub(:new).
|
22
|
+
with(program_builder).
|
23
|
+
and_return("AAA\nBBB\n")
|
24
|
+
Rake::Builder::Presenters::MakefileAm::BuilderPresenter.
|
25
|
+
stub(:new).
|
26
|
+
with(library_builder).
|
27
|
+
and_return("XXX\nYYY\n")
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'lists libraries' do
|
31
|
+
expect(subject.to_s).to include("lib_LIBRARIES = the_library\n\n")
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'lists programs' do
|
35
|
+
expect(subject.to_s).to include("bin_PROGRAMS = the_program\n\n")
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'includes builder text' do
|
39
|
+
Rake::Builder::Presenters::MakefileAm::BuilderPresenter.
|
40
|
+
should_receive(:new).
|
41
|
+
with(program_builder).
|
42
|
+
and_return("AAA\nBBB\n")
|
43
|
+
Rake::Builder::Presenters::MakefileAm::BuilderPresenter.
|
44
|
+
should_receive(:new).
|
45
|
+
with(library_builder).
|
46
|
+
and_return("XXX\nYYY\n")
|
47
|
+
|
48
|
+
output = subject.to_s
|
49
|
+
|
50
|
+
expect(output).to include("AAA\nBBB\n")
|
51
|
+
expect(output).to include("XXX\nYYY\n")
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
@@ -0,0 +1,71 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Rake::Builder::Presenters::MakefileAm::BuilderPresenter do
|
4
|
+
context '.new' do
|
5
|
+
it 'takes one parameter' do
|
6
|
+
expect {
|
7
|
+
Rake::Builder::Presenters::MakefileAm::BuilderPresenter.new
|
8
|
+
}.to raise_error(ArgumentError, 'wrong number of arguments (0 for 1)')
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
context '#to_s' do
|
13
|
+
let(:builder) do
|
14
|
+
stub(
|
15
|
+
'Rake::Builder',
|
16
|
+
:is_library? => false,
|
17
|
+
:label => 'fubar',
|
18
|
+
:source_paths => ['path/to/1', 'path/to/2'],
|
19
|
+
:compiler_flags => '-D FOO -D BAR',
|
20
|
+
:library_dependencies_list => '-lfoo -lbar'
|
21
|
+
)
|
22
|
+
end
|
23
|
+
let(:library) do
|
24
|
+
builder.stub(:is_library? => true)
|
25
|
+
builder.stub(:library_dependencies_list => [])
|
26
|
+
builder
|
27
|
+
end
|
28
|
+
let(:binary) do
|
29
|
+
builder.stub(:is_library? => false)
|
30
|
+
builder
|
31
|
+
end
|
32
|
+
|
33
|
+
subject { Rake::Builder::Presenters::MakefileAm::BuilderPresenter.new(builder) }
|
34
|
+
|
35
|
+
it 'lists sources' do
|
36
|
+
sources_match = %r(fubar_SOURCES\s+=\s+path/to/1 path/to/2)
|
37
|
+
expect(subject.to_s).to match(sources_match)
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'shows cpp flags' do
|
41
|
+
expect(subject.to_s).to match(/fubar_CPPFLAGS\s+=\s+-D FOO -D BAR/)
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'ends with a blank line'
|
45
|
+
|
46
|
+
context 'library builder' do
|
47
|
+
subject { Rake::Builder::Presenters::MakefileAm::BuilderPresenter.new(library) }
|
48
|
+
|
49
|
+
it "doesn't show ld flags" do
|
50
|
+
expect(subject.to_s).to_not include('fubar_LDFLAGS')
|
51
|
+
end
|
52
|
+
|
53
|
+
it "doesn't list library dependencies" do
|
54
|
+
expect(subject.to_s).to_not include('fubar_LDADD')
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
context 'executable builder' do
|
59
|
+
subject { Rake::Builder::Presenters::MakefileAm::BuilderPresenter.new(binary) }
|
60
|
+
|
61
|
+
it 'shows ld flags' do
|
62
|
+
expect(subject.to_s).to match(%r(fubar_LDFLAGS\s+=\s+-L))
|
63
|
+
end
|
64
|
+
|
65
|
+
it "lists library dependencies" do
|
66
|
+
expect(subject.to_s).to match(%r(fubar_LDADD\s+=\s+-lfoo -lbar))
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|