[前][次][番号順一覧][スレッド一覧]

ruby-changes:65254

From: V=C3=ADt <ko1@a...>
Date: Sun, 14 Feb 2021 14:10:02 +0900 (JST)
Subject: [ruby-changes:65254] 763b8fed3d (master): Use UnpackedInstaller to install default gems.

https://git.ruby-lang.org/ruby.git/commit/?id=763b8fed3d

From 763b8fed3dee32ff3bd6c86260f7d4ce4cfaa508 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?V=C3=ADt=20Ondruch?= <vondruch@r...>
Date: Thu, 10 Oct 2019 12:32:59 +0200
Subject: Use UnpackedInstaller to install default gems.

Use UnpackedInstaller for installation of default gems similarly it is
already used to install bundled gems.

This allows to reuse RubyGems functionality instead of custom code full
of exceptions.
---
 tool/rbinstall.rb | 48 ++++++++++++++++++++++++++----------------------
 1 file changed, 26 insertions(+), 22 deletions(-)

diff --git a/tool/rbinstall.rb b/tool/rbinstall.rb
index 8790268..56502f1 100755
--- a/tool/rbinstall.rb
+++ b/tool/rbinstall.rb
@@ -700,7 +700,7 @@ module RbInstall https://github.com/ruby/ruby/blob/trunk/tool/rbinstall.rb#L700
           base = "#{prefix}#{relative_base}"
         when "lib"
           base = @base_dir
-          prefix = base.sub(/lib\/.*?\z/, "") + "lib/"
+          prefix = base.sub(/lib\/.*?\z/, "")
         else
           # other/something.gemspec ->
           #   [other/something.rb, other/something/foo.rb, ...]
@@ -763,7 +763,13 @@ module RbInstall https://github.com/ruby/ruby/blob/trunk/tool/rbinstall.rb#L763
       mode = pattern == File.join(spec.bindir, '*') ? prog_mode : data_mode
       destdir = without_destdir(destination_dir)
       spec.files.each do |f|
+        next unless File.fnmatch(pattern, f)
         src = File.join(@src_dir, f)
+        # The `src` is fine for bundled gems. However, default gems have their
+        # binaries in `libexec`.
+        unless File.exist?(src)
+          src = File.join(@src_dir, 'libexec', File.basename(f))
+        end
         dest = File.join(destdir, f)
         makedirs(dest[/.*(?=\/)/m])
         install src, dest, :mode => mode
@@ -871,10 +877,10 @@ end https://github.com/ruby/ruby/blob/trunk/tool/rbinstall.rb#L877
 # :startdoc:
 
 install?(:ext, :comm, :gem, :'default-gems', :'default-gems-comm') do
-  install_default_gem('lib', srcdir)
+  install_default_gem('lib', srcdir, bindir)
 end
 install?(:ext, :arch, :gem, :'default-gems', :'default-gems-arch') do
-  install_default_gem('ext', srcdir)
+  install_default_gem('ext', srcdir, bindir)
 end
 
 def load_gemspec(file, expanded = false)
@@ -902,12 +908,23 @@ def load_gemspec(file, expanded = false) https://github.com/ruby/ruby/blob/trunk/tool/rbinstall.rb#L908
   spec
 end
 
-def install_default_gem(dir, srcdir)
+def install_default_gem(dir, srcdir, bindir)
   gem_dir = Gem.default_dir
   install_dir = with_destdir(gem_dir)
   prepare "default gems from #{dir}", gem_dir
   makedirs(Gem.ensure_default_gem_subdirectories(install_dir, $dir_mode).map {|d| File.join(gem_dir, d)})
 
+  options = {
+    :install_dir => with_destdir(gem_dir),
+    :bin_dir => with_destdir(bindir),
+    :ignore_dependencies => true,
+    :dir_mode => $dir_mode,
+    :data_mode => $data_mode,
+    :prog_mode => $script_mode,
+    :wrappers => true,
+    :format_executable => true,
+    :install_as_default => true,
+  }
   default_spec_dir = Gem.default_specifications_dir
 
   gems = Dir.glob("#{srcdir}/#{dir}/**/*.gemspec").map {|src|
@@ -926,25 +943,12 @@ def install_default_gem(dir, srcdir) https://github.com/ruby/ruby/blob/trunk/tool/rbinstall.rb#L943
 
     full_name = "#{gemspec.name}-#{gemspec.version}"
 
-    puts "#{INDENT}#{gemspec.name} #{gemspec.version}"
-    gemspec_path = File.join(default_spec_dir, "#{full_name}.gemspec")
-    open_for_install(gemspec_path, $data_mode) do
-      gemspec.to_ruby.gsub(/.*\0.*\n/, '')
-    end
-
-    specific_gem_dir = File.join(gem_dir, 'gems', full_name)
-
-    makedirs(specific_gem_dir)
-
-    unless gemspec.executables.empty? then
-      bin_dir = File.join(specific_gem_dir, gemspec.bindir)
-      makedirs(bin_dir)
+    gemspec.loaded_from = File.join srcdir, gemspec.spec_name
 
-      gemspec.executables.map {|exec|
-        install File.join(srcdir, 'libexec', exec),
-                File.join(bin_dir, exec)
-      }
-    end
+    package = RbInstall::DirPackage.new gemspec
+    ins = RbInstall::UnpackedInstaller.new(package, options)
+    puts "#{INDENT}#{gemspec.name} #{gemspec.version}"
+    ins.install
   end
 end
 
-- 
cgit v1.1


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]