From 56b89d952cd55daaa3564311e24bb8c9b82476c6 Mon Sep 17 00:00:00 2001 From: Mike Dalessio Date: Wed, 5 Jan 2022 15:27:34 -0500 Subject: [PATCH] package: native win gem correctly specifies required ruby version --- rakelib/extensions.rake | 9 +++++++++ scripts/test-gem-file-contents | 34 ++++++++++++++++++++++++++++++---- 2 files changed, 39 insertions(+), 4 deletions(-) diff --git a/rakelib/extensions.rake b/rakelib/extensions.rake index 9cbb2fa758..af3a2f6df1 100644 --- a/rakelib/extensions.rake +++ b/rakelib/extensions.rake @@ -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) diff --git a/scripts/test-gem-file-contents b/scripts/test-gem-file-contents index ce33c676f9..08a3c0905f 100755 --- a/scripts/test-gem-file-contents +++ b/scripts/test-gem-file-contents @@ -68,8 +68,7 @@ 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 @@ -77,6 +76,13 @@ describe File.basename(gemfile) do 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 @@ -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 @@ -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