Skip to content

Commit

Permalink
package: native win gem correctly specifies required ruby version
Browse files Browse the repository at this point in the history
  • Loading branch information
flavorjones committed Jan 5, 2022
1 parent a76963c commit 56b89d9
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 4 deletions.
9 changes: 9 additions & 0 deletions rakelib/extensions.rake
Expand Up @@ -405,6 +405,15 @@ else
spec.files.reject! { |path| File.fnmatch?("gumbo-parser/**/*", path) }
spec.dependencies.reject! { |dep| dep.name == "mini_portile2" }

# I would like rake-compiler to do this, but can't quite figure it out right now
supported_rubies = CROSS_RUBIES.select { |c| spec.platform =~ c.platform }
.map { |c| Gem::Version.new(c.ver) }
.sort
spec.required_ruby_version = [
">= #{supported_rubies.first.to_s.split(".").take(2).join(".")}",
"< #{supported_rubies.last.to_s.split(".").take(2).join(".").succ}.dev",
]

# when pre-compiling a native gem, package all the C headers sitting in ext/nokogiri/include
# which were copied there in the $INSTALLFILES section of extconf.rb.
# (see scripts/test-gem-file-contents and scripts/test-gem-installation for tests)
Expand Down
34 changes: 30 additions & 4 deletions scripts/test-gem-file-contents
Expand Up @@ -68,15 +68,21 @@ puts "Testing '#{gemfile}' (#{gemspec.platform})"
describe File.basename(gemfile) do
let(:cross_rubies_path) { File.join(File.dirname(__FILE__), "..", ".cross_rubies") }

# Ruby versions that should be supported by the native gem depending on the platform
let(:native_ruby_versions) do
let(:platform_supported_ruby_versions) do
File.read(cross_rubies_path).split("\n").map do |line|
ver, plat = line.split(":")
next if plat != gemspec.platform.to_s
ver.split(".").take(2).join(".") # ugh
end.compact.uniq.sort
end

let(:all_supported_ruby_versions) do
File.read(cross_rubies_path).split("\n").map do |line|
ver, _ = line.split(":")
ver.split(".").take(2).join(".") # ugh
end.uniq.sort
end

describe "setup" do
it "gemfile contains some files" do
actual = gemfile_contents.length
Expand Down Expand Up @@ -179,7 +185,7 @@ describe File.basename(gemfile) do
end

it "contains expected shared library files " do
native_ruby_versions.each do |version|
platform_supported_ruby_versions.each do |version|
actual = gemfile_contents.find do |p|
File.fnmatch?("lib/nokogiri/#{version}/nokogiri.{so,bundle}", p, File::FNM_EXTGLOB)
end
Expand All @@ -194,7 +200,27 @@ describe File.basename(gemfile) do
actual = gemfile_contents.find_all do |p|
File.fnmatch?("lib/nokogiri/**/*.{so,bundle}", p, File::FNM_EXTGLOB)
end
assert_equal(native_ruby_versions.length, actual.length, "did not expect extra shared library files")
assert_equal(
platform_supported_ruby_versions.length,
actual.length,
"did not expect extra shared library files",
)
end

it "sets required_ruby_version appropriately" do
unsupported_versions = all_supported_ruby_versions - platform_supported_ruby_versions
platform_supported_ruby_versions.each do |v|
assert(
gemspec.required_ruby_version.satisfied_by?(Gem::Version.new(v)),
"required_ruby_version='#{gemspec.required_ruby_version}' should support ruby #{v}",
)
end
unsupported_versions.each do |v|
refute(
gemspec.required_ruby_version.satisfied_by?(Gem::Version.new(v)),
"required_ruby_version='#{gemspec.required_ruby_version}' should not support ruby #{v}",
)
end
end
end if gemspec.platform.is_a?(Gem::Platform) && gemspec.platform.cpu

Expand Down

0 comments on commit 56b89d9

Please sign in to comment.