diff options
author | nagachika <nagachika@ruby-lang.org> | 2022-10-16 19:37:57 +0900 |
---|---|---|
committer | nagachika <nagachika@ruby-lang.org> | 2022-10-16 19:37:57 +0900 |
commit | c1129491bbf072862d10caa5b97acaa59437ecf3 (patch) | |
tree | 311d3b87ad571f5b9d036ccf301e32ee05f64e30 | |
parent | 174594cf77bed6c3899af4ef14f6c7d257e6461d (diff) |
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(-)
-rw-r--r-- | common.mk | 3 | ||||
-rw-r--r-- | defs/gmake.mk | 2 | ||||
-rw-r--r-- | tool/gem-unpack.rb | 30 | ||||
-rw-r--r-- | version.h | 2 |
4 files changed, 23 insertions, 14 deletions
@@ -1362,10 +1362,11 @@ extract-gems$(gnumake:yes=-nongnumake): PHONY -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)) $(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' # 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 @@ -11,7 +11,7 @@ # 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 |