rake-compiler 0.3.0 → 0.5.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.
@@ -7,10 +7,10 @@ require 'rake'
7
7
  require 'rake/clean'
8
8
  require 'rake/tasklib'
9
9
  require 'rbconfig'
10
+ require 'yaml'
10
11
 
11
12
  module Rake
12
13
  autoload :GemPackageTask, 'rake/gempackagetask'
13
- autoload :YAML, 'yaml'
14
14
 
15
15
  class ExtensionTask < TaskLib
16
16
  attr_accessor :name
@@ -37,7 +37,7 @@ module Rake
37
37
  @gem_spec = gem_spec
38
38
  @config_script = 'extconf.rb'
39
39
  @tmp_dir = 'tmp'
40
- @ext_dir = 'ext'
40
+ @ext_dir = "ext/#{@name}"
41
41
  @lib_dir = 'lib'
42
42
  @source_pattern = "*.c"
43
43
  @config_options = []
@@ -62,8 +62,13 @@ module Rake
62
62
  define_native_tasks if @gem_spec && @gem_spec.platform == 'ruby'
63
63
 
64
64
  # only define cross platform functionality when enabled
65
- # FIXME: there is no value for having this on Windows or JRuby
66
- define_cross_platform_tasks if @cross_compile
65
+ return unless @cross_compile
66
+
67
+ if cross_platform.is_a?(Array) then
68
+ cross_platform.each { |platf| define_cross_platform_tasks(platf) }
69
+ else
70
+ define_cross_platform_tasks(cross_platform)
71
+ end
67
72
  end
68
73
 
69
74
  private
@@ -76,7 +81,7 @@ module Rake
76
81
 
77
82
  # cleanup and clobbering
78
83
  CLEAN.include(tmp_path)
79
- CLOBBER.include("#{@lib_dir}/#{binary}")
84
+ CLOBBER.include("#{@lib_dir}/#{binary(platf)}")
80
85
  CLOBBER.include("#{@tmp_dir}")
81
86
 
82
87
  # directories we need
@@ -85,13 +90,13 @@ module Rake
85
90
 
86
91
  # copy binary from temporary location to final lib
87
92
  # tmp/extension_name/extension_name.{so,bundle} => lib/
88
- task "copy:#{@name}:#{platf}" => [lib_dir, "#{tmp_path}/#{binary}"] do
89
- cp "#{tmp_path}/#{binary}", "#{@lib_dir}/#{binary}"
93
+ task "copy:#{@name}:#{platf}" => [lib_dir, "#{tmp_path}/#{binary(platf)}"] do
94
+ cp "#{tmp_path}/#{binary(platf)}", "#{@lib_dir}/#{binary(platf)}"
90
95
  end
91
96
 
92
97
  # binary in temporary folder depends on makefile and source files
93
98
  # tmp/extension_name/extension_name.{so,bundle}
94
- file "#{tmp_path}/#{binary}" => ["#{tmp_path}/Makefile"] + source_files do
99
+ file "#{tmp_path}/#{binary(platf)}" => ["#{tmp_path}/Makefile"] + source_files do
95
100
  chdir tmp_path do
96
101
  sh make
97
102
  end
@@ -102,17 +107,30 @@ module Rake
102
107
  file "#{tmp_path}/Makefile" => [tmp_path, extconf] do |t|
103
108
  options = @config_options.dup
104
109
 
110
+ # include current directory
111
+ cmd = ['-I.']
112
+
113
+ # if fake.rb is present, add to the command line
114
+ if t.prerequisites.include?("#{tmp_path}/fake.rb") then
115
+ cmd << '-rfake'
116
+ end
117
+
118
+ # now add the extconf script
119
+ cmd << File.join(Dir.pwd, extconf)
120
+
105
121
  # rbconfig.rb will be present if we are cross compiling
106
122
  if t.prerequisites.include?("#{tmp_path}/rbconfig.rb") then
107
123
  options.push(*@cross_config_options)
108
124
  end
109
125
 
110
- parent = Dir.pwd
126
+ # add options to command
127
+ cmd.push(*options)
128
+
111
129
  chdir tmp_path do
112
130
  # FIXME: Rake is broken for multiple arguments system() calls.
113
131
  # Add current directory to the search path of Ruby
114
132
  # Also, include additional parameters supplied.
115
- ruby ['-I.', File.join(parent, extconf), *options].join(' ')
133
+ ruby cmd.join(' ')
116
134
  end
117
135
  end
118
136
 
@@ -128,7 +146,7 @@ module Rake
128
146
  task "compile:#{@name}"
129
147
  end
130
148
 
131
- # Allow segmented compilation by platfrom (open door for 'cross compile')
149
+ # Allow segmented compilation by platform (open door for 'cross compile')
132
150
  task "compile:#{@name}:#{platf}" => ["copy:#{@name}:#{platf}"]
133
151
  task "compile:#{platf}" => ["compile:#{@name}:#{platf}"]
134
152
 
@@ -136,7 +154,7 @@ module Rake
136
154
  # platform matches the indicated one.
137
155
  if platf == RUBY_PLATFORM then
138
156
  # ensure file is always copied
139
- file "#{@lib_dir}/#{binary}" => ["copy:#{name}:#{platf}"]
157
+ file "#{@lib_dir}/#{binary(platf)}" => ["copy:#{name}:#{platf}"]
140
158
 
141
159
  task "compile:#{@name}" => ["compile:#{@name}:#{platf}"]
142
160
  task "compile" => ["compile:#{platf}"]
@@ -150,12 +168,14 @@ module Rake
150
168
  tmp_path = "#{@tmp_dir}/#{platf}/#{@name}"
151
169
 
152
170
  # create 'native:gem_name' and chain it to 'native' task
153
- spec = @gem_spec.dup
154
-
155
171
  unless Rake::Task.task_defined?("native:#{@gem_spec.name}:#{platf}")
156
172
  task "native:#{@gem_spec.name}:#{platf}" do |t|
173
+ # FIXME: truly duplicate the Gem::Specification
174
+ # workaround the lack of #dup for Gem::Specification
175
+ spec = Gem::Specification.from_yaml(gem_spec.to_yaml)
176
+
157
177
  # adjust to specified platform
158
- spec.platform = platf
178
+ spec.platform = Gem::Platform.new(platf)
159
179
 
160
180
  # clear the extensions defined in the specs
161
181
  spec.extensions.clear
@@ -173,6 +193,11 @@ module Rake
173
193
  # include the files in the gem specification
174
194
  spec.files += ext_files
175
195
 
196
+ # Make sure that the required ruby version matches the ruby version
197
+ # we've used for cross compiling:
198
+ target_version = RUBY_VERSION =~ /^1.8/ ? '1.8.6' : '1.9.0'
199
+ spec.required_ruby_version = "~> #{target_version}"
200
+
176
201
  # Generate a package for this gem
177
202
  gem_package = Rake::GemPackageTask.new(spec) do |pkg|
178
203
  pkg.need_zip = false
@@ -185,7 +210,7 @@ module Rake
185
210
  end
186
211
 
187
212
  # add binaries to the dependency chain
188
- task "native:#{@gem_spec.name}:#{platf}" => ["#{tmp_path}/#{binary}"]
213
+ task "native:#{@gem_spec.name}:#{platf}" => ["#{tmp_path}/#{binary(platf)}"]
189
214
 
190
215
  # Allow segmented packaging by platfrom (open door for 'cross compile')
191
216
  task "native:#{platf}" => ["native:#{@gem_spec.name}:#{platf}"]
@@ -198,9 +223,9 @@ module Rake
198
223
  end
199
224
  end
200
225
 
201
- def define_cross_platform_tasks
226
+ def define_cross_platform_tasks(for_platform)
202
227
  config_path = File.expand_path("~/.rake-compiler/config.yml")
203
- major_ver = (ENV['RUBY_CC_VERSION'] || RUBY_VERSION).match(/(\d+.\d+)/)[1]
228
+ ruby_ver = ENV['RUBY_CC_VERSION'] || RUBY_VERSION
204
229
 
205
230
  # warn the user about the need of configuration to use cross compilation.
206
231
  unless File.exist?(config_path)
@@ -211,60 +236,102 @@ module Rake
211
236
  config_file = YAML.load_file(config_path)
212
237
 
213
238
  # tmp_path
214
- tmp_path = "#{@tmp_dir}/#{cross_platform}/#{@name}"
239
+ tmp_path = "#{@tmp_dir}/#{for_platform}/#{@name}"
215
240
 
216
- unless rbconfig_file = config_file["rbconfig-#{major_ver}"] then
217
- fail "no configuration section for this version of Ruby (rbconfig-#{major_ver})"
241
+ unless rbconfig_file = config_file["rbconfig-#{ruby_ver}"] then
242
+ warn "no configuration section for specified version of Ruby (rbconfig-#{ruby_ver})"
243
+ return
218
244
  end
219
245
 
220
246
  # define compilation tasks for cross platfrom!
221
- define_compile_tasks(cross_platform)
247
+ define_compile_tasks(for_platform)
222
248
 
223
- # chain rbconfig.rb to Makefile generation
224
- file "#{tmp_path}/Makefile" => ["#{tmp_path}/rbconfig.rb"]
249
+ # chain fake.rb and rbconfig.rb to Makefile generation
250
+ file "#{tmp_path}/Makefile" => ["#{tmp_path}/fake.rb", "#{tmp_path}/rbconfig.rb"]
225
251
 
226
252
  # copy the file from the cross-ruby location
227
253
  file "#{tmp_path}/rbconfig.rb" => [rbconfig_file] do |t|
228
254
  cp t.prerequisites.first, t.name
229
255
  end
230
256
 
257
+ # genearte fake.rb for different ruby versions
258
+ file "#{tmp_path}/fake.rb" do |t|
259
+ File.open(t.name, 'w') do |f|
260
+ f.write fake_rb(ruby_ver)
261
+ end
262
+ end
263
+
231
264
  # now define native tasks for cross compiled files
232
- define_native_tasks(cross_platform) if @gem_spec && @gem_spec.platform == 'ruby'
265
+ define_native_tasks(for_platform) if @gem_spec && @gem_spec.platform == 'ruby'
233
266
 
234
267
  # create cross task
235
268
  task 'cross' do
236
269
  # clear compile dependencies
237
- Rake::Task['compile'].prerequisites.clear
270
+ Rake::Task['compile'].prerequisites.reject! { |t| !compiles_cross_platform.include?(t) }
238
271
 
239
272
  # chain the cross platform ones
240
- task 'compile' => ["compile:#{cross_platform}"]
273
+ task 'compile' => ["compile:#{for_platform}"]
241
274
 
242
275
  # clear lib/binary dependencies and trigger cross platform ones
243
- Rake::Task["#{@lib_dir}/#{binary}"].prerequisites.clear
244
- file "#{@lib_dir}/#{binary}" => ["copy:#{@name}:#{cross_platform}"]
276
+ # check if lib/binary is defined (damn bundle versus so versus dll)
277
+ if Rake::Task.task_defined?("#{@lib_dir}/#{binary(for_platform)}") then
278
+ Rake::Task["#{@lib_dir}/#{binary(for_platform)}"].prerequisites.clear
279
+ end
280
+
281
+ # FIXME: targeting multiple platforms copies the file twice
282
+ file "#{@lib_dir}/#{binary(for_platform)}" => ["copy:#{@name}:#{for_platform}"]
245
283
 
246
284
  # if everything for native task is in place
247
285
  if @gem_spec && @gem_spec.platform == 'ruby' then
248
- Rake::Task['native'].prerequisites.clear
249
- task 'native' => ["native:#{cross_platform}"]
286
+ # double check: only cross platform native tasks should be here
287
+ # FIXME: Sooo brittle
288
+ Rake::Task['native'].prerequisites.reject! { |t| !natives_cross_platform.include?(t) }
289
+ task 'native' => ["native:#{for_platform}"]
250
290
  end
251
291
  end
252
292
  end
253
293
 
254
294
  def extconf
255
- "#{@ext_dir}/#{@name}/#{@config_script}"
295
+ "#{@ext_dir}/#{@config_script}"
256
296
  end
257
297
 
258
298
  def make
259
299
  RUBY_PLATFORM =~ /mswin/ ? 'nmake' : 'make'
260
300
  end
261
301
 
262
- def binary
263
- "#{@name}.#{RbConfig::CONFIG['DLEXT']}"
302
+ def binary(platform = nil)
303
+ ext = case platform
304
+ when /darwin/
305
+ 'bundle'
306
+ when /mingw|mswin|linux/
307
+ 'so'
308
+ else
309
+ RbConfig::CONFIG['DLEXT']
310
+ end
311
+ "#{@name}.#{ext}"
264
312
  end
265
313
 
266
314
  def source_files
267
- @source_files ||= FileList["#{@ext_dir}/#{@name}/#{@source_pattern}"]
315
+ @source_files ||= FileList["#{@ext_dir}/#{@source_pattern}"]
316
+ end
317
+
318
+ def compiles_cross_platform
319
+ [*@cross_platform].map { |p| "compile:#{p}" }
320
+ end
321
+
322
+ def natives_cross_platform
323
+ [*@cross_platform].map { |p| "native:#{p}" }
324
+ end
325
+
326
+ def fake_rb(version)
327
+ <<-FAKE_RB
328
+ class Object
329
+ remove_const :RUBY_PLATFORM
330
+ remove_const :RUBY_VERSION
331
+ RUBY_PLATFORM = "i386-mingw32"
332
+ RUBY_VERSION = "#{version}"
333
+ end
334
+ FAKE_RB
268
335
  end
269
336
  end
270
337
  end
@@ -4,8 +4,8 @@ require 'rake/extensiontask'
4
4
  require 'rbconfig'
5
5
 
6
6
  describe Rake::ExtensionTask do
7
- describe '#new' do
8
- describe '(basic)' do
7
+ context '#new' do
8
+ context '(basic)' do
9
9
  it 'should raise an error if no name is provided' do
10
10
  lambda {
11
11
  Rake::ExtensionTask.new
@@ -55,7 +55,7 @@ describe Rake::ExtensionTask do
55
55
  end
56
56
  end
57
57
 
58
- describe '(defaults)' do
58
+ context '(defaults)' do
59
59
  before :each do
60
60
  @ext = Rake::ExtensionTask.new('extension_one')
61
61
  end
@@ -68,10 +68,6 @@ describe Rake::ExtensionTask do
68
68
  @ext.tmp_dir.should == 'tmp'
69
69
  end
70
70
 
71
- it 'should look for extension inside ext/' do
72
- @ext.ext_dir.should == 'ext'
73
- end
74
-
75
71
  it 'should copy build extension into lib/' do
76
72
  @ext.lib_dir.should == 'lib'
77
73
  end
@@ -101,14 +97,14 @@ describe Rake::ExtensionTask do
101
97
  end
102
98
  end
103
99
 
104
- describe '(tasks)' do
100
+ context '(tasks)' do
105
101
  before :each do
106
102
  Rake.application.clear
107
103
  CLEAN.clear
108
104
  CLOBBER.clear
109
105
  end
110
106
 
111
- describe '(one extension)' do
107
+ context '(one extension)' do
112
108
  before :each do
113
109
  Rake::FileList.stub!(:[]).and_return(["ext/extension_one/source.c"])
114
110
  @ext = Rake::ExtensionTask.new('extension_one')
@@ -116,7 +112,7 @@ describe Rake::ExtensionTask do
116
112
  @platform = RUBY_PLATFORM
117
113
  end
118
114
 
119
- describe 'compile' do
115
+ context 'compile' do
120
116
  it 'should define as task' do
121
117
  Rake::Task.task_defined?('compile').should be_true
122
118
  end
@@ -126,7 +122,7 @@ describe Rake::ExtensionTask do
126
122
  end
127
123
  end
128
124
 
129
- describe 'compile:extension_one' do
125
+ context 'compile:extension_one' do
130
126
  it 'should define as task' do
131
127
  Rake::Task.task_defined?('compile:extension_one').should be_true
132
128
  end
@@ -136,7 +132,7 @@ describe Rake::ExtensionTask do
136
132
  end
137
133
  end
138
134
 
139
- describe 'lib/extension_one.{so,bundle}' do
135
+ context 'lib/extension_one.{so,bundle}' do
140
136
  it 'should define as task' do
141
137
  Rake::Task.task_defined?("lib/#{@ext_bin}").should be_true
142
138
  end
@@ -146,7 +142,7 @@ describe Rake::ExtensionTask do
146
142
  end
147
143
  end
148
144
 
149
- describe 'tmp/{platform}/extension_one/extension_one.{so,bundle}' do
145
+ context 'tmp/{platform}/extension_one/extension_one.{so,bundle}' do
150
146
  it 'should define as task' do
151
147
  Rake::Task.task_defined?("tmp/#{@platform}/extension_one/#{@ext_bin}").should be_true
152
148
  end
@@ -164,7 +160,7 @@ describe Rake::ExtensionTask do
164
160
  end
165
161
  end
166
162
 
167
- describe 'tmp/{platform}/extension_one/Makefile' do
163
+ context 'tmp/{platform}/extension_one/Makefile' do
168
164
  it 'should define as task' do
169
165
  Rake::Task.task_defined?("tmp/#{@platform}/extension_one/Makefile").should be_true
170
166
  end
@@ -178,13 +174,13 @@ describe Rake::ExtensionTask do
178
174
  end
179
175
  end
180
176
 
181
- describe 'clean' do
177
+ context 'clean' do
182
178
  it "should include 'tmp/{platform}/extension_one' in the pattern" do
183
179
  CLEAN.should include("tmp/#{@platform}/extension_one")
184
180
  end
185
181
  end
186
182
 
187
- describe 'clobber' do
183
+ context 'clobber' do
188
184
  it "should include 'lib/extension_one.{so,bundle}'" do
189
185
  CLOBBER.should include("lib/#{@ext_bin}")
190
186
  end
@@ -195,7 +191,24 @@ describe Rake::ExtensionTask do
195
191
  end
196
192
  end
197
193
 
198
- describe '(native tasks)' do
194
+ context '(extension in custom location)' do
195
+ before :each do
196
+ Rake::FileList.stub!(:[]).and_return(["ext/extension_one/source.c"])
197
+ @ext = Rake::ExtensionTask.new('extension_one') do |ext|
198
+ ext.ext_dir = 'custom/ext/foo'
199
+ end
200
+ @ext_bin = ext_bin('extension_one')
201
+ @platform = RUBY_PLATFORM
202
+ end
203
+
204
+ context 'tmp/{platform}/extension_one/Makefile' do
205
+ it "should depend on 'custom/ext/foo/extconf.rb'" do
206
+ Rake::Task["tmp/#{@platform}/extension_one/Makefile"].prerequisites.should include("custom/ext/foo/extconf.rb")
207
+ end
208
+ end
209
+ end
210
+
211
+ context '(native tasks)' do
199
212
  before :each do
200
213
  Rake::FileList.stub!(:[]).and_return(["ext/extension_one/source.c"])
201
214
  @spec = mock_gem_spec
@@ -203,7 +216,7 @@ describe Rake::ExtensionTask do
203
216
  @platform = RUBY_PLATFORM
204
217
  end
205
218
 
206
- describe 'native' do
219
+ context 'native' do
207
220
  before :each do
208
221
  @spec.stub!(:platform=).and_return('ruby')
209
222
  end
@@ -230,7 +243,7 @@ describe Rake::ExtensionTask do
230
243
  Rake::Task["native"].prerequisites.should include("native:#{@platform}")
231
244
  end
232
245
 
233
- describe 'native:my_gem:{platform}' do
246
+ context 'native:my_gem:{platform}' do
234
247
  it 'should depend on binary extension' do
235
248
  Rake::ExtensionTask.new('extension_one', @spec)
236
249
  Rake::Task["native:my_gem:#{@platform}"].prerequisites.should include("tmp/#{@platform}/extension_one/#{@ext_bin}")
@@ -239,24 +252,29 @@ describe Rake::ExtensionTask do
239
252
  end
240
253
  end
241
254
 
242
- describe '(cross platform tasks)' do
255
+ context '(cross platform tasks)' do
243
256
  before :each do
244
257
  File.stub!(:exist?).and_return(true)
245
258
  YAML.stub!(:load_file).and_return(mock_config_yml)
246
259
  Rake::FileList.stub!(:[]).and_return(["ext/extension_one/source.c"])
247
260
  @spec = mock_gem_spec
248
261
  @config_file = File.expand_path("~/.rake-compiler/config.yml")
249
- @major_ver = RUBY_VERSION.match(/(\d+.\d+)/)[1]
250
- @config_path = mock_config_yml["rbconfig-#{@major_ver}"]
262
+ @ruby_ver = RUBY_VERSION
263
+ @config_path = mock_config_yml["rbconfig-#{@ruby_ver}"]
264
+
265
+ File.stub!(:open).and_yield(mock_fake_rb)
251
266
  end
252
267
 
253
- it 'should not generate an error if no rake-compiler configuration exist' do
268
+ it 'should warn if no rake-compiler configuration exist' do
254
269
  File.should_receive(:exist?).with(@config_file).and_return(false)
255
- lambda {
270
+
271
+ out, err = capture_output do
256
272
  Rake::ExtensionTask.new('extension_one') do |ext|
257
273
  ext.cross_compile = true
258
274
  end
259
- }.should_not raise_error(RuntimeError)
275
+ end
276
+
277
+ err.should match(/rake-compiler must be configured first to enable cross-compilation/)
260
278
  end
261
279
 
262
280
  it 'should parse the config file using YAML' do
@@ -266,32 +284,34 @@ describe Rake::ExtensionTask do
266
284
  end
267
285
  end
268
286
 
269
- it 'should fail if no section of config file defines running version of ruby' do
287
+ it 'should warn if no section of config file defines running version of ruby' do
270
288
  config = mock(Hash)
271
- config.should_receive(:[]).with("rbconfig-#{@major_ver}").and_return(nil)
289
+ config.should_receive(:[]).with("rbconfig-#{@ruby_ver}").and_return(nil)
272
290
  YAML.stub!(:load_file).and_return(config)
273
- lambda {
291
+ out, err = capture_output do
274
292
  Rake::ExtensionTask.new('extension_one') do |ext|
275
293
  ext.cross_compile = true
276
294
  end
277
- }.should raise_error(RuntimeError, /no configuration section for this version of Ruby/)
295
+ end
296
+ err.should match(/no configuration section for specified version of Ruby/)
278
297
  end
279
298
 
280
299
  it 'should allow usage of RUBY_CC_VERSION to indicate a different version of ruby' do
281
300
  config = mock(Hash)
282
- config.should_receive(:[]).with("rbconfig-2.0").and_return('/path/to/ruby/2.0/rbconfig.rb')
301
+ config.should_receive(:[]).with("rbconfig-1.9.1").and_return('/path/to/ruby/1.9.1/rbconfig.rb')
283
302
  YAML.stub!(:load_file).and_return(config)
284
- begin
285
- ENV['RUBY_CC_VERSION'] = '2.0'
286
- Rake::ExtensionTask.new('extension_one') do |ext|
287
- ext.cross_compile = true
288
- end
289
- ensure
290
- ENV.delete('RUBY_CC_VERSION')
303
+
304
+ ENV['RUBY_CC_VERSION'] = '1.9.1'
305
+ Rake::ExtensionTask.new('extension_one') do |ext|
306
+ ext.cross_compile = true
291
307
  end
292
308
  end
293
309
 
294
- describe "(cross for 'universal-unknown' platform)" do
310
+ after :each do
311
+ ENV.delete('RUBY_CC_VERSION')
312
+ end
313
+
314
+ context "(cross for 'universal-unknown' platform)" do
295
315
  before :each do
296
316
  @ext = Rake::ExtensionTask.new('extension_one', @spec) do |ext|
297
317
  ext.cross_compile = true
@@ -299,7 +319,13 @@ describe Rake::ExtensionTask do
299
319
  end
300
320
  end
301
321
 
302
- describe 'rbconfig' do
322
+ context 'fake' do
323
+ it 'should chain fake task to Makefile generation' do
324
+ Rake::Task['tmp/universal-unknown/extension_one/Makefile'].prerequisites.should include('tmp/universal-unknown/extension_one/fake.rb')
325
+ end
326
+ end
327
+
328
+ context 'rbconfig' do
303
329
  it 'should chain rbconfig tasks to Makefile generation' do
304
330
  Rake::Task['tmp/universal-unknown/extension_one/Makefile'].prerequisites.should include('tmp/universal-unknown/extension_one/rbconfig.rb')
305
331
  end
@@ -309,7 +335,7 @@ describe Rake::ExtensionTask do
309
335
  end
310
336
  end
311
337
 
312
- describe 'compile:universal-unknown' do
338
+ context 'compile:universal-unknown' do
313
339
  it "should be defined" do
314
340
  Rake::Task.task_defined?('compile:universal-unknown').should be_true
315
341
  end
@@ -319,7 +345,7 @@ describe Rake::ExtensionTask do
319
345
  end
320
346
  end
321
347
 
322
- describe 'native:universal-unknown' do
348
+ context 'native:universal-unknown' do
323
349
  it "should be defined" do
324
350
  Rake::Task.task_defined?('native:universal-unknown').should be_true
325
351
  end
@@ -329,6 +355,18 @@ describe Rake::ExtensionTask do
329
355
  end
330
356
  end
331
357
  end
358
+
359
+ context '(cross for multiple platforms)' do
360
+ it 'should define task for each supplied platform' do
361
+ @ext = Rake::ExtensionTask.new('extension_one', @spec) do |ext|
362
+ ext.cross_compile = true
363
+ ext.cross_platform = ['universal-known', 'universal-unknown']
364
+ end
365
+
366
+ Rake::Task.should have_defined('compile:universal-known')
367
+ Rake::Task.should have_defined('compile:universal-unknown')
368
+ end
369
+ end
332
370
  end
333
371
  end
334
372
 
@@ -345,8 +383,13 @@ describe Rake::ExtensionTask do
345
383
 
346
384
  def mock_config_yml
347
385
  {
348
- 'rbconfig-1.8' => '/some/path/version/1.8/to/rbconfig.rb',
349
- 'rbconfig-1.9' => '/some/path/version/1.9/to/rbconfig.rb'
386
+ 'rbconfig-1.8.6' => '/some/path/version/1.8/to/rbconfig.rb',
387
+ 'rbconfig-1.9.1' => '/some/path/version/1.9.1/to/rbconfig.rb',
388
+ 'rbconfig-3.0.0' => '/some/fake/version/3.0.0/to/rbconfig.rb'
350
389
  }
351
390
  end
391
+
392
+ def mock_fake_rb
393
+ mock(File, :write => 45)
394
+ end
352
395
  end
data/spec/spec_helper.rb CHANGED
@@ -5,5 +5,11 @@ $LOAD_PATH.unshift(libdir) unless $LOAD_PATH.include?(libdir)
5
5
  require 'rubygems'
6
6
  require 'spec'
7
7
 
8
+ # Console redirection helper
9
+ require File.expand_path(File.join(File.dirname(__FILE__), 'support/capture_output_helper'))
10
+
8
11
  Spec::Runner.configure do |config|
12
+ config.predicate_matchers[:have_defined] = :task_defined?
13
+
14
+ include CaptureOutputHelper
9
15
  end
@@ -0,0 +1,22 @@
1
+ module CaptureOutputHelper
2
+ def capture_output(&block)
3
+ old_stdout = $stdout
4
+ old_stderr = $stderr
5
+
6
+ stream_out = StringIO.new
7
+ stream_err = StringIO.new
8
+
9
+ begin
10
+ $stdout = stream_out
11
+ $stderr = stream_err
12
+ yield
13
+ ensure
14
+ $stdout = old_stdout
15
+ $stderr = old_stderr
16
+ end
17
+ stream_out.rewind
18
+ stream_err.rewind
19
+
20
+ [stream_out.read, stream_err.read]
21
+ end
22
+ end