diff options
author | Mike Dalessio <mike.dalessio@gmail.com> | 2022-12-15 21:01:04 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-12-16 06:01:04 +0900 |
commit | 66740bbe2e7867bbcb2f4e73b5e85277c4a21f9f (patch) | |
tree | 91158b44f7237275d93d540b8853faa678d8b0ad /lib/rake | |
parent | 8c907ac32f87bf16da6e84105fb4d6bf257e6bbd (diff) | |
download | rake-compiler-66740bbe2e7867bbcb2f4e73b5e85277c4a21f9f.tar.gz |
Add support for RubyGems 3.3.21 or later (#209)
Since Rubygems 3.3.21, the Gem::Platform name always contains the
library version for gnu platforms. So where the rake-compiler config
entries previously were:
```yaml
---
rbconfig-x86_64-linux-gnu-2.7.0: "/usr/local/rake-compiler/ruby/x86_64-redhat-linux/ruby-2.7.0/lib/ruby/2.7.0/x86_64-linux-gnu/rbconfig.rb"
rbconfig-x86_64-linux-2.7.0: "/usr/local/rake-compiler/ruby/x86_64-redhat-linux/ruby-2.7.0/lib/ruby/2.7.0/x86_64-linux-gnu/rbconfig.rb"
```
with later versions of rubygems, it is only
```yaml
---
rbconfig-x86_64-linux-gnu-2.7.0: "/usr/local/rake-compiler/ruby/x86_64-redhat-linux/ruby-2.7.0/lib/ruby/2.7.0/x86_64-linux-gnu/rbconfig.rb"
```
This means that the current way of finding a matching runtime, by doing
a string comparison on the config keys, is no longer appropriate. This
is causing failing builds downstream in `rake-compiler-dock`.
This PR:
- extracts a new CompilerConfig class to encapsulate the logic
- uses `Gem::Platform#=~` to tell if the gem platform matches the
runtime platform
Diffstat (limited to 'lib/rake')
-rw-r--r-- | lib/rake/baseextensiontask.rb | 2 | ||||
-rw-r--r-- | lib/rake/compiler_config.rb | 38 | ||||
-rw-r--r-- | lib/rake/extensiontask.rb | 12 |
3 files changed, 45 insertions, 7 deletions
diff --git a/lib/rake/baseextensiontask.rb b/lib/rake/baseextensiontask.rb index cf32147..063a555 100644 --- a/lib/rake/baseextensiontask.rb +++ b/lib/rake/baseextensiontask.rb @@ -5,6 +5,8 @@ require 'rbconfig' require 'pathname' +require_relative "compiler_config" + module Rake class BaseExtensionTask < TaskLib diff --git a/lib/rake/compiler_config.rb b/lib/rake/compiler_config.rb new file mode 100644 index 0000000..e9832dc --- /dev/null +++ b/lib/rake/compiler_config.rb @@ -0,0 +1,38 @@ +module Rake + class CompilerConfig + def initialize(config_path) + require "yaml" + @config = YAML.load_file(config_path) + end + + def find(ruby_version, gem_platform) + gem_platform = Gem::Platform.new(gem_platform) + + @config.each do |config_name, config_location| + # There are two variations we might find in the rake-compiler config.yml + # + # 1. config_name: rbconfig-x86_64-linux-3.0.0 + # runtime_platform_name: x86_64-linux + # runtime_version: 3.0.0 + # + # 2. config_name: rbconfig-x86_64-linux-gnu-3.0.0 + # runtime_platform_name: x86_64-linux-gnu + # runtime_version: 3.0.0 + # + # With rubygems < 3.3.21, both variations will be present (two entries pointing at the same + # installation). + # + # With rubygems >= 3.3.21, only the second variation will be present. + runtime_platform_name = config_name.split("-")[1..-2].join("-") + runtime_version = config_name.split("-").last + runtime_platform = Gem::Platform.new(runtime_platform_name) + + if (ruby_version == runtime_version) && (gem_platform =~ runtime_platform) + return config_location + end + end + + nil + end + end +end diff --git a/lib/rake/extensiontask.rb b/lib/rake/extensiontask.rb index 7c69741..0f48520 100644 --- a/lib/rake/extensiontask.rb +++ b/lib/rake/extensiontask.rb @@ -393,8 +393,11 @@ Java extension should be preferred. return end - require "yaml" - config_file = YAML.load_file(config_path) + rbconfig_file = Rake::CompilerConfig.new(config_path).find(ruby_ver, for_platform) + unless rbconfig_file + warn "no configuration section for specified version of Ruby (rbconfig-#{for_platform}-#{ruby_ver})" + return + end # tmp_path tmp_path = "#{@tmp_dir}/#{for_platform}/#{@name}/#{ruby_ver}" @@ -405,11 +408,6 @@ Java extension should be preferred. # lib_binary_path lib_binary_path = "#{lib_path}/#{File.basename(binary(for_platform))}" - unless rbconfig_file = config_file["rbconfig-#{for_platform}-#{ruby_ver}"] then - warn "no configuration section for specified version of Ruby (rbconfig-#{for_platform}-#{ruby_ver})" - return - end - # mkmf mkmf_file = File.expand_path(File.join(File.dirname(rbconfig_file), '..', 'mkmf.rb')) |