rake-compiler 1.2.2 → 1.2.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/History.md +29 -1
- data/README.md +74 -63
- data/lib/rake/extensiontask.rb +37 -41
- metadata +2 -8
- data/spec/lib/rake/compiler_config_spec.rb +0 -54
- data/spec/lib/rake/extensiontask_spec.rb +0 -679
- data/spec/lib/rake/javaextensiontask_spec.rb +0 -237
- data/spec/spec.opts +0 -3
- data/spec/spec_helper.rb +0 -15
- data/spec/support/capture_output_helper.rb +0 -22
@@ -1,679 +0,0 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
2
|
-
|
3
|
-
require 'rake/extensiontask'
|
4
|
-
require 'rbconfig'
|
5
|
-
require 'yaml'
|
6
|
-
|
7
|
-
describe Rake::ExtensionTask do
|
8
|
-
context '#new' do
|
9
|
-
context '(basic)' do
|
10
|
-
it 'should raise an error if no name is provided' do
|
11
|
-
lambda {
|
12
|
-
Rake::ExtensionTask.new
|
13
|
-
}.should raise_error(RuntimeError, /Extension name must be provided/)
|
14
|
-
end
|
15
|
-
|
16
|
-
it 'should allow string as extension name assignation' do
|
17
|
-
ext = Rake::ExtensionTask.new('extension_one')
|
18
|
-
ext.name.should == 'extension_one'
|
19
|
-
end
|
20
|
-
|
21
|
-
it 'should allow symbol as extension name assignation' do
|
22
|
-
ext = Rake::ExtensionTask.new(:extension_one)
|
23
|
-
ext.name.should == 'extension_one'
|
24
|
-
end
|
25
|
-
|
26
|
-
it 'should allow string as extension name using block assignation' do
|
27
|
-
ext = Rake::ExtensionTask.new do |ext|
|
28
|
-
ext.name = 'extension_two'
|
29
|
-
end
|
30
|
-
ext.name.should == 'extension_two'
|
31
|
-
end
|
32
|
-
|
33
|
-
it 'should return itself for the block' do
|
34
|
-
from_block = nil
|
35
|
-
from_lasgn = Rake::ExtensionTask.new('extension_three') do |ext|
|
36
|
-
from_block = ext
|
37
|
-
end
|
38
|
-
from_block.should == from_lasgn
|
39
|
-
end
|
40
|
-
|
41
|
-
it 'should accept a gem specification as parameter' do
|
42
|
-
spec = mock_gem_spec
|
43
|
-
ext = Rake::ExtensionTask.new('extension_three', spec)
|
44
|
-
ext.gem_spec.should == spec
|
45
|
-
end
|
46
|
-
|
47
|
-
it 'should allow gem specification be defined using block assignation' do
|
48
|
-
spec = mock_gem_spec
|
49
|
-
ext = Rake::ExtensionTask.new('extension_four') do |ext|
|
50
|
-
ext.gem_spec = spec
|
51
|
-
end
|
52
|
-
ext.gem_spec.should == spec
|
53
|
-
end
|
54
|
-
|
55
|
-
it 'should allow forcing of platform' do
|
56
|
-
ext = Rake::ExtensionTask.new('weird_extension') do |ext|
|
57
|
-
ext.platform = 'universal-foo-bar-10.5'
|
58
|
-
end
|
59
|
-
ext.platform.should == 'universal-foo-bar-10.5'
|
60
|
-
end
|
61
|
-
|
62
|
-
it 'should allow extra sources to be added' do
|
63
|
-
ext = Rake::ExtensionTask.new('extension_one') do |ext|
|
64
|
-
ext.extra_sources << 'extra.c'
|
65
|
-
end
|
66
|
-
ext.extra_sources.should include('extra.c')
|
67
|
-
# Private API between the base task and the extension task
|
68
|
-
ext.send(:source_files).should include('extra.c')
|
69
|
-
end
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
context '(defaults)' do
|
74
|
-
before :each do
|
75
|
-
@ext = Rake::ExtensionTask.new('extension_one')
|
76
|
-
end
|
77
|
-
|
78
|
-
it 'should look for extconf script' do
|
79
|
-
@ext.config_script.should == 'extconf.rb'
|
80
|
-
end
|
81
|
-
|
82
|
-
it 'should dump intermediate files to tmp/' do
|
83
|
-
@ext.tmp_dir.should == 'tmp'
|
84
|
-
end
|
85
|
-
|
86
|
-
it 'should copy build extension into lib/' do
|
87
|
-
@ext.lib_dir.should == 'lib'
|
88
|
-
end
|
89
|
-
|
90
|
-
it 'should look for C/C++ files pattern (.c,.cc,.cpp)' do
|
91
|
-
@ext.source_pattern.should == "*.{c,cc,cpp}"
|
92
|
-
end
|
93
|
-
|
94
|
-
it 'should have no configuration options preset to delegate' do
|
95
|
-
@ext.config_options.should be_empty
|
96
|
-
end
|
97
|
-
|
98
|
-
it "should have no includes preset to delegate" do
|
99
|
-
@ext.config_includes.should be_empty
|
100
|
-
end
|
101
|
-
|
102
|
-
it 'should default to current platform' do
|
103
|
-
@ext.platform.should == RUBY_PLATFORM
|
104
|
-
end
|
105
|
-
|
106
|
-
it 'should default to no cross compilation' do
|
107
|
-
@ext.cross_compile.should == false
|
108
|
-
end
|
109
|
-
|
110
|
-
it 'should have no configuration options for cross compilation' do
|
111
|
-
@ext.cross_config_options.should be_empty
|
112
|
-
end
|
113
|
-
|
114
|
-
it "should have cross platform defined to 'i386-mingw32'" do
|
115
|
-
@ext.cross_platform.should == 'i386-mingw32'
|
116
|
-
end
|
117
|
-
end
|
118
|
-
|
119
|
-
context '(tasks)' do
|
120
|
-
before :each do
|
121
|
-
Rake.application.clear
|
122
|
-
CLEAN.clear
|
123
|
-
CLOBBER.clear
|
124
|
-
end
|
125
|
-
|
126
|
-
context '(one extension)' do
|
127
|
-
before :each do
|
128
|
-
allow(Rake::FileList).to receive(:[]).and_return(["ext/extension_one/source.c"], [])
|
129
|
-
@ext = Rake::ExtensionTask.new('extension_one')
|
130
|
-
@ext_bin = ext_bin('extension_one')
|
131
|
-
@platform = RUBY_PLATFORM
|
132
|
-
@ruby_ver = RUBY_VERSION
|
133
|
-
end
|
134
|
-
|
135
|
-
context 'compile' do
|
136
|
-
it 'should define as task' do
|
137
|
-
Rake::Task.task_defined?('compile').should == true
|
138
|
-
end
|
139
|
-
|
140
|
-
it "should depend on 'compile:{platform}'" do
|
141
|
-
Rake::Task['compile'].prerequisites.should include("compile:#{@platform}")
|
142
|
-
end
|
143
|
-
end
|
144
|
-
|
145
|
-
context 'compile:extension_one' do
|
146
|
-
it 'should define as task' do
|
147
|
-
Rake::Task.task_defined?('compile:extension_one').should == true
|
148
|
-
end
|
149
|
-
|
150
|
-
it "should depend on 'compile:extension_one:{platform}'" do
|
151
|
-
Rake::Task['compile:extension_one'].prerequisites.should include("compile:extension_one:#{@platform}")
|
152
|
-
end
|
153
|
-
end
|
154
|
-
|
155
|
-
context 'lib/extension_one.{so,bundle}' do
|
156
|
-
it 'should define as task' do
|
157
|
-
Rake::Task.task_defined?("lib/#{@ext_bin}").should == true
|
158
|
-
end
|
159
|
-
|
160
|
-
it "should depend on 'copy:extension_one:{platform}:{ruby_ver}'" do
|
161
|
-
Rake::Task["lib/#{@ext_bin}"].prerequisites.should include("copy:extension_one:#{@platform}:#{@ruby_ver}")
|
162
|
-
end
|
163
|
-
end
|
164
|
-
|
165
|
-
context 'tmp/{platform}/extension_one/{ruby_ver}/extension_one.{so,bundle}' do
|
166
|
-
it 'should define as task' do
|
167
|
-
Rake::Task.task_defined?("tmp/#{@platform}/extension_one/#{@ruby_ver}/#{@ext_bin}").should == true
|
168
|
-
end
|
169
|
-
|
170
|
-
it "should depend on 'tmp/{platform}/extension_one/{ruby_ver}/Makefile'" do
|
171
|
-
Rake::Task["tmp/#{@platform}/extension_one/#{@ruby_ver}/#{@ext_bin}"].prerequisites.should include("tmp/#{@platform}/extension_one/#{@ruby_ver}/Makefile")
|
172
|
-
end
|
173
|
-
|
174
|
-
it "should depend on 'ext/extension_one/source.c'" do
|
175
|
-
Rake::Task["tmp/#{@platform}/extension_one/#{@ruby_ver}/#{@ext_bin}"].prerequisites.should include("ext/extension_one/source.c")
|
176
|
-
end
|
177
|
-
|
178
|
-
it "should not depend on 'ext/extension_one/source.h'" do
|
179
|
-
Rake::Task["tmp/#{@platform}/extension_one/#{@ruby_ver}/#{@ext_bin}"].prerequisites.should_not include("ext/extension_one/source.h")
|
180
|
-
end
|
181
|
-
end
|
182
|
-
|
183
|
-
context 'tmp/{platform}/extension_one/{ruby_ver}/Makefile' do
|
184
|
-
it 'should define as task' do
|
185
|
-
Rake::Task.task_defined?("tmp/#{@platform}/extension_one/#{@ruby_ver}/Makefile").should == true
|
186
|
-
end
|
187
|
-
|
188
|
-
it "should depend on 'tmp/{platform}/extension_one/{ruby_ver}'" do
|
189
|
-
Rake::Task["tmp/#{@platform}/extension_one/#{@ruby_ver}/Makefile"].prerequisites.should include("tmp/#{@platform}/extension_one/#{@ruby_ver}")
|
190
|
-
end
|
191
|
-
|
192
|
-
it "should depend on 'ext/extension_one/extconf.rb'" do
|
193
|
-
Rake::Task["tmp/#{@platform}/extension_one/#{@ruby_ver}/Makefile"].prerequisites.should include("ext/extension_one/extconf.rb")
|
194
|
-
end
|
195
|
-
end
|
196
|
-
|
197
|
-
context 'clean' do
|
198
|
-
it "should include 'tmp/{platform}/extension_one/{ruby_ver}' in the pattern" do
|
199
|
-
CLEAN.should include("tmp/#{@platform}/extension_one/#{@ruby_ver}")
|
200
|
-
end
|
201
|
-
end
|
202
|
-
|
203
|
-
context 'clobber' do
|
204
|
-
it "should include 'lib/extension_one.{so,bundle}'" do
|
205
|
-
CLOBBER.should include("lib/#{@ext_bin}")
|
206
|
-
end
|
207
|
-
|
208
|
-
it "should include 'tmp'" do
|
209
|
-
CLOBBER.should include('tmp')
|
210
|
-
end
|
211
|
-
end
|
212
|
-
|
213
|
-
it "should warn when pre-compiled files exist in extension directory" do
|
214
|
-
allow(Rake::FileList).to receive(:[]).
|
215
|
-
and_return(["ext/extension_one/source.c"],
|
216
|
-
["ext/extension_one/source.o"])
|
217
|
-
|
218
|
-
_, err = capture_output do
|
219
|
-
Rake::ExtensionTask.new('extension_one')
|
220
|
-
end
|
221
|
-
err.should match(/rake-compiler found compiled files in 'ext\/extension_one' directory. Please remove them./)
|
222
|
-
end
|
223
|
-
end
|
224
|
-
|
225
|
-
context '(extension in custom location)' do
|
226
|
-
before :each do
|
227
|
-
allow(Rake::FileList).to receive(:[]).and_return(["ext/extension_one/source.c"], [])
|
228
|
-
@ext = Rake::ExtensionTask.new('extension_one') do |ext|
|
229
|
-
ext.ext_dir = 'custom/ext/foo'
|
230
|
-
end
|
231
|
-
@ext_bin = ext_bin('extension_one')
|
232
|
-
@platform = RUBY_PLATFORM
|
233
|
-
@ruby_ver = RUBY_VERSION
|
234
|
-
end
|
235
|
-
|
236
|
-
context 'tmp/{platform}/extension_one/{ruby_ver}/Makefile' do
|
237
|
-
it "should depend on 'custom/ext/foo/extconf.rb'" do
|
238
|
-
Rake::Task["tmp/#{@platform}/extension_one/#{@ruby_ver}/Makefile"].prerequisites.should include("custom/ext/foo/extconf.rb")
|
239
|
-
end
|
240
|
-
end
|
241
|
-
end
|
242
|
-
|
243
|
-
context '(native tasks)' do
|
244
|
-
before :each do
|
245
|
-
allow(Rake::FileList).to receive(:[]).and_return(["ext/extension_one/source.c"], [])
|
246
|
-
@spec = mock_gem_spec
|
247
|
-
@ext_bin = ext_bin('extension_one')
|
248
|
-
@platform = RUBY_PLATFORM
|
249
|
-
@ruby_ver = RUBY_VERSION
|
250
|
-
end
|
251
|
-
|
252
|
-
context 'native' do
|
253
|
-
before :each do
|
254
|
-
allow(@spec).to receive(:platform=).and_return('ruby')
|
255
|
-
end
|
256
|
-
|
257
|
-
it 'should define a task for building the supplied gem' do
|
258
|
-
Rake::ExtensionTask.new('extension_one', @spec)
|
259
|
-
Rake::Task.task_defined?('native:my_gem').should == true
|
260
|
-
end
|
261
|
-
|
262
|
-
it 'should define as task for pure ruby gems' do
|
263
|
-
Rake::Task.task_defined?('native').should == false
|
264
|
-
Rake::ExtensionTask.new('extension_one', @spec)
|
265
|
-
Rake::Task.task_defined?('native').should == true
|
266
|
-
end
|
267
|
-
|
268
|
-
it 'should not define a task for already native gems' do
|
269
|
-
allow(@spec).to receive(:platform).and_return('current')
|
270
|
-
Rake::ExtensionTask.new('extension_one', @spec)
|
271
|
-
Rake::Task.task_defined?('native').should == false
|
272
|
-
end
|
273
|
-
|
274
|
-
it 'should depend on platform specific native tasks' do
|
275
|
-
Rake::ExtensionTask.new('extension_one', @spec)
|
276
|
-
Rake::Task["native"].prerequisites.should include("native:#{@platform}")
|
277
|
-
end
|
278
|
-
|
279
|
-
context 'native:my_gem:{platform}' do
|
280
|
-
it 'should depend on binary extension' do
|
281
|
-
Rake::ExtensionTask.new('extension_one', @spec)
|
282
|
-
Rake::Task["native:my_gem:#{@platform}"].prerequisites.should include("tmp/#{@platform}/stage/lib/#{@ext_bin}")
|
283
|
-
end
|
284
|
-
end
|
285
|
-
end
|
286
|
-
end
|
287
|
-
|
288
|
-
context '(one extension whose name with directory prefixes)' do
|
289
|
-
before :each do
|
290
|
-
allow(Rake::FileList).to receive(:[]).and_return(["ext/prefix1/prefix2/extension_one/source.c"], [])
|
291
|
-
@ext = Rake::ExtensionTask.new('prefix1/prefix2/extension_one')
|
292
|
-
@ext_bin = ext_bin('extension_one')
|
293
|
-
@platform = RUBY_PLATFORM
|
294
|
-
@ruby_ver = RUBY_VERSION
|
295
|
-
end
|
296
|
-
|
297
|
-
context 'compile' do
|
298
|
-
it 'should define as task' do
|
299
|
-
Rake::Task.task_defined?('compile').should == true
|
300
|
-
end
|
301
|
-
|
302
|
-
it "should depend on 'compile:{platform}'" do
|
303
|
-
Rake::Task['compile'].prerequisites.should include("compile:#{@platform}")
|
304
|
-
end
|
305
|
-
end
|
306
|
-
|
307
|
-
context 'compile:prefix1/prefix2/extension_one' do
|
308
|
-
it 'should define as task' do
|
309
|
-
Rake::Task.task_defined?('compile:prefix1/prefix2/extension_one').should == true
|
310
|
-
end
|
311
|
-
|
312
|
-
it "should depend on 'compile:prefix1/prefix2/extension_one:{platform}'" do
|
313
|
-
Rake::Task['compile:prefix1/prefix2/extension_one'].prerequisites.should include("compile:prefix1/prefix2/extension_one:#{@platform}")
|
314
|
-
end
|
315
|
-
end
|
316
|
-
|
317
|
-
context 'lib/prefix1/prefix2/extension_one.{so,bundle}' do
|
318
|
-
it 'should define as task' do
|
319
|
-
Rake::Task.task_defined?("lib/prefix1/prefix2/#{@ext_bin}").should == true
|
320
|
-
end
|
321
|
-
|
322
|
-
it "should depend on 'copy:prefix1/prefix2/extension_one:{platform}:{ruby_ver}'" do
|
323
|
-
Rake::Task["lib/prefix1/prefix2/#{@ext_bin}"].prerequisites.should include("copy:prefix1/prefix2/extension_one:#{@platform}:#{@ruby_ver}")
|
324
|
-
end
|
325
|
-
end
|
326
|
-
|
327
|
-
context 'tmp/{platform}/prefix1/prefix2/extension_one/{ruby_ver}/prefix1/prefix2/extension_one.{so,bundle}' do
|
328
|
-
it 'should define as task' do
|
329
|
-
Rake::Task.task_defined?("tmp/#{@platform}/prefix1/prefix2/extension_one/#{@ruby_ver}/prefix1/prefix2/#{@ext_bin}").should == true
|
330
|
-
end
|
331
|
-
|
332
|
-
it "should depend on 'tmp/{platform}/prefix1/prefix2/extension_one/{ruby_ver}/Makefile'" do
|
333
|
-
Rake::Task["tmp/#{@platform}/prefix1/prefix2/extension_one/#{@ruby_ver}/prefix1/prefix2/#{@ext_bin}"].prerequisites.should include("tmp/#{@platform}/prefix1/prefix2/extension_one/#{@ruby_ver}/Makefile")
|
334
|
-
end
|
335
|
-
|
336
|
-
it "should depend on 'ext/extension_one/source.c'" do
|
337
|
-
Rake::Task["tmp/#{@platform}/prefix1/prefix2/extension_one/#{@ruby_ver}/prefix1/prefix2/#{@ext_bin}"].prerequisites.should include("ext/prefix1/prefix2/extension_one/source.c")
|
338
|
-
end
|
339
|
-
|
340
|
-
it "should not depend on 'ext/extension_one/source.h'" do
|
341
|
-
Rake::Task["tmp/#{@platform}/prefix1/prefix2/extension_one/#{@ruby_ver}/prefix1/prefix2/#{@ext_bin}"].prerequisites.should_not include("ext/prefix1/prefix2/extension_one/source.h")
|
342
|
-
end
|
343
|
-
end
|
344
|
-
end
|
345
|
-
|
346
|
-
context '(cross platform tasks)' do
|
347
|
-
before :each do
|
348
|
-
allow(File).to receive(:exist?).and_return(true)
|
349
|
-
allow(YAML).to receive(:load_file).and_return(mock_config_yml)
|
350
|
-
allow(Rake::FileList).to receive(:[]).and_return(["ext/extension_one/source.c"], [])
|
351
|
-
@spec = mock_gem_spec
|
352
|
-
@config_file = File.expand_path("~/.rake-compiler/config.yml")
|
353
|
-
@ruby_ver = RUBY_VERSION
|
354
|
-
@platform = 'i386-mingw32'
|
355
|
-
@config_path = mock_config_yml["rbconfig-#{@platform}-#{@ruby_ver}"]
|
356
|
-
|
357
|
-
allow(File).to receive(:open).and_yield(mock_fake_rb)
|
358
|
-
end
|
359
|
-
|
360
|
-
context 'if no rake-compiler configuration exists' do
|
361
|
-
before :each do
|
362
|
-
expect(File).to receive(:exist?).with(@config_file).and_return(false)
|
363
|
-
|
364
|
-
_, @err = capture_output do
|
365
|
-
Rake::ExtensionTask.new('extension_one') do |ext|
|
366
|
-
ext.cross_compile = true
|
367
|
-
end
|
368
|
-
end
|
369
|
-
end
|
370
|
-
|
371
|
-
it 'should not generate a warning' do
|
372
|
-
@err.should eq("")
|
373
|
-
end
|
374
|
-
|
375
|
-
it 'should create a dummy nested cross-compile target that raises an error' do
|
376
|
-
Rake::Task.should have_defined("cross")
|
377
|
-
Rake::Task["cross"].invoke
|
378
|
-
lambda {
|
379
|
-
Rake::Task["compile"].invoke
|
380
|
-
}.should raise_error(RuntimeError,
|
381
|
-
/rake-compiler must be configured first to enable cross-compilation/)
|
382
|
-
end
|
383
|
-
end
|
384
|
-
|
385
|
-
it 'should parse the config file using YAML' do
|
386
|
-
expect(YAML).to receive(:load_file).with(@config_file).and_return(mock_config_yml)
|
387
|
-
Rake::ExtensionTask.new('extension_one') do |ext|
|
388
|
-
ext.cross_compile = true
|
389
|
-
end
|
390
|
-
end
|
391
|
-
|
392
|
-
it 'should warn if no section of config file defines running version of ruby' do
|
393
|
-
allow_any_instance_of(Rake::CompilerConfig).to(
|
394
|
-
receive(:find).with(@ruby_ver, @platform).and_return(nil)
|
395
|
-
)
|
396
|
-
|
397
|
-
out, err = capture_output do
|
398
|
-
Rake::ExtensionTask.new('extension_one') do |ext|
|
399
|
-
ext.cross_compile = true
|
400
|
-
end
|
401
|
-
end
|
402
|
-
err.should match(/no configuration section for specified version of Ruby/)
|
403
|
-
end
|
404
|
-
|
405
|
-
it 'should capture an action block to be executed when cross compiling' do
|
406
|
-
lambda {
|
407
|
-
Rake::ExtensionTask.new('extension_one') do |ext|
|
408
|
-
ext.cross_compiling do |gem_spec|
|
409
|
-
gem_spec.post_install_message = "Cross compiled gem"
|
410
|
-
end
|
411
|
-
end
|
412
|
-
}.should_not raise_error
|
413
|
-
end
|
414
|
-
|
415
|
-
it 'should generate additional rake tasks if files are added when cross compiling' do
|
416
|
-
allow_any_instance_of(Rake::CompilerConfig).to(
|
417
|
-
receive(:find).and_return("/rubies/1.9.1/rbconfig.rb")
|
418
|
-
)
|
419
|
-
|
420
|
-
# Use a real spec instead of a mock because define_native_tasks dups and
|
421
|
-
# calls methods on Gem::Specification, which is more than mock can do.
|
422
|
-
spec = Gem::Specification.new do |s|
|
423
|
-
s.name = 'my_gem'
|
424
|
-
s.platform = Gem::Platform::RUBY
|
425
|
-
end
|
426
|
-
|
427
|
-
# Gem::PackageTask calls Rake::PackageTask which sets Gem.configuration.verbose,
|
428
|
-
# which initializes Gem::ConfigFile,
|
429
|
-
# which gets mad if it cannot find `sysconfdir`/gemrc
|
430
|
-
allow(Gem).to receive_message_chain(:configuration, :verbose=).and_return(true)
|
431
|
-
|
432
|
-
ENV['RUBY_CC_VERSION'] = '1.9.1'
|
433
|
-
Rake::ExtensionTask.new('extension_one', spec) do |ext|
|
434
|
-
ext.cross_compile = true
|
435
|
-
ext.cross_platform = 'universal-unknown'
|
436
|
-
ext.cross_compiling do |gem_spec|
|
437
|
-
gem_spec.files << 'somedir/somefile'
|
438
|
-
end
|
439
|
-
end
|
440
|
-
Rake::Task['native:my_gem:universal-unknown'].execute
|
441
|
-
Rake::Task.should have_defined("tmp/universal-unknown/stage/somedir")
|
442
|
-
Rake::Task.should have_defined("tmp/universal-unknown/stage/somedir/somefile")
|
443
|
-
end
|
444
|
-
|
445
|
-
it 'should allow usage of RUBY_CC_VERSION to indicate a different version of ruby' do
|
446
|
-
allow_any_instance_of(Rake::CompilerConfig).to(
|
447
|
-
receive(:find)
|
448
|
-
.with("1.9.1", "i386-mingw32")
|
449
|
-
.and_return("/rubies/1.9.1/rbconfig.rb")
|
450
|
-
)
|
451
|
-
|
452
|
-
ENV['RUBY_CC_VERSION'] = '1.9.1'
|
453
|
-
Rake::ExtensionTask.new('extension_one') do |ext|
|
454
|
-
ext.cross_compile = true
|
455
|
-
end
|
456
|
-
end
|
457
|
-
|
458
|
-
it 'should allow multiple versions be supplied to RUBY_CC_VERSION' do
|
459
|
-
allow_any_instance_of(Rake::CompilerConfig).to(
|
460
|
-
receive(:find)
|
461
|
-
.with("1.8.6", "i386-mingw32")
|
462
|
-
.and_return("/rubies/1.8.6/rbconfig.rb")
|
463
|
-
)
|
464
|
-
allow_any_instance_of(Rake::CompilerConfig).to(
|
465
|
-
receive(:find)
|
466
|
-
.with("1.9.1", "i386-mingw32")
|
467
|
-
.and_return("/rubies/1.9.1/rbconfig.rb")
|
468
|
-
)
|
469
|
-
|
470
|
-
ENV['RUBY_CC_VERSION'] = '1.8.6:1.9.1'
|
471
|
-
Rake::ExtensionTask.new('extension_one') do |ext|
|
472
|
-
ext.cross_compile = true
|
473
|
-
end
|
474
|
-
end
|
475
|
-
|
476
|
-
it "should set required_ruby_version from RUBY_CC_VERSION, set platform, clear extensions but keep metadata" do
|
477
|
-
platforms = ["x86-mingw32", "x64-mingw32"]
|
478
|
-
ruby_cc_versions = ["1.8.6", "2.1.10", "2.2.6", "2.3.3", "2.10.1", "2.11.0"]
|
479
|
-
ENV["RUBY_CC_VERSION"] = ruby_cc_versions.join(":")
|
480
|
-
|
481
|
-
ruby_cc_versions.each do |ruby_cc_version|
|
482
|
-
platforms.each do |platform|
|
483
|
-
unless platform == "x64-mingw32" && ruby_cc_version == "2.11.0"
|
484
|
-
rbconf = "/rubies/#{ruby_cc_version}/rbconfig.rb"
|
485
|
-
end
|
486
|
-
allow_any_instance_of(Rake::CompilerConfig).to(
|
487
|
-
receive(:find)
|
488
|
-
.with(ruby_cc_version, platform)
|
489
|
-
.and_return(rbconf)
|
490
|
-
)
|
491
|
-
end
|
492
|
-
end
|
493
|
-
|
494
|
-
allow(Gem).to receive_message_chain(:configuration, :verbose=).and_return(true)
|
495
|
-
|
496
|
-
spec = Gem::Specification.new do |s|
|
497
|
-
s.name = 'my_gem'
|
498
|
-
s.platform = Gem::Platform::RUBY
|
499
|
-
s.extensions = ['ext/somegem/extconf.rb']
|
500
|
-
s.metadata['allowed_push_host'] = 'http://test'
|
501
|
-
end
|
502
|
-
|
503
|
-
cross_specs = []
|
504
|
-
Rake::ExtensionTask.new("extension_one", spec) do |ext|
|
505
|
-
ext.cross_platform = platforms
|
506
|
-
ext.cross_compile = true
|
507
|
-
ext.cross_compiling do |cross_spec|
|
508
|
-
cross_specs << cross_spec
|
509
|
-
end
|
510
|
-
end
|
511
|
-
platforms.each do |platform|
|
512
|
-
Rake::Task["native:my_gem:#{platform}"].execute
|
513
|
-
end
|
514
|
-
|
515
|
-
expected_required_ruby_versions = [
|
516
|
-
Gem::Requirement.new([">= 1.8", "< 2.12.dev"]),
|
517
|
-
Gem::Requirement.new([">= 1.8", "< 2.11.dev"]),
|
518
|
-
]
|
519
|
-
cross_specs.collect(&:required_ruby_version).should == expected_required_ruby_versions
|
520
|
-
cross_specs.collect(&:extensions).should == [[], []]
|
521
|
-
cross_specs.collect(&:platform).collect(&:to_s).should == platforms
|
522
|
-
cross_specs.collect{|s| s.metadata['allowed_push_host']}.should == ['http://test', 'http://test']
|
523
|
-
|
524
|
-
# original gemspec should keep unchanged
|
525
|
-
spec.required_ruby_version.should == Gem::Requirement.new([">= 0"])
|
526
|
-
spec.platform.should == Gem::Platform::RUBY
|
527
|
-
spec.extensions.should == ['ext/somegem/extconf.rb']
|
528
|
-
spec.metadata['allowed_push_host'].should == 'http://test'
|
529
|
-
end
|
530
|
-
|
531
|
-
after :each do
|
532
|
-
ENV.delete('RUBY_CC_VERSION')
|
533
|
-
end
|
534
|
-
|
535
|
-
context "(cross compile for multiple versions)" do
|
536
|
-
before :each do
|
537
|
-
allow_any_instance_of(Rake::CompilerConfig).to(
|
538
|
-
receive(:find)
|
539
|
-
.with("1.8.6", "universal-unknown")
|
540
|
-
.and_return("/rubies/1.8.6/rbconfig.rb")
|
541
|
-
)
|
542
|
-
allow_any_instance_of(Rake::CompilerConfig).to(
|
543
|
-
receive(:find)
|
544
|
-
.with("1.9.1", "universal-unknown")
|
545
|
-
.and_return("/rubies/1.9.1/rbconfig.rb")
|
546
|
-
)
|
547
|
-
|
548
|
-
ENV['RUBY_CC_VERSION'] = '1.8.6:1.9.1'
|
549
|
-
@ext = Rake::ExtensionTask.new('extension_one') do |ext|
|
550
|
-
ext.cross_compile = true
|
551
|
-
ext.cross_platform = 'universal-unknown'
|
552
|
-
end
|
553
|
-
end
|
554
|
-
|
555
|
-
it 'should create specific copy of binaries for each version' do
|
556
|
-
Rake::Task.should have_defined("copy:extension_one:universal-unknown:1.8.6")
|
557
|
-
Rake::Task.should have_defined("copy:extension_one:universal-unknown:1.9.1")
|
558
|
-
end
|
559
|
-
end
|
560
|
-
|
561
|
-
context "(cross for 'universal-unknown' platform)" do
|
562
|
-
before :each do
|
563
|
-
@ext = Rake::ExtensionTask.new('extension_one', @spec) do |ext|
|
564
|
-
ext.cross_compile = true
|
565
|
-
ext.cross_platform = 'universal-unknown'
|
566
|
-
end
|
567
|
-
end
|
568
|
-
|
569
|
-
context 'fake' do
|
570
|
-
it 'should chain fake task to Makefile generation' do
|
571
|
-
Rake::Task["tmp/universal-unknown/extension_one/#{@ruby_ver}/Makefile"].prerequisites.should include("tmp/universal-unknown/extension_one/#{@ruby_ver}/fake.rb")
|
572
|
-
end
|
573
|
-
|
574
|
-
it 'should chain rbconfig tasks to fake.rb generation' do
|
575
|
-
Rake::Task["tmp/universal-unknown/extension_one/#{@ruby_ver}/fake.rb"].prerequisites.should include(@config_path)
|
576
|
-
end
|
577
|
-
end
|
578
|
-
|
579
|
-
context 'mkmf' do
|
580
|
-
it 'should chain mkmf tasks to Makefile generation' do
|
581
|
-
Rake::Task["tmp/universal-unknown/extension_one/#{@ruby_ver}/Makefile"].prerequisites.should include("tmp/universal-unknown/extension_one/#{@ruby_ver}/mkmf.rb")
|
582
|
-
end
|
583
|
-
|
584
|
-
it 'should take mkmf from rake-compiler configuration' do
|
585
|
-
mkmf_path = File.expand_path(File.join(File.dirname(@config_path), '..', 'mkmf.rb'))
|
586
|
-
Rake::Task["tmp/universal-unknown/extension_one/#{@ruby_ver}/mkmf.rb"].prerequisites.should include(mkmf_path)
|
587
|
-
end
|
588
|
-
end
|
589
|
-
|
590
|
-
context 'compile:universal-unknown' do
|
591
|
-
it "should be defined" do
|
592
|
-
Rake::Task.task_defined?('compile:universal-unknown').should == true
|
593
|
-
end
|
594
|
-
|
595
|
-
it "should depend on 'compile:extension_one:universal-unknown'" do
|
596
|
-
Rake::Task['compile:universal-unknown'].prerequisites.should include('compile:extension_one:universal-unknown')
|
597
|
-
end
|
598
|
-
end
|
599
|
-
|
600
|
-
context 'native:universal-unknown' do
|
601
|
-
it "should be defined" do
|
602
|
-
Rake::Task.task_defined?('native:universal-unknown').should == true
|
603
|
-
end
|
604
|
-
|
605
|
-
it "should depend on 'native:my_gem:universal-unknown'" do
|
606
|
-
Rake::Task['native:universal-unknown'].prerequisites.should include('native:my_gem:universal-unknown')
|
607
|
-
end
|
608
|
-
end
|
609
|
-
end
|
610
|
-
|
611
|
-
context '(cross for multiple platforms)' do
|
612
|
-
before :each do
|
613
|
-
@ext = Rake::ExtensionTask.new('extension_one', @spec) do |ext|
|
614
|
-
ext.cross_compile = true
|
615
|
-
ext.cross_platform = ['universal-known', 'universal-unknown']
|
616
|
-
ext.cross_config_options << '--with-something'
|
617
|
-
ext.cross_config_options << {'universal-known' => '--with-known'}
|
618
|
-
end
|
619
|
-
end
|
620
|
-
|
621
|
-
it 'should define task for each supplied platform' do
|
622
|
-
Rake::Task.should have_defined('compile:universal-known')
|
623
|
-
Rake::Task.should have_defined('compile:universal-unknown')
|
624
|
-
end
|
625
|
-
|
626
|
-
it 'should filter options for each supplied platform' do
|
627
|
-
@ext.cross_config_options('universal-unknown').should eq(%w[--with-something])
|
628
|
-
@ext.cross_config_options('universal-known').should eq(%w[--with-something --with-known])
|
629
|
-
end
|
630
|
-
end
|
631
|
-
end
|
632
|
-
end
|
633
|
-
|
634
|
-
private
|
635
|
-
def ext_bin(extension_name)
|
636
|
-
"#{extension_name}.#{RbConfig::CONFIG['DLEXT']}"
|
637
|
-
end
|
638
|
-
|
639
|
-
def mock_gem_spec(stubs = {})
|
640
|
-
double(Gem::Specification,
|
641
|
-
{ :name => 'my_gem', :platform => 'ruby', :files => [] }.merge(stubs)
|
642
|
-
)
|
643
|
-
end
|
644
|
-
|
645
|
-
def mock_config_yml
|
646
|
-
return @mock_config_yml if @mock_config_yml
|
647
|
-
|
648
|
-
versions = {
|
649
|
-
"1.8.6" => "1.8",
|
650
|
-
"1.8.7" => "1.8",
|
651
|
-
"1.9.3" => "1.9.1",
|
652
|
-
"2.0.0" => "2.0.0",
|
653
|
-
"2.1.2" => "2.1.0",
|
654
|
-
RUBY_VERSION => RbConfig::CONFIG["ruby_version"]
|
655
|
-
}
|
656
|
-
|
657
|
-
platforms = [
|
658
|
-
"i386-mingw32",
|
659
|
-
"universal-known",
|
660
|
-
"universal-unknown",
|
661
|
-
"x64-mingw32",
|
662
|
-
RUBY_PLATFORM
|
663
|
-
]
|
664
|
-
|
665
|
-
@mock_config_yml = {}
|
666
|
-
|
667
|
-
platforms.collect do |platform|
|
668
|
-
versions.each do |version, api_version|
|
669
|
-
@mock_config_yml["rbconfig-#{platform}-#{version}"] = "/rubies/#{api_version}/rbconfig.rb"
|
670
|
-
end
|
671
|
-
end
|
672
|
-
|
673
|
-
@mock_config_yml
|
674
|
-
end
|
675
|
-
|
676
|
-
def mock_fake_rb
|
677
|
-
double(File, :write => 45)
|
678
|
-
end
|
679
|
-
end
|