Skip to content

Commit

Permalink
Merge pull request #137 from larskanis/add-ruby-version-to-cross-gems
Browse files Browse the repository at this point in the history
Set Ruby version constraints in the gemspec of cross gems.

Patch by Lars Kanis. Thanks!!!
  • Loading branch information
kou committed Dec 2, 2016
2 parents 62448ba + 0dc2350 commit 263ae17
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions lib/rake/extensiontask.rb
Expand Up @@ -25,6 +25,7 @@ def init(name = nil, gem_spec = nil)
@cross_compiling = nil
@no_native = false
@config_includes = []
@ruby_versions_per_platform = Hash.new([])
end

def cross_platform
Expand Down Expand Up @@ -253,6 +254,13 @@ def define_native_tasks(for_platform = nil, ruby_ver = RUBY_VERSION, callback =
# 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

Expand Down Expand Up @@ -346,6 +354,9 @@ def define_cross_platform_tasks(for_platform)
@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
Expand Down Expand Up @@ -497,6 +508,14 @@ 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(".")
end

def fake_rb(platform, version)
<<-FAKE_RB
# Pre-load resolver library before faking, in order to avoid error
Expand Down

0 comments on commit 263ae17

Please sign in to comment.