Permalink
Browse files

Simplify

  • Loading branch information...
1 parent 092f3c5 commit 5854dfa95f68eaaf27edba7552d40d6825d1e50b @kou kou committed Dec 2, 2016
Showing with 49 additions and 10 deletions.
  1. +9 −10 lib/rake/extensiontask.rb
  2. +40 −0 spec/lib/rake/extensiontask_spec.rb
@@ -255,10 +255,13 @@ def define_native_tasks(for_platform = nil, ruby_ver = RUBY_VERSION, callback =
spec.platform = Gem::Platform.new(platf)
# set ruby version constraints
- cross_rubies = @ruby_versions_per_platform[platf] || []
+ ruby_versions = @ruby_versions_per_platform[platf] || []
+ sorted_ruby_versions = ruby_versions.sort_by do |ruby_version|
+ ruby_version.split(".").collect(&:to_i)
+ end
spec.required_ruby_version = [
- ">= #{version_ary2str( cross_rubies.min[0,2] )}",
- "< #{version_ary2str( cross_rubies.max[0,2].succ )}"
+ ">= #{ruby_api_version(sorted_ruby_versions.first)}",
+ "< #{ruby_api_version(sorted_ruby_versions.last).succ}"
]
# clear the extensions defined in the specs
@@ -356,7 +359,7 @@ def define_cross_platform_tasks(for_platform)
# Update cross compiled platform/version combinations
ruby_versions = (@ruby_versions_per_platform[for_platform] ||= [])
- ruby_versions << version_str2ary(version)
+ ruby_versions << version
define_cross_platform_tasks_with_version(for_platform, version)
@@ -509,12 +512,8 @@ def natives_cross_platform
[*@cross_platform].map { |p| "native:#{p}" }
end
- def version_str2ary(version_string)
- version_string[/\A[^-]+/].split(".").map(&:to_i).pack("C*")
- end
-
- def version_ary2str(version_ary)
- version_ary.unpack("C*").join(".")
+ def ruby_api_version(ruby_version)
+ ruby_version.split(".")[0, 2].join(".")
end
def fake_rb(platform, version)
@@ -454,6 +454,46 @@
end
end
+ it "should set required_ruby_version from RUBY_CC_VERSION" do
+ platforms = ["x86-mingw32", "x64-mingw32"]
+ ruby_cc_versions = ["1.8.6", "2.1.10", "2.2.6", "2.3.3", "2.10.1"]
+ ENV["RUBY_CC_VERSION"] = ruby_cc_versions.join(":")
+ config = mock(Hash)
+ ruby_cc_versions.each do |ruby_cc_version|
+ platforms.each do |platform|
+ config.stub!(:[]).
+ with("rbconfig-#{platform}-#{ruby_cc_version}").
+ and_return("/rubies/#{ruby_cc_version}/rbconfig.rb")
+ end
+ end
+ YAML.stub!(:load_file).and_return(config)
+
+ Gem.stub_chain(:configuration, :verbose=).and_return(true)
+
+ spec = Gem::Specification.new do |s|
+ s.name = 'my_gem'
+ s.platform = Gem::Platform::RUBY
+ end
+
+ cross_specs = []
+ Rake::ExtensionTask.new("extension_one", spec) do |ext|
+ ext.cross_platform = platforms
+ ext.cross_compile = true
+ ext.cross_compiling do |cross_spec|
+ cross_specs << cross_spec
+ end
+ end
+ platforms.each do |platform|
+ Rake::Task["native:my_gem:#{platform}"].execute
+ end
+
+ expected_required_ruby_versions = [
+ Gem::Requirement.new([">= 1.8", "< 2.11"]),
+ Gem::Requirement.new([">= 1.8", "< 2.11"]),
+ ]
+ cross_specs.collect(&:required_ruby_version).should == expected_required_ruby_versions
+ end
+
after :each do
ENV.delete('RUBY_CC_VERSION')
end

0 comments on commit 5854dfa

Please sign in to comment.