Browse files

Generate dummy cross-compile target when no configuration exists.

This fixes issue #16.
  • Loading branch information...
1 parent fdb8f76 commit 8ae0a59ecca73994bc481ecbdb15a9e88b04c0a8 @mvz mvz committed Oct 30, 2011
Showing with 29 additions and 7 deletions.
  1. +10 −1 lib/rake/extensiontask.rb
  2. +19 −6 spec/lib/rake/extensiontask_spec.rb
View
11 lib/rake/extensiontask.rb
@@ -278,7 +278,7 @@ def define_cross_platform_tasks_with_version(for_platform, ruby_ver)
# warn the user about the need of configuration to use cross compilation.
unless File.exist?(config_path)
- warn "rake-compiler must be configured first to enable cross-compilation"
+ define_dummy_cross_platform_tasks
return
end
@@ -355,6 +355,15 @@ def define_cross_platform_tasks_with_version(for_platform, ruby_ver)
end
end
+ def define_dummy_cross_platform_tasks
+ task 'cross' do
+ Rake::Task['compile'].clear
+ task 'compile' do
+ raise "rake-compiler must be configured first to enable cross-compilation"
+ end
+ end
+ end
+
def extconf
"#{@ext_dir}/#{@config_script}"
end
View
25 spec/lib/rake/extensiontask_spec.rb
@@ -283,16 +283,29 @@
File.stub!(:open).and_yield(mock_fake_rb)
end
- it 'should warn if no rake-compiler configuration exist' do
- File.should_receive(:exist?).with(@config_file).and_return(false)
+ context 'if no rake-compiler configuration exists' do
+ before :each do
+ File.should_receive(:exist?).with(@config_file).and_return(false)
- out, err = capture_output do
- Rake::ExtensionTask.new('extension_one') do |ext|
- ext.cross_compile = true
+ _, @err = capture_output do
+ Rake::ExtensionTask.new('extension_one') do |ext|
+ ext.cross_compile = true
+ end
end
end
- err.should match(/rake-compiler must be configured first to enable cross-compilation/)
+ it 'should not generate a warning' do
+ @err.should eq("")
+ end
+
+ it 'should create a dummy nested cross-compile target that raises an error' do
+ Rake::Task.should have_defined("cross")
+ Rake::Task["cross"].invoke
+ lambda {
+ Rake::Task["compile"].invoke
+ }.should raise_error(RuntimeError,
+ /rake-compiler must be configured first to enable cross-compilation/)
+ end
end
it 'should parse the config file using YAML' do

0 comments on commit 8ae0a59

Please sign in to comment.