Skip to content

Commit

Permalink
Allow X.Y.Z version of Ruby be specified.
Browse files Browse the repository at this point in the history
This is part of the work required for getting you
compile a extension from one version of ruby targetting another.
  • Loading branch information
luislavena committed Mar 21, 2009
1 parent a293a28 commit 486434e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
6 changes: 3 additions & 3 deletions lib/rake/extensiontask.rb
Expand Up @@ -202,7 +202,7 @@ def define_native_tasks(for_platform = nil)

def define_cross_platform_tasks
config_path = File.expand_path("~/.rake-compiler/config.yml")
major_ver = (ENV['RUBY_CC_VERSION'] || RUBY_VERSION).match(/(\d+.\d+)/)[1]
ruby_ver = ENV['RUBY_CC_VERSION'] || RUBY_VERSION

# warn the user about the need of configuration to use cross compilation.
unless File.exist?(config_path)
Expand All @@ -215,8 +215,8 @@ def define_cross_platform_tasks
# tmp_path
tmp_path = "#{@tmp_dir}/#{cross_platform}/#{@name}"

unless rbconfig_file = config_file["rbconfig-#{major_ver}"] then
fail "no configuration section for this version of Ruby (rbconfig-#{major_ver})"
unless rbconfig_file = config_file["rbconfig-#{ruby_ver}"] then
fail "no configuration section for specified version of Ruby (rbconfig-#{ruby_ver})"
end

# define compilation tasks for cross platfrom!
Expand Down
16 changes: 8 additions & 8 deletions spec/lib/rake/extensiontask_spec.rb
Expand Up @@ -259,8 +259,8 @@
Rake::FileList.stub!(:[]).and_return(["ext/extension_one/source.c"])
@spec = mock_gem_spec
@config_file = File.expand_path("~/.rake-compiler/config.yml")
@major_ver = RUBY_VERSION.match(/(\d+.\d+)/)[1]
@config_path = mock_config_yml["rbconfig-#{@major_ver}"]
@ruby_ver = RUBY_VERSION
@config_path = mock_config_yml["rbconfig-#{@ruby_ver}"]
end

it 'should not generate an error if no rake-compiler configuration exist' do
Expand All @@ -281,21 +281,21 @@

it 'should fail if no section of config file defines running version of ruby' do
config = mock(Hash)
config.should_receive(:[]).with("rbconfig-#{@major_ver}").and_return(nil)
config.should_receive(:[]).with("rbconfig-#{@ruby_ver}").and_return(nil)
YAML.stub!(:load_file).and_return(config)
lambda {
Rake::ExtensionTask.new('extension_one') do |ext|
ext.cross_compile = true
end
}.should raise_error(RuntimeError, /no configuration section for this version of Ruby/)
}.should raise_error(RuntimeError, /no configuration section for specified version of Ruby/)
end

it 'should allow usage of RUBY_CC_VERSION to indicate a different version of ruby' do
config = mock(Hash)
config.should_receive(:[]).with("rbconfig-2.0").and_return('/path/to/ruby/2.0/rbconfig.rb')
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'] = '2.0'
ENV['RUBY_CC_VERSION'] = '1.9.1'
Rake::ExtensionTask.new('extension_one') do |ext|
ext.cross_compile = true
end
Expand Down Expand Up @@ -358,8 +358,8 @@ def mock_gem_spec(stubs = {})

def mock_config_yml
{
'rbconfig-1.8' => '/some/path/version/1.8/to/rbconfig.rb',
'rbconfig-1.9' => '/some/path/version/1.9/to/rbconfig.rb'
'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'
}
end
end

0 comments on commit 486434e

Please sign in to comment.