[rubygems/rubygems] Don't modify RbConfig at all when building extensions
Instead, pass sitearchdir and sitelibdir directly to `make`. This also removes the need to create and use the siteconf file at all when generating makefiles. https://github.com/rubygems/rubygems/commit/dea41fa2dc
This commit is contained in:
parent
1aaeff8e36
commit
8855b68f97
@ -17,7 +17,7 @@ class Gem::Ext::Builder
|
|||||||
$1.downcase
|
$1.downcase
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.make(dest_path, results, make_dir = Dir.pwd)
|
def self.make(dest_path, results, make_dir = Dir.pwd, sitedir = nil)
|
||||||
unless File.exist? File.join(make_dir, 'Makefile')
|
unless File.exist? File.join(make_dir, 'Makefile')
|
||||||
raise Gem::InstallError, 'Makefile not found'
|
raise Gem::InstallError, 'Makefile not found'
|
||||||
end
|
end
|
||||||
@ -33,11 +33,18 @@ class Gem::Ext::Builder
|
|||||||
# The installation of the bundled gems is failed when DESTDIR is empty in mswin platform.
|
# The installation of the bundled gems is failed when DESTDIR is empty in mswin platform.
|
||||||
destdir = (/\bnmake/i !~ make_program_name || ENV['DESTDIR'] && ENV['DESTDIR'] != "") ? 'DESTDIR=%s' % ENV['DESTDIR'] : ''
|
destdir = (/\bnmake/i !~ make_program_name || ENV['DESTDIR'] && ENV['DESTDIR'] != "") ? 'DESTDIR=%s' % ENV['DESTDIR'] : ''
|
||||||
|
|
||||||
|
env = [destdir]
|
||||||
|
|
||||||
|
if sitedir
|
||||||
|
env << 'sitearchdir=%s' % sitedir
|
||||||
|
env << 'sitelibdir=%s' % sitedir
|
||||||
|
end
|
||||||
|
|
||||||
['clean', '', 'install'].each do |target|
|
['clean', '', 'install'].each do |target|
|
||||||
# Pass DESTDIR via command line to override what's in MAKEFLAGS
|
# Pass DESTDIR via command line to override what's in MAKEFLAGS
|
||||||
cmd = [
|
cmd = [
|
||||||
*make_program,
|
*make_program,
|
||||||
destdir,
|
*env,
|
||||||
target,
|
target,
|
||||||
].reject(&:empty?)
|
].reject(&:empty?)
|
||||||
begin
|
begin
|
||||||
|
@ -23,26 +23,13 @@ class Gem::Ext::ExtConfBuilder < Gem::Ext::Builder
|
|||||||
# Details: https://github.com/rubygems/rubygems/issues/977#issuecomment-171544940
|
# Details: https://github.com/rubygems/rubygems/issues/977#issuecomment-171544940
|
||||||
tmp_dest_relative = get_relative_path(tmp_dest.clone, extension_dir)
|
tmp_dest_relative = get_relative_path(tmp_dest.clone, extension_dir)
|
||||||
|
|
||||||
Tempfile.open %w[siteconf .rb], extension_dir do |siteconf|
|
|
||||||
siteconf.puts "require 'rbconfig'"
|
|
||||||
siteconf.puts "dest_path = #{tmp_dest_relative.dump}"
|
|
||||||
%w[sitearchdir sitelibdir].each do |dir|
|
|
||||||
siteconf.puts "RbConfig::MAKEFILE_CONFIG['#{dir}'] = dest_path"
|
|
||||||
end
|
|
||||||
|
|
||||||
siteconf.close
|
|
||||||
|
|
||||||
destdir = ENV["DESTDIR"]
|
destdir = ENV["DESTDIR"]
|
||||||
|
|
||||||
begin
|
begin
|
||||||
# workaround for https://github.com/oracle/truffleruby/issues/2115
|
|
||||||
siteconf_path = RUBY_ENGINE == "truffleruby" ? siteconf.path.dup : siteconf.path
|
|
||||||
require "shellwords"
|
require "shellwords"
|
||||||
cmd = Gem.ruby.shellsplit << "-I" << File.expand_path('../..', __dir__) <<
|
cmd = Gem.ruby.shellsplit << "-I" << File.expand_path('../..', __dir__) << File.basename(extension)
|
||||||
"-r" << get_relative_path(siteconf_path, extension_dir) << File.basename(extension)
|
|
||||||
cmd.push(*args)
|
cmd.push(*args)
|
||||||
|
|
||||||
begin
|
|
||||||
run(cmd, results, class_name, extension_dir) do |s, r|
|
run(cmd, results, class_name, extension_dir) do |s, r|
|
||||||
mkmf_log = File.join(extension_dir, 'mkmf.log')
|
mkmf_log = File.join(extension_dir, 'mkmf.log')
|
||||||
if File.exist? mkmf_log
|
if File.exist? mkmf_log
|
||||||
@ -54,12 +41,10 @@ class Gem::Ext::ExtConfBuilder < Gem::Ext::Builder
|
|||||||
FileUtils.mv mkmf_log, dest_path
|
FileUtils.mv mkmf_log, dest_path
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
siteconf.unlink
|
|
||||||
end
|
|
||||||
|
|
||||||
ENV["DESTDIR"] = nil
|
ENV["DESTDIR"] = nil
|
||||||
|
|
||||||
make dest_path, results, extension_dir
|
make dest_path, results, extension_dir, tmp_dest_relative
|
||||||
|
|
||||||
full_tmp_dest = File.join(extension_dir, tmp_dest_relative)
|
full_tmp_dest = File.join(extension_dir, tmp_dest_relative)
|
||||||
|
|
||||||
@ -77,8 +62,6 @@ class Gem::Ext::ExtConfBuilder < Gem::Ext::Builder
|
|||||||
end
|
end
|
||||||
ensure
|
ensure
|
||||||
ENV["DESTDIR"] = destdir
|
ENV["DESTDIR"] = destdir
|
||||||
siteconf.close!
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
results
|
results
|
||||||
|
Loading…
x
Reference in New Issue
Block a user