ruby-changes:72213
From: David <ko1@a...>
Date: Fri, 17 Jun 2022 17:05:41 +0900 (JST)
Subject: [ruby-changes:72213] 8855b68f97 (master): [rubygems/rubygems] Don't modify RbConfig at all when building extensions
https://git.ruby-lang.org/ruby.git/commit/?id=8855b68f97 From 8855b68f970b34be4b39006b404391d06163573a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rodr=C3=ADguez?= <deivid.rodriguez@r...> Date: Tue, 14 Jun 2022 15:26:37 +0200 Subject: [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 --- lib/rubygems/ext/builder.rb | 11 ++++- lib/rubygems/ext/ext_conf_builder.rb | 79 ++++++++++++++---------------------- 2 files changed, 40 insertions(+), 50 deletions(-) diff --git a/lib/rubygems/ext/builder.rb b/lib/rubygems/ext/builder.rb index a5b3363c21..c98ff643fc 100644 --- a/lib/rubygems/ext/builder.rb +++ b/lib/rubygems/ext/builder.rb @@ -17,7 +17,7 @@ class Gem::Ext::Builder https://github.com/ruby/ruby/blob/trunk/lib/rubygems/ext/builder.rb#L17 $1.downcase 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') raise Gem::InstallError, 'Makefile not found' end @@ -33,11 +33,18 @@ class Gem::Ext::Builder https://github.com/ruby/ruby/blob/trunk/lib/rubygems/ext/builder.rb#L33 # 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'] : '' + env = [destdir] + + if sitedir + env << 'sitearchdir=%s' % sitedir + env << 'sitelibdir=%s' % sitedir + end + ['clean', '', 'install'].each do |target| # Pass DESTDIR via command line to override what's in MAKEFLAGS cmd = [ *make_program, - destdir, + *env, target, ].reject(&:empty?) begin diff --git a/lib/rubygems/ext/ext_conf_builder.rb b/lib/rubygems/ext/ext_conf_builder.rb index 3fd7559234..52972b901b 100644 --- a/lib/rubygems/ext/ext_conf_builder.rb +++ b/lib/rubygems/ext/ext_conf_builder.rb @@ -23,62 +23,45 @@ class Gem::Ext::ExtConfBuilder < Gem::Ext::Builder https://github.com/ruby/ruby/blob/trunk/lib/rubygems/ext/ext_conf_builder.rb#L23 # Details: https://github.com/rubygems/rubygems/issues/977#issuecomment-171544940 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"] - - begin - # workaround for https://github.com/oracle/truffleruby/issues/2115 - siteconf_path = RUBY_ENGINE == "truffleruby" ? siteconf.path.dup : siteconf.path - require "shellwords" - cmd = Gem.ruby.shellsplit << "-I" << File.expand_path('../..', __dir__) << - "-r" << get_relative_path(siteconf_path, extension_dir) << File.basename(extension) - cmd.push(*args) - - begin - run(cmd, results, class_name, extension_dir) do |s, r| - mkmf_log = File.join(extension_dir, 'mkmf.log') - if File.exist? mkmf_log - unless s.success? - r << "To see why this extension failed to compile, please check" \ - " the mkmf.log which can be found here:\n" - r << " " + File.join(dest_path, 'mkmf.log') + "\n" - end - FileUtils.mv mkmf_log, dest_path - end + destdir = ENV["DESTDIR"] + + begin + require "shellwords" + cmd = Gem.ruby.shellsplit << "-I" << File.expand_path('../..', __dir__) << File.basename(extension) + cmd.push(*args) + + run(cmd, results, class_name, extension_dir) do |s, r| + mkmf_log = File.join(extension_dir, 'mkmf.log') + if File.exist? mkmf_log + unless s.success? + r << "To see why this extension failed to compile, please check" \ + " the mkmf.log which can be found here:\n" + r << " " + File.join(dest_path, 'mkmf.log') + "\n" end - siteconf.unlink + FileUtils.mv mkmf_log, dest_path end + 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) - # TODO remove in RubyGems 3 - if Gem.install_extension_in_lib and lib_dir - FileUtils.mkdir_p lib_dir - entries = Dir.entries(full_tmp_dest) - %w[. ..] - entries = entries.map {|entry| File.join full_tmp_dest, entry } - FileUtils.cp_r entries, lib_dir, :remove_destination => true - end + # TODO remove in RubyGems 3 + if Gem.install_extension_in_lib and lib_dir + FileUtils.mkdir_p lib_dir + entries = Dir.entries(full_tmp_dest) - %w[. ..] + entries = entries.map {|entry| File.join full_tmp_dest, entry } + FileUtils.cp_r entries, lib_dir, :remove_destination => true + end - FileUtils::Entry_.new(full_tmp_dest).traverse do |ent| - destent = ent.class.new(dest_path, ent.rel) - destent.exist? or FileUtils.mv(ent.path, destent.path) - end - ensure - ENV["DESTDIR"] = destdir - siteconf.close! + FileUtils::Entry_.new(full_tmp_dest).traverse do |ent| + destent = ent.class.new(dest_path, ent.rel) + destent.exist? or FileUtils.mv(ent.path, destent.path) end + ensure + ENV["DESTDIR"] = destdir end results -- cgit v1.2.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/