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

ruby-changes:74028

From: nagachika <ko1@a...>
Date: Sun, 16 Oct 2022 19:38:54 +0900 (JST)
Subject: [ruby-changes:74028] c1129491bb (ruby_3_1): merge revision(s) 64cff780051adf95a0f1799baddec98ae23e8add:

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

From c1129491bbf072862d10caa5b97acaa59437ecf3 Mon Sep 17 00:00:00 2001
From: nagachika <nagachika@r...>
Date: Sun, 16 Oct 2022 19:37:57 +0900
Subject: merge revision(s) 64cff780051adf95a0f1799baddec98ae23e8add:

	`Gem.unpack` extracts gems so able to execute

	Creates simple bin stubs to load the extracted executable files.
	After only extracted under `gems` directory, the gems are considered
	installed but the executable scripts are not found.
	Also the second argument is now the parent of the previous second and
	third arguments.
	---
	 common.mk          |  6 ++----
	 defs/gmake.mk      |  3 +--
	 tool/gem-unpack.rb | 30 +++++++++++++++++++-----------
	 3 files changed, 22 insertions(+), 17 deletions(-)
---
 common.mk          |  3 ++-
 defs/gmake.mk      |  2 +-
 tool/gem-unpack.rb | 30 +++++++++++++++++++-----------
 version.h          |  2 +-
 4 files changed, 23 insertions(+), 14 deletions(-)

diff --git a/common.mk b/common.mk
index 39b8b727f5..7e97562d77 100644
--- a/common.mk
+++ b/common.mk
@@ -1362,10 +1362,11 @@ extract-gems$(gnumake:yes=-nongnumake): PHONY https://github.com/ruby/ruby/blob/trunk/common.mk#L1362
 	    -Itool -rgem-unpack -answ \
 	    -e 'BEGIN {FileUtils.mkdir_p(d = ".bundle/gems")}' \
 	    -e 'BEGIN {FileUtils.mkdir_p(s = ".bundle/specifications")}' \
+	    -e 'BEGIN {d = ".bundle/gems"}' \
 	    -e 'gem, ver = *$$F' \
 	    -e 'next if !ver or /^#/=~gem' \
 	    -e 'g = "#{gem}-#{ver}"' \
-	    -e 'File.directory?("#{d}/#{g}") or Gem.unpack("gems/#{g}.gem", d, s)' \
+	    -e 'File.directory?("#{d}/#{g}") or Gem.unpack("gems/#{g}.gem", ".bundle")' \
 	    gems/bundled_gems
 
 update-bundled_gems: PHONY
diff --git a/defs/gmake.mk b/defs/gmake.mk
index b4e12d1385..7243a304dc 100644
--- a/defs/gmake.mk
+++ b/defs/gmake.mk
@@ -290,7 +290,7 @@ extract-gems: | $(patsubst %,.bundle/gems/%,$(bundled-gems)) https://github.com/ruby/ruby/blob/trunk/defs/gmake.mk#L290
 	$(ECHO) Extracting bundle gem $*...
 	$(Q) $(BASERUBY) -C "$(srcdir)" \
 	    -Itool -rgem-unpack \
-	    -e 'Gem.unpack("gems/$(@F).gem", ".bundle/gems", ".bundle/specifications")'
+	    -e 'Gem.unpack("gems/$(@F).gem", ".bundle")'
 
 $(srcdir)/.bundle/gems:
 	$(MAKEDIRS) $@
diff --git a/tool/gem-unpack.rb b/tool/gem-unpack.rb
index 770ddce618..c50d47f797 100644
--- a/tool/gem-unpack.rb
+++ b/tool/gem-unpack.rb
@@ -5,22 +5,30 @@ require 'rubygems/package' https://github.com/ruby/ruby/blob/trunk/tool/gem-unpack.rb#L5
 # This library is used by "make extract-gems" to
 # unpack bundled gem files.
 
-def Gem.unpack(file, dir = nil, spec_dir = nil)
+def Gem.unpack(file, dir = ".")
   pkg = Gem::Package.new(file)
   spec = pkg.spec
   target = spec.full_name
-  target = File.join(dir, target) if dir
-  pkg.extract_files target
-  if spec.extensions.empty?
-    spec_dir ||= target
-  else
-    spec_dir = target
-  end
-  FileUtils.mkdir_p(spec_dir)
-  File.binwrite(File.join(spec_dir, "#{spec.name}-#{spec.version}.gemspec"), spec.to_ruby)
+  Gem.ensure_gem_subdirectories(dir)
+  gem_dir = File.join(dir, "gems", target)
+  pkg.extract_files gem_dir
+  spec_dir = spec.extensions.empty? ? "specifications" : File.join("gems", target)
+  File.binwrite(File.join(dir, spec_dir, "#{target}.gemspec"), spec.to_ruby)
   unless spec.extensions.empty?
     spec.dependencies.clear
-    File.binwrite(File.join(spec_dir, ".bundled.#{spec.name}-#{spec.version}.gemspec"), spec.to_ruby)
+    File.binwrite(File.join(dir, spec_dir, ".bundled.#{target}.gemspec"), spec.to_ruby)
+  end
+  if spec.bindir and spec.executables
+    bindir = File.join(dir, "bin")
+    Dir.mkdir(bindir) rescue nil
+    spec.executables.each do |exe|
+      File.open(File.join(bindir, exe), "wb", 0o777) {|f|
+        f.print "#!ruby\n",
+                %[load File.realpath("../gems/#{target}/#{spec.bindir}/#{exe}", __dir__)\n]
+      }
+    end
   end
+  FileUtils.rm_rf(Dir.glob("#{gem_dir}/.git*"))
+
   puts "Unpacked #{file}"
 end
diff --git a/version.h b/version.h
index 68b3a26cfc..24268de146 100644
--- a/version.h
+++ b/version.h
@@ -11,7 +11,7 @@ https://github.com/ruby/ruby/blob/trunk/version.h#L11
 # define RUBY_VERSION_MINOR RUBY_API_VERSION_MINOR
 #define RUBY_VERSION_TEENY 3
 #define RUBY_RELEASE_DATE RUBY_RELEASE_YEAR_STR"-"RUBY_RELEASE_MONTH_STR"-"RUBY_RELEASE_DAY_STR
-#define RUBY_PATCHLEVEL 97
+#define RUBY_PATCHLEVEL 98
 
 #define RUBY_RELEASE_YEAR 2022
 #define RUBY_RELEASE_MONTH 10
-- 
cgit v1.2.3


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

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