diff options
author | Luis Lavena <luislavena@gmail.com> | 2009-03-21 23:08:14 -0300 |
---|---|---|
committer | Luis Lavena <luislavena@gmail.com> | 2009-03-21 23:08:14 -0300 |
commit | 2a83029f54be9b8803658afb515b62bd6fa8b9e9 (patch) | |
tree | 018f56445f9717f54b2c77e41cd4e105406e6954 | |
parent | 18c73cc0e91ced20f7de453bf02eec6867376b62 (diff) | |
download | rake-compiler-2a83029f54be9b8803658afb515b62bd6fa8b9e9.tar.gz |
Implement Ruby version faker.
During cross compilation, rake-compiler will create a fake.rb
file to mimic a different version than the one used to execute
the build process.
Yet still, there are some changes between 1.9 and 1.8 not yet
ironed.
-rw-r--r-- | lib/rake/extensiontask.rb | 39 | ||||
-rw-r--r-- | spec/lib/rake/extensiontask_spec.rb | 30 |
2 files changed, 57 insertions, 12 deletions
diff --git a/lib/rake/extensiontask.rb b/lib/rake/extensiontask.rb index e81595a..522ad2f 100644 --- a/lib/rake/extensiontask.rb +++ b/lib/rake/extensiontask.rb @@ -102,17 +102,30 @@ module Rake file "#{tmp_path}/Makefile" => [tmp_path, extconf] do |t| options = @config_options.dup + # include current directory + cmd = ['-I.'] + + # if fake.rb is present, add to the command line + if t.prerequisites.include?("#{tmp_path}/fake.rb") then + cmd << '-rfake' + end + + # now add the extconf script + cmd << File.join(Dir.pwd, extconf) + # rbconfig.rb will be present if we are cross compiling if t.prerequisites.include?("#{tmp_path}/rbconfig.rb") then options.push(*@cross_config_options) end - parent = Dir.pwd + # add options to command + cmd.push(*options) + chdir tmp_path do # FIXME: Rake is broken for multiple arguments system() calls. # Add current directory to the search path of Ruby # Also, include additional parameters supplied. - ruby ['-I.', File.join(parent, extconf), *options].join(' ') + ruby cmd.join(' ') end end @@ -222,14 +235,21 @@ module Rake # define compilation tasks for cross platfrom! define_compile_tasks(cross_platform) - # chain rbconfig.rb to Makefile generation - file "#{tmp_path}/Makefile" => ["#{tmp_path}/rbconfig.rb"] + # chain fake.rb and rbconfig.rb to Makefile generation + file "#{tmp_path}/Makefile" => ["#{tmp_path}/fake.rb", "#{tmp_path}/rbconfig.rb"] # copy the file from the cross-ruby location file "#{tmp_path}/rbconfig.rb" => [rbconfig_file] do |t| cp t.prerequisites.first, t.name end + # genearte fake.rb for different ruby versions + file "#{tmp_path}/fake.rb" do |t| + File.open(t.name, 'w') do |f| + f.write fake_rb(ruby_ver) + end + end + # now define native tasks for cross compiled files define_native_tasks(cross_platform) if @gem_spec && @gem_spec.platform == 'ruby' @@ -279,5 +299,16 @@ module Rake def source_files @source_files ||= FileList["#{@ext_dir}/#{@source_pattern}"] end + + def fake_rb(version) + <<-FAKE_RB + class Object + remove_const :RUBY_PLATFORM + remove_const :RUBY_VERSION + RUBY_PLATFORM = "i386-mingw32" + RUBY_VERSION = "#{version}" + end +FAKE_RB + end end end diff --git a/spec/lib/rake/extensiontask_spec.rb b/spec/lib/rake/extensiontask_spec.rb index e0d7eae..eb385b6 100644 --- a/spec/lib/rake/extensiontask_spec.rb +++ b/spec/lib/rake/extensiontask_spec.rb @@ -261,6 +261,8 @@ describe Rake::ExtensionTask do @config_file = File.expand_path("~/.rake-compiler/config.yml") @ruby_ver = RUBY_VERSION @config_path = mock_config_yml["rbconfig-#{@ruby_ver}"] + + File.stub!(:open).and_yield(mock_fake_rb) end it 'should not generate an error if no rake-compiler configuration exist' do @@ -294,16 +296,17 @@ describe Rake::ExtensionTask do config = mock(Hash) config.should_receive(:[]).with("rbconfig-1.9.1").and_return('/path/to/ruby/1.9.1/rbconfig.rb') YAML.stub!(:load_file).and_return(config) - begin - ENV['RUBY_CC_VERSION'] = '1.9.1' - Rake::ExtensionTask.new('extension_one') do |ext| - ext.cross_compile = true - end - ensure - ENV.delete('RUBY_CC_VERSION') + + ENV['RUBY_CC_VERSION'] = '1.9.1' + Rake::ExtensionTask.new('extension_one') do |ext| + ext.cross_compile = true end end + after :each do + ENV.delete('RUBY_CC_VERSION') + end + describe "(cross for 'universal-unknown' platform)" do before :each do @ext = Rake::ExtensionTask.new('extension_one', @spec) do |ext| @@ -312,6 +315,12 @@ describe Rake::ExtensionTask do end end + describe 'fake' do + it 'should chain fake task to Makefile generation' do + Rake::Task['tmp/universal-unknown/extension_one/Makefile'].prerequisites.should include('tmp/universal-unknown/extension_one/fake.rb') + end + end + describe 'rbconfig' do it 'should chain rbconfig tasks to Makefile generation' do Rake::Task['tmp/universal-unknown/extension_one/Makefile'].prerequisites.should include('tmp/universal-unknown/extension_one/rbconfig.rb') @@ -359,7 +368,12 @@ describe Rake::ExtensionTask do def mock_config_yml { 'rbconfig-1.8.6' => '/some/path/version/1.8/to/rbconfig.rb', - 'rbconfig-1.9.1' => '/some/path/version/1.9.1/to/rbconfig.rb' + 'rbconfig-1.9.1' => '/some/path/version/1.9.1/to/rbconfig.rb', + 'rbconfig-3.0.0' => '/some/fake/version/3.0.0/to/rbconfig.rb' } end + + def mock_fake_rb + mock(File, :write => 45) + end end |