diff options
author | Lars Kanis <lars@greiz-reinsdorf.de> | 2016-11-30 21:47:09 +0100 |
---|---|---|
committer | Lars Kanis <lars@greiz-reinsdorf.de> | 2016-11-30 21:47:09 +0100 |
commit | 0dc23504cb03ed2fb3c506e1bb58af48d3851d1e (patch) | |
tree | 05fd51245f4ac9860e1dbefaf33bb3a0ec4ddbe4 /lib/rake | |
parent | 62448baff5084feebbc8d60eccf77f13f16882d0 (diff) | |
download | rake-compiler-0dc23504cb03ed2fb3c506e1bb58af48d3851d1e.tar.gz |
Set Ruby version constraints in the gemspec of cross gems.
This way the gem, that is not built for the ruby version in use,
fails at install time rather than runtime.
Moreover a clear error message is given to the user or bundler can
select the source gem instead.
Diffstat (limited to 'lib/rake')
-rw-r--r-- | lib/rake/extensiontask.rb | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/lib/rake/extensiontask.rb b/lib/rake/extensiontask.rb index d5c6c85..9df8743 100644 --- a/lib/rake/extensiontask.rb +++ b/lib/rake/extensiontask.rb @@ -25,6 +25,7 @@ module Rake @cross_compiling = nil @no_native = false @config_includes = [] + @ruby_versions_per_platform = Hash.new([]) end def cross_platform @@ -253,6 +254,13 @@ Java extension should be preferred. # adjust to specified platform spec.platform = Gem::Platform.new(platf) + # set ruby version constraints + cross_rubies = @ruby_versions_per_platform[platf] + spec.required_ruby_version = [ + ">= #{version_ary2str( cross_rubies.min[0,2] )}", + "< #{version_ary2str( cross_rubies.max[0,2].succ )}" + ] + # clear the extensions defined in the specs spec.extensions.clear @@ -346,6 +354,9 @@ Java extension should be preferred. @lib_dir = "#{@lib_dir}/#{$1}" end + # Update cross compiled platform/version combinations + @ruby_versions_per_platform[for_platform] << version_str2ary(version) + define_cross_platform_tasks_with_version(for_platform, version) # restore lib_dir @@ -497,6 +508,14 @@ Java extension should be preferred. [*@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(".") + end + def fake_rb(platform, version) <<-FAKE_RB # Pre-load resolver library before faking, in order to avoid error |