[rubygems/rubygems] Cleanup intermediate artifacts after installing built extensions

https://github.com/rubygems/rubygems/commit/98b6a959bd
This commit is contained in:
Eloy Espinaco 2022-11-29 23:40:02 -03:00 коммит произвёл Hiroshi SHIBATA
Родитель 9d10b8393e
Коммит 0a9544ce4a
3 изменённых файлов: 39 добавлений и 2 удалений

Просмотреть файл

@ -17,7 +17,7 @@ class Gem::Ext::Builder
$1.downcase
end
def self.make(dest_path, results, make_dir = Dir.pwd, sitedir = nil)
def self.make(dest_path, results, make_dir = Dir.pwd, sitedir = nil, targets = ["clean", "", "install"])
unless File.exist? File.join(make_dir, "Makefile")
raise Gem::InstallError, "Makefile not found"
end
@ -40,7 +40,7 @@ class Gem::Ext::Builder
env << "sitelibdir=%s" % sitedir
end
["clean", "", "install"].each do |target|
targets.each do |target|
# Pass DESTDIR via command line to override what's in MAKEFLAGS
cmd = [
*make_program,

Просмотреть файл

@ -55,6 +55,8 @@ class Gem::Ext::ExtConfBuilder < Gem::Ext::Builder
destent = ent.class.new(dest_path, ent.rel)
destent.exist? || FileUtils.mv(ent.path, destent.path)
end
make dest_path, results, extension_dir, tmp_dest_relative, ["clean"]
ensure
ENV["DESTDIR"] = destdir
end

Просмотреть файл

@ -1584,6 +1584,41 @@ gem 'other', version
end
end
def test_install_extension_clean_intermediate_files
pend "extensions don't quite work on jruby" if Gem.java_platform?
@spec = setup_base_spec
@spec.require_paths = ["."]
@spec.extensions << "extconf.rb"
File.write File.join(@tempdir, "extconf.rb"), <<-RUBY
require "mkmf"
CONFIG['CC'] = '$(TOUCH) $@ ||'
CONFIG['LDSHARED'] = '$(TOUCH) $@ ||'
$ruby = '#{Gem.ruby}'
create_makefile("#{@spec.name}")
RUBY
# empty depend file for no auto dependencies
@spec.files += %W[depend #{@spec.name}.c].each do |file|
write_file File.join(@tempdir, file)
end
shared_object = "#{@spec.name}.#{RbConfig::CONFIG["DLEXT"]}"
extension_file = File.join @spec.extension_dir, shared_object
intermediate_file = File.join @spec.gem_dir, shared_object
assert_path_not_exist extension_file, "no before installing"
use_ui @ui do
path = Gem::Package.build @spec
installer = Gem::Installer.at path
installer.install
end
assert_path_exist extension_file, "installed"
assert_path_not_exist intermediate_file
end
def test_installation_satisfies_dependency_eh
installer = setup_base_installer