summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/rake/baseextensiontask.rb2
-rw-r--r--lib/rake/compiler_config.rb38
-rw-r--r--lib/rake/extensiontask.rb12
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'))