rake-builder 0.7.0 → 0.8.0
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/Rakefile +8 -5
- data/examples/05_tests/Rakefile +3 -3
- data/examples/05_tests/include/units.h +2 -2
- data/lib/compiler.rb +25 -30
- data/lib/rake/builder.rb +135 -136
- data/lib/rake/builder/installer.rb +37 -0
- data/lib/rake/{local_config.rb → builder/local_config.rb} +13 -14
- data/lib/rake/builder/logger/formatter.rb +7 -1
- data/lib/rake/builder/presenters/makefile/builder_presenter.rb +66 -33
- data/lib/rake/builder/presenters/makefile_am/builder_presenter.rb +4 -4
- data/lib/rake/builder/qt_builder.rb +3 -8
- data/lib/rake/builder/task_definers/builder_task_definer.rb +1 -4
- data/lib/rake/builder/version.rb +1 -1
- data/lib/rake/{microsecond.rb → microsecond_task.rb} +22 -27
- data/lib/rake/once_task.rb +2 -7
- data/lib/rake/path.rb +1 -6
- data/spec/gather_rspec_coverage.rb +2 -0
- data/spec/spec_helper.rb +13 -98
- data/spec/unit/compiler_spec.rb +129 -0
- data/spec/unit/rake/builder/autoconf/version_spec.rb +62 -5
- data/spec/unit/rake/builder/configure_ac_spec.rb +53 -0
- data/spec/unit/rake/builder/install_spec.rb +101 -0
- data/spec/unit/rake/builder/local_config_spec.rb +53 -0
- data/spec/unit/rake/builder/logger/formatter_spec.rb +20 -0
- data/spec/unit/rake/builder/presenters/makefile/builder_presenter_spec.rb +163 -0
- data/spec/unit/rake/builder/presenters/makefile_am/builder_presenter_spec.rb +4 -2
- data/spec/unit/rake/builder/task_definers/builder_task_definer_spec.rb +6 -0
- data/spec/unit/rake/builder_spec.rb +391 -16
- data/spec/unit/rake/microsecond_task_spec.rb +63 -0
- metadata +39 -55
- data/examples/01_hello_world_cpp/vendor/bundle/gems/coderay-1.0.8/Rakefile +0 -35
- data/examples/01_hello_world_cpp/vendor/bundle/gems/json-1.7.6/Rakefile +0 -412
- data/examples/01_hello_world_cpp/vendor/bundle/gems/json-1.7.6/ext/json/ext/fbuffer/fbuffer.h +0 -185
- data/examples/01_hello_world_cpp/vendor/bundle/gems/json-1.7.6/ext/json/ext/generator/generator.c +0 -1427
- data/examples/01_hello_world_cpp/vendor/bundle/gems/json-1.7.6/ext/json/ext/generator/generator.h +0 -149
- data/examples/01_hello_world_cpp/vendor/bundle/gems/json-1.7.6/ext/json/ext/parser/parser.c +0 -2204
- data/examples/01_hello_world_cpp/vendor/bundle/gems/json-1.7.6/ext/json/ext/parser/parser.h +0 -77
- data/examples/01_hello_world_cpp/vendor/bundle/gems/method_source-0.8.1/Rakefile +0 -79
- data/examples/01_hello_world_cpp/vendor/bundle/gems/pry-0.9.11.3/Rakefile +0 -136
- data/examples/01_hello_world_cpp/vendor/bundle/gems/rake-10.0.3/Rakefile +0 -374
- data/examples/01_hello_world_cpp/vendor/bundle/gems/rake-10.0.3/doc/example/a.c +0 -6
- data/examples/01_hello_world_cpp/vendor/bundle/gems/rake-10.0.3/doc/example/b.c +0 -6
- data/examples/01_hello_world_cpp/vendor/bundle/gems/rake-10.0.3/doc/example/main.c +0 -11
- data/examples/01_hello_world_cpp/vendor/bundle/gems/slop-3.4.3/Rakefile +0 -29
- data/lib/rake/file_task_alias.rb +0 -24
- data/spec/c_project/main.c +0 -12
- data/spec/c_project/main.h +0 -6
- data/spec/c_project_spec.rb +0 -41
- data/spec/cpp_project/main.cpp +0 -12
- data/spec/cpp_project/main.h +0 -8
- data/spec/cpp_project_spec.rb +0 -203
- data/spec/generated_files_spec.rb +0 -65
- data/spec/libraries_spec.rb +0 -35
- data/spec/local_config_spec.rb +0 -95
- data/spec/logger_spec.rb +0 -25
- data/spec/microsecond_task_spec.rb +0 -32
- data/spec/objective_c_project/main.h +0 -1
- data/spec/objective_c_project/main.m +0 -18
- data/spec/objective_c_project_spec.rb +0 -72
- data/spec/paths_spec.rb +0 -19
- data/spec/project_spec.rb +0 -20
- data/spec/target_spec.rb +0 -48
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Rake::Builder::LocalConfig do
|
4
|
+
let(:local_config_file) { 'local_config' }
|
5
|
+
let(:include_paths) { ['/foo/bar'] }
|
6
|
+
let(:compilation_options) { ['foo', 'bar'] }
|
7
|
+
let(:config_data) do
|
8
|
+
{
|
9
|
+
:rake_builder => {
|
10
|
+
:config_file => {:version => '1.1'},
|
11
|
+
},
|
12
|
+
:include_paths => include_paths,
|
13
|
+
:compilation_options => compilation_options,
|
14
|
+
}
|
15
|
+
end
|
16
|
+
let(:bad_config_data) do
|
17
|
+
config_data[:rake_builder][:config_file][:version] = '0.1'
|
18
|
+
config_data
|
19
|
+
end
|
20
|
+
|
21
|
+
before { YAML.stub(:load_file).and_return(config_data) }
|
22
|
+
|
23
|
+
subject { Rake::Builder::LocalConfig.new(local_config_file) }
|
24
|
+
|
25
|
+
context '#load' do
|
26
|
+
it 'loads the file' do
|
27
|
+
YAML.should_receive(:load_file).and_return(config_data)
|
28
|
+
|
29
|
+
subject.load
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'fails if the version is not recognized' do
|
33
|
+
YAML.should_receive(:load_file).and_return(bad_config_data)
|
34
|
+
|
35
|
+
expect {
|
36
|
+
subject.load
|
37
|
+
}.to raise_error(Rake::Builder::Error, /version incorrect/)
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'sets the include_paths' do
|
41
|
+
subject.load
|
42
|
+
|
43
|
+
expect(subject.include_paths).to eq(include_paths)
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'sets compilation_options' do
|
47
|
+
subject.load
|
48
|
+
|
49
|
+
expect(subject.compilation_options).to eq(compilation_options)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'Rake::Builder::Logger::Formatter' do
|
4
|
+
let(:formatter) { Rake::Builder::Logger::Formatter.new }
|
5
|
+
let(:stream) { StringIO.new }
|
6
|
+
let(:logger) do
|
7
|
+
logger = Logger.new(stream)
|
8
|
+
logger.formatter = formatter
|
9
|
+
logger
|
10
|
+
end
|
11
|
+
|
12
|
+
context '#call' do
|
13
|
+
it 'only prints the supplied string' do
|
14
|
+
logger.info 'foo'
|
15
|
+
|
16
|
+
expect(stream.string).to eq("foo\n")
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
@@ -0,0 +1,163 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Rake::Builder::Presenters::Makefile::BuilderPresenter do
|
4
|
+
def self.compiler; 'the_compiler'; end
|
5
|
+
def self.compiler_flags; 'the_compiler_flags'; end
|
6
|
+
def self.linker; 'the_linker'; end
|
7
|
+
def self.link_flags; 'the_link_flags'; end
|
8
|
+
def self.objects_path; '/objects'; end
|
9
|
+
|
10
|
+
let(:executable_target) { 'the_executable' }
|
11
|
+
let(:shared_library_target) { 'libshared.so' }
|
12
|
+
let(:static_library_target) { 'libstatic.a' }
|
13
|
+
let(:label) { 'the_label' }
|
14
|
+
let(:source_files) { ['/sources/one.c', '/sources/two.c'] }
|
15
|
+
let(:object_files) { ['/objects/one.o', '/objects/two.o'] }
|
16
|
+
let(:makefile_name) { 'the_makefile' }
|
17
|
+
let(:common_attributes) do
|
18
|
+
{
|
19
|
+
:label => label,
|
20
|
+
:compiler => self.class.compiler,
|
21
|
+
:compiler_flags => self.class.compiler_flags,
|
22
|
+
:linker => self.class.linker,
|
23
|
+
:link_flags => self.class.link_flags,
|
24
|
+
:objects_path => self.class.objects_path,
|
25
|
+
:source_files => source_files,
|
26
|
+
:object_files => object_files,
|
27
|
+
:makefile_name => makefile_name,
|
28
|
+
}
|
29
|
+
end
|
30
|
+
let(:executable_attributes) do
|
31
|
+
common_attributes.merge(
|
32
|
+
:target => executable_target,
|
33
|
+
:target_type => :executable,
|
34
|
+
)
|
35
|
+
end
|
36
|
+
let(:static_library_attributes) do
|
37
|
+
common_attributes.merge(
|
38
|
+
:target => static_library_target,
|
39
|
+
:target_type => :static_library,
|
40
|
+
)
|
41
|
+
end
|
42
|
+
let(:shared_library_attributes) do
|
43
|
+
common_attributes.merge(
|
44
|
+
:target => shared_library_target,
|
45
|
+
:target_type => :shared_library,
|
46
|
+
)
|
47
|
+
end
|
48
|
+
|
49
|
+
let(:executable_builder) { stub('Rake::Builder', executable_attributes) }
|
50
|
+
let(:static_library_builder) { stub('Rake::Builder', static_library_attributes) }
|
51
|
+
let(:shared_library_builder) { stub('Rake::Builder', shared_library_attributes) }
|
52
|
+
|
53
|
+
let(:executable_subject) { Rake::Builder::Presenters::Makefile::BuilderPresenter.new(executable_builder) }
|
54
|
+
let(:static_library_subject) { Rake::Builder::Presenters::Makefile::BuilderPresenter.new(static_library_builder) }
|
55
|
+
let(:shared_library_subject) { Rake::Builder::Presenters::Makefile::BuilderPresenter.new(shared_library_builder) }
|
56
|
+
|
57
|
+
context '.new' do
|
58
|
+
it 'takes one parameter' do
|
59
|
+
expect {
|
60
|
+
Rake::Builder::Presenters::Makefile::BuilderPresenter.new
|
61
|
+
}.to raise_error(ArgumentError, /wrong number of arguments/)
|
62
|
+
end
|
63
|
+
|
64
|
+
it 'fails with unknown target types' do
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
context '#to_s' do
|
69
|
+
it 'fails with unknown target types' do
|
70
|
+
executable_builder.should_receive(:target_type).any_number_of_times.and_return(:foo)
|
71
|
+
|
72
|
+
expect {
|
73
|
+
Rake::Builder::Presenters::Makefile::BuilderPresenter.new(executable_builder)
|
74
|
+
}.to raise_error(RuntimeError, /Unknown.*?target type/)
|
75
|
+
end
|
76
|
+
|
77
|
+
context 'target' do
|
78
|
+
context 'for executable' do
|
79
|
+
it 'is executable' do
|
80
|
+
expect(executable_subject.to_s).to include("EXECUTABLE_TARGET = #{executable_target}")
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
context 'for library' do
|
85
|
+
it 'is a library' do
|
86
|
+
expect(static_library_subject.to_s).to include("LIB_TARGET = #{static_library_target}")
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
context 'variables' do
|
92
|
+
[
|
93
|
+
['COMPILER', compiler],
|
94
|
+
['COMPILER_FLAGS', compiler_flags],
|
95
|
+
['LINKER', linker],
|
96
|
+
['LINK_FLAGS', link_flags],
|
97
|
+
['OBJECT_DIR', objects_path],
|
98
|
+
].each do |name, value|
|
99
|
+
it "declares '#{name}'" do
|
100
|
+
expect(executable_subject.to_s).to match(/#{name}\s+=\s+#{value}/)
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
it "declares 'OBJECTS'" do
|
105
|
+
expect(executable_subject.to_s).to match(%r(OBJECTS\s+=\s+\$\(OBJECT_DIR\)/one\.o \$\(OBJECT_DIR\)/two\.o))
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
context 'actions' do
|
110
|
+
context 'for executable' do
|
111
|
+
it 'builds the target' do
|
112
|
+
expected = <<EOT
|
113
|
+
$(EXECUTABLE_TARGET): $(OBJECTS)
|
114
|
+
$(LINKER) $(LINK_FLAGS) -o $(EXECUTABLE_TARGET) $(OBJECTS)
|
115
|
+
EOT
|
116
|
+
expect(executable_subject.to_s).to include(expected)
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
context 'for static library' do
|
121
|
+
it 'builds the target' do
|
122
|
+
expected = <<EOT
|
123
|
+
$(LIB_TARGET): $(OBJECTS)
|
124
|
+
rm -f $(LIB_TARGET)
|
125
|
+
ar -cq $(LIB_TARGET) $(OBJECTS)
|
126
|
+
ranlib $(LIB_TARGET)
|
127
|
+
EOT
|
128
|
+
expect(static_library_subject.to_s).to include(expected)
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
context 'for shared library' do
|
133
|
+
it 'builds the target' do
|
134
|
+
expected = <<EOT
|
135
|
+
$(LIB_TARGET): $(OBJECTS)
|
136
|
+
$(LINKER) -shared -o $(LIB_TARGET) $(OBJECTS) $(LINK_FLAGS)
|
137
|
+
EOT
|
138
|
+
expect(shared_library_subject.to_s).to include(expected)
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
context '#save' do
|
145
|
+
it 'creates the makefile' do
|
146
|
+
File.should_receive(:open).with(makefile_name, 'w')
|
147
|
+
|
148
|
+
executable_subject.save
|
149
|
+
end
|
150
|
+
|
151
|
+
it 'saves' do
|
152
|
+
file = stub('File')
|
153
|
+
File.stub(:open).with(makefile_name, 'w') do |&block|
|
154
|
+
block.call file
|
155
|
+
end
|
156
|
+
|
157
|
+
file.should_receive(:write).with(/COMPILER.*?= the_compiler/)
|
158
|
+
|
159
|
+
executable_subject.save
|
160
|
+
end
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
@@ -15,7 +15,7 @@ describe Rake::Builder::Presenters::MakefileAm::BuilderPresenter do
|
|
15
15
|
'Rake::Builder',
|
16
16
|
:is_library? => false,
|
17
17
|
:label => 'fubar',
|
18
|
-
:
|
18
|
+
:source_files => ['path/to/1', 'path/to/2'],
|
19
19
|
:compiler_flags => '-D FOO -D BAR',
|
20
20
|
:library_dependencies_list => '-lfoo -lbar'
|
21
21
|
)
|
@@ -41,7 +41,9 @@ describe Rake::Builder::Presenters::MakefileAm::BuilderPresenter do
|
|
41
41
|
expect(subject.to_s).to match(/fubar_CPPFLAGS\s+=\s+-D FOO -D BAR/)
|
42
42
|
end
|
43
43
|
|
44
|
-
it 'ends with a blank line'
|
44
|
+
it 'ends with a blank line' do
|
45
|
+
expect(subject.to_s).to end_with("\n")
|
46
|
+
end
|
45
47
|
|
46
48
|
context 'library builder' do
|
47
49
|
subject { Rake::Builder::Presenters::MakefileAm::BuilderPresenter.new(library) }
|
@@ -129,6 +129,12 @@ describe Rake::Builder::BuilderTaskDefiner do
|
|
129
129
|
|
130
130
|
expect(Rake::Task.task_defined?('foo')).to be_true
|
131
131
|
end
|
132
|
+
|
133
|
+
it 'does not fiddle up the local_config file' do
|
134
|
+
subject.run
|
135
|
+
|
136
|
+
expect(Rake::Task['foo:load_local_config'].prerequisites).to eq([namespaced_builder.local_config])
|
137
|
+
end
|
132
138
|
end
|
133
139
|
end
|
134
140
|
|
@@ -1,7 +1,26 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Rake::Builder do
|
4
|
-
include
|
4
|
+
include InputOutputTestHelper
|
5
|
+
|
6
|
+
let(:target_pathname) { File.join('foo', 'bar', 'my_prog.exe') }
|
7
|
+
let(:source_paths) { ['src/file1.cpp'] }
|
8
|
+
let(:builder) do
|
9
|
+
Rake::Builder.new do |b|
|
10
|
+
b.target = target_pathname
|
11
|
+
b.library_dependencies = ['foo', 'bar']
|
12
|
+
end
|
13
|
+
end
|
14
|
+
let(:installer) do
|
15
|
+
stub(
|
16
|
+
'Rake::Builder::Installer',
|
17
|
+
:install => nil
|
18
|
+
)
|
19
|
+
end
|
20
|
+
|
21
|
+
before do
|
22
|
+
Rake::Path.stub(:find_files).and_return(source_paths)
|
23
|
+
end
|
5
24
|
|
6
25
|
context '.create_autoconf' do
|
7
26
|
let(:version) { stub('Rake::Builder::Autoconf::Autoconf::Version', :decide => 'qux') }
|
@@ -59,41 +78,397 @@ describe Rake::Builder do
|
|
59
78
|
end
|
60
79
|
end
|
61
80
|
|
81
|
+
context '.new' do
|
82
|
+
it 'fails without a block' do
|
83
|
+
expect {
|
84
|
+
Rake::Builder.new
|
85
|
+
}.to raise_error(RuntimeError, 'No block given')
|
86
|
+
end
|
87
|
+
|
88
|
+
it 'raises an error when the target is an empty string' do
|
89
|
+
expect {
|
90
|
+
Rake::Builder.new { |b| b.target = '' }
|
91
|
+
}.to raise_error(Rake::Builder::Error, 'The target name cannot be an empty string')
|
92
|
+
end
|
93
|
+
|
94
|
+
it 'raises an error when the target is nil' do
|
95
|
+
expect {
|
96
|
+
Rake::Builder.new { |b| b.target = nil }
|
97
|
+
}.to raise_error(Rake::Builder::Error, 'The target name cannot be nil')
|
98
|
+
end
|
99
|
+
|
100
|
+
it 'raises an error when the supplied target_type is unknown' do
|
101
|
+
expect {
|
102
|
+
Rake::Builder.new { |b| b.target_type = :foo }
|
103
|
+
}.to raise_error(Rake::Builder::Error, 'Building foo targets is not supported')
|
104
|
+
end
|
105
|
+
|
106
|
+
it 'remembers the Rakefile path' do
|
107
|
+
Rake::Path.stub(:find_files => ['main.cpp'])
|
108
|
+
here = File.dirname(File.expand_path(__FILE__))
|
109
|
+
|
110
|
+
builder = Rake::Builder.new {}
|
111
|
+
|
112
|
+
expect(builder.rakefile_path).to eq(here)
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
context '#build' do
|
117
|
+
before do
|
118
|
+
@target_exists = [false, true]
|
119
|
+
File.stub(:exist?).with(builder.target) { @target_exists.shift }
|
120
|
+
builder.stub(:system => nil)
|
121
|
+
`(exit 0)` # set $? to a successful Process::Status
|
122
|
+
end
|
123
|
+
|
124
|
+
it 'checks if the old target exists' do
|
125
|
+
File.should_receive(:exist?).with(builder.target) { @target_exists.shift }
|
126
|
+
|
127
|
+
builder.build
|
128
|
+
end
|
129
|
+
|
130
|
+
it 'deletes the old target' do
|
131
|
+
@target_exists = [true, true]
|
132
|
+
|
133
|
+
File.should_receive(:unlink).with(builder.target)
|
134
|
+
|
135
|
+
builder.build
|
136
|
+
end
|
137
|
+
|
138
|
+
it 'fails if a build command fails' do
|
139
|
+
`(exit 1)` # set $? to a failing Process::Status
|
140
|
+
|
141
|
+
expect {
|
142
|
+
builder.build
|
143
|
+
}.to raise_error(Rake::Builder::BuildFailure, /command.*?failed/)
|
144
|
+
end
|
145
|
+
|
146
|
+
it 'fails if the target is missing afterwards' do
|
147
|
+
@target_exists = [false, false]
|
148
|
+
|
149
|
+
expect {
|
150
|
+
builder.build
|
151
|
+
}.to raise_error(Rake::Builder::BuildFailure, /not created/)
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
context '#run' do
|
156
|
+
before do
|
157
|
+
@old_dir = Dir.pwd
|
158
|
+
Dir.stub(:chdir).with(builder.rakefile_path)
|
159
|
+
builder.stub(:system)
|
160
|
+
Dir.stub(:chdir).with(@old_dir)
|
161
|
+
end
|
162
|
+
|
163
|
+
it 'changes directory to the Rakefile path' do
|
164
|
+
Dir.should_receive(:chdir).with(builder.rakefile_path)
|
165
|
+
|
166
|
+
capturing_output do
|
167
|
+
builder.run
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
it 'runs the executable' do
|
172
|
+
builder.should_receive(:system).with('./' + builder.target, anything)
|
173
|
+
|
174
|
+
capturing_output do
|
175
|
+
builder.run
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
179
|
+
it 'outputs the stdout results, then the stderr results' do
|
180
|
+
builder.stub(:system) do |command|
|
181
|
+
$stdout.puts 'standard output'
|
182
|
+
$stderr.puts 'error output'
|
183
|
+
end
|
184
|
+
|
185
|
+
stdout, stderr = capturing_output do
|
186
|
+
builder.run
|
187
|
+
end
|
188
|
+
|
189
|
+
expect(stdout).to eq("standard output\n")
|
190
|
+
expect(stderr).to eq("error output\n")
|
191
|
+
end
|
192
|
+
|
193
|
+
it 'raises and error is the program does not run successfully' do
|
194
|
+
builder.stub(:system) { `(exit 1)` } # set $? to a failing Process::Status
|
195
|
+
|
196
|
+
expect {
|
197
|
+
builder.run
|
198
|
+
}.to raise_error(Exception, /Running.*?failed with status 1/)
|
199
|
+
end
|
200
|
+
|
201
|
+
it 'restores the preceding working directory, even after errors' do
|
202
|
+
builder.stub(:system).and_raise('foo')
|
203
|
+
|
204
|
+
Dir.should_receive(:chdir).with(@old_dir)
|
205
|
+
|
206
|
+
builder.run rescue nil
|
207
|
+
end
|
208
|
+
end
|
209
|
+
|
210
|
+
context '#clean' do
|
211
|
+
it 'checks if files exist' do
|
212
|
+
exists = []
|
213
|
+
File.stub(:exist?) { |file| exists << file; false }
|
214
|
+
|
215
|
+
builder.clean
|
216
|
+
|
217
|
+
expect(exists).to eq(builder.generated_files)
|
218
|
+
end
|
219
|
+
|
220
|
+
it 'deletes generated files' do
|
221
|
+
deletes = []
|
222
|
+
File.stub(:exist? => true)
|
223
|
+
File.stub(:unlink) { |file| deletes << file }
|
224
|
+
|
225
|
+
builder.clean
|
226
|
+
|
227
|
+
expect(deletes).to eq(builder.generated_files)
|
228
|
+
end
|
229
|
+
end
|
230
|
+
|
231
|
+
context '#header_search_paths' do
|
232
|
+
it 'is deprecated' do
|
233
|
+
stdout, stderr = capturing_output do
|
234
|
+
builder.header_search_paths
|
235
|
+
end
|
236
|
+
|
237
|
+
expect(stderr).to include('Deprecation notice')
|
238
|
+
end
|
239
|
+
end
|
240
|
+
|
241
|
+
context '#header_search_paths=' do
|
242
|
+
it 'is deprecated' do
|
243
|
+
stdout, stderr = capturing_output do
|
244
|
+
builder.header_search_paths = []
|
245
|
+
end
|
246
|
+
|
247
|
+
expect(stderr).to include('Deprecation notice')
|
248
|
+
end
|
249
|
+
end
|
250
|
+
|
251
|
+
context '#target' do
|
252
|
+
it "defaults to 'a.out'" do
|
253
|
+
Rake::Path.stub(:find_files => ['main.cpp'])
|
254
|
+
|
255
|
+
builder = Rake::Builder.new {}
|
256
|
+
|
257
|
+
expect(builder.target).to end_with('/a.out')
|
258
|
+
end
|
259
|
+
end
|
260
|
+
|
62
261
|
context '#primary_name' do
|
63
262
|
it 'returns a relative path' do
|
64
|
-
|
65
|
-
target_pathname = File.join(here, 'my_prog')
|
66
|
-
builder = cpp_task(:executable) { |b| b.target = target_pathname }
|
67
|
-
|
68
|
-
expect(builder.primary_name).to eq(File.join('unit', 'rake', 'my_prog'))
|
263
|
+
expect(builder.primary_name).to eq(File.join('foo', 'bar', 'my_prog.exe'))
|
69
264
|
end
|
70
265
|
end
|
71
266
|
|
72
267
|
context '#label' do
|
73
268
|
it 'replaces dots with underscores' do
|
74
|
-
builder
|
269
|
+
expect(builder.label).to eq(File.join('foo', 'bar', 'my_prog_exe'))
|
270
|
+
end
|
271
|
+
end
|
272
|
+
|
273
|
+
context '#target_type' do
|
274
|
+
[
|
275
|
+
['my_program', :executable],
|
276
|
+
['libstatic.a', :static_library],
|
277
|
+
['libshared.so', :shared_library],
|
278
|
+
].each do |name, type|
|
279
|
+
it "recognises '#{name}' as '#{type}'" do
|
280
|
+
Rake::Path.stub(:find_files).and_return(['file'])
|
75
281
|
|
76
|
-
|
282
|
+
builder = Rake::Builder.new { |b| b.target = name }
|
283
|
+
|
284
|
+
expect(builder.target_type).to eq(type)
|
285
|
+
end
|
77
286
|
end
|
78
287
|
end
|
79
288
|
|
80
|
-
context '#
|
81
|
-
|
82
|
-
|
289
|
+
context '#is_library?' do
|
290
|
+
[
|
291
|
+
[:static_library, 'libbaz.a', true],
|
292
|
+
[:shared_library, 'libfoo.so', true],
|
293
|
+
[:executable, 'baz', false]
|
294
|
+
].each do |type, target, is_library|
|
295
|
+
example type do
|
296
|
+
builder = Rake::Builder.new do |b|
|
297
|
+
b.target = target
|
298
|
+
end
|
299
|
+
expect(builder.is_library?).to eq(is_library)
|
300
|
+
end
|
301
|
+
end
|
302
|
+
end
|
303
|
+
|
304
|
+
context '#source_files' do
|
305
|
+
it 'finds files with the .cpp extension' do
|
306
|
+
Rake::Path.should_receive(:find_files).with(anything, 'cpp').and_return(['a.cpp'])
|
307
|
+
|
308
|
+
builder
|
309
|
+
end
|
310
|
+
|
311
|
+
it 'should allow configuration of source extension' do
|
312
|
+
Rake::Path.should_receive(:find_files).with(anything, 'cc').and_return(['a.cc'])
|
83
313
|
|
84
|
-
|
314
|
+
Rake::Builder.new do |b|
|
315
|
+
b.source_file_extension = 'cc'
|
316
|
+
end
|
85
317
|
end
|
86
318
|
end
|
87
319
|
|
88
|
-
context '#
|
89
|
-
|
320
|
+
context '#object_path' do
|
321
|
+
let(:source_path) { 'foo/bar/baz.cpp' }
|
90
322
|
|
323
|
+
subject { builder.object_path(source_path) }
|
324
|
+
|
325
|
+
it 'substitutes the source extension with the object one' do
|
326
|
+
expect(subject).to end_with('.o')
|
327
|
+
end
|
328
|
+
|
329
|
+
it 'adds the objects path' do
|
330
|
+
expect(subject).to start_with(builder.objects_path)
|
331
|
+
end
|
332
|
+
end
|
333
|
+
|
334
|
+
context '#library_dependencies_list' do
|
91
335
|
it 'is a string' do
|
92
|
-
expect(
|
336
|
+
expect(builder.library_dependencies_list).to be_a(String)
|
93
337
|
end
|
94
338
|
|
95
339
|
it 'lists libraries' do
|
96
|
-
expect(
|
340
|
+
expect(builder.library_dependencies_list).to eq('-lfoo -lbar')
|
341
|
+
end
|
342
|
+
end
|
343
|
+
|
344
|
+
context '#create_makedepend_file' do
|
345
|
+
before do
|
346
|
+
builder.stub(:system).with('which makedepend >/dev/null') do
|
347
|
+
`(exit 0)` # set $? to a successful Process::Status
|
348
|
+
end
|
349
|
+
|
350
|
+
builder.stub(:system).with(/makedepend -f-/, anything)
|
351
|
+
end
|
352
|
+
|
353
|
+
it 'fails if makedepend is missing' do
|
354
|
+
builder.stub(:system).with('which makedepend >/dev/null') do
|
355
|
+
`(exit 1)` # set $? to a successful Process::Status
|
356
|
+
end
|
357
|
+
|
358
|
+
expect {
|
359
|
+
builder.create_makedepend_file
|
360
|
+
}.to raise_error(RuntimeError, 'makedepend not found')
|
361
|
+
end
|
362
|
+
|
363
|
+
it 'calls makedepend' do
|
364
|
+
builder.should_receive(:system).with(/makedepend -f-/, anything)
|
365
|
+
|
366
|
+
builder.create_makedepend_file
|
367
|
+
end
|
368
|
+
end
|
369
|
+
|
370
|
+
context '#load_makedepend' do
|
371
|
+
let(:content) do
|
372
|
+
lines = []
|
373
|
+
lines << 'Some text'
|
374
|
+
builder.source_files.each do |f|
|
375
|
+
source_path_object = f.gsub(/\.[^\.]+$/, '.o')
|
376
|
+
lines << source_path_object + ': header1.h'
|
377
|
+
end
|
378
|
+
lines.join("\n")
|
379
|
+
end
|
380
|
+
|
381
|
+
before do
|
382
|
+
File.stub(:read).with(builder.makedepend_file).and_return(content)
|
383
|
+
end
|
384
|
+
|
385
|
+
it 'opens the file' do
|
386
|
+
File.should_receive(:read).with(builder.makedepend_file).and_return(content)
|
387
|
+
|
388
|
+
builder.load_makedepend
|
389
|
+
end
|
390
|
+
|
391
|
+
it 'returns a map of sources to headers' do
|
392
|
+
expected = builder.object_files.reduce({}) do |a, e|
|
393
|
+
a[e] = ['header1.h']
|
394
|
+
a
|
395
|
+
end
|
396
|
+
|
397
|
+
expect(builder.load_makedepend).to eq(expected)
|
398
|
+
end
|
399
|
+
end
|
400
|
+
|
401
|
+
context '#load_local_config' do
|
402
|
+
let(:config_include_paths) { ['/path/one', '/path/two'] }
|
403
|
+
let(:config_compilation_options) { ['opt1', 'opt2'] }
|
404
|
+
let(:local_config) do
|
405
|
+
stub(
|
406
|
+
'Rake::Builder::LocalConfig',
|
407
|
+
:load => nil,
|
408
|
+
:include_paths => config_include_paths,
|
409
|
+
:compilation_options => config_compilation_options,
|
410
|
+
)
|
411
|
+
end
|
412
|
+
|
413
|
+
before { Rake::Builder::LocalConfig.stub(:new => local_config) }
|
414
|
+
|
415
|
+
it 'loads local config' do
|
416
|
+
Rake::Builder::LocalConfig.should_receive(:new).
|
417
|
+
with(/\.rake-builder/).and_return(local_config)
|
418
|
+
local_config.should_receive(:load).with()
|
419
|
+
|
420
|
+
builder.load_local_config
|
421
|
+
end
|
422
|
+
|
423
|
+
it 'adds include paths' do
|
424
|
+
original = builder.include_paths.clone
|
425
|
+
|
426
|
+
builder.load_local_config
|
427
|
+
|
428
|
+
expect(builder.include_paths).to eq(original + config_include_paths)
|
429
|
+
end
|
430
|
+
|
431
|
+
it 'adds compilation options' do
|
432
|
+
original = builder.compilation_options.clone
|
433
|
+
|
434
|
+
builder.load_local_config
|
435
|
+
|
436
|
+
expect(builder.compilation_options).to eq(original + config_compilation_options)
|
437
|
+
end
|
438
|
+
end
|
439
|
+
|
440
|
+
context '#install' do
|
441
|
+
before { Rake::Builder::Installer.stub(:new).and_return(installer) }
|
442
|
+
|
443
|
+
it 'installs the target' do
|
444
|
+
Rake::Builder::Installer.should_receive(:new).and_return(installer)
|
445
|
+
installer.should_receive(:install).with(builder.target, anything)
|
446
|
+
|
447
|
+
builder.install
|
448
|
+
end
|
449
|
+
|
450
|
+
it 'installs headers for static libraries' do
|
451
|
+
installer.stub(:install).with(builder.target, anything)
|
452
|
+
File.should_receive(:file?).with('header.h').and_return(true)
|
453
|
+
installer.should_receive(:install).with('header.h', anything)
|
454
|
+
|
455
|
+
builder = Rake::Builder.new do |b|
|
456
|
+
b.target = 'libthe_static_library.a'
|
457
|
+
b.installable_headers = ['header.h']
|
458
|
+
end
|
459
|
+
|
460
|
+
builder.install
|
461
|
+
end
|
462
|
+
end
|
463
|
+
|
464
|
+
context '#uninstall' do
|
465
|
+
before { Rake::Builder::Installer.stub(:new).and_return(installer) }
|
466
|
+
|
467
|
+
it 'uninstalls' do
|
468
|
+
installed_path = File.join(builder.install_path, builder.target_basename)
|
469
|
+
installer.should_receive(:uninstall).with(installed_path)
|
470
|
+
|
471
|
+
builder.uninstall
|
97
472
|
end
|
98
473
|
end
|
99
474
|
end
|