1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

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.
This commit is contained in:
Nobuyoshi Nakada 2022-07-17 16:05:16 +09:00
parent fab8f3bde6
commit 64cff78005
Notes: git 2022-07-17 19:58:17 +09:00
3 changed files with 22 additions and 17 deletions

View file

@ -1360,13 +1360,11 @@ extract-gems$(gnumake:yes=-nongnumake): PHONY
$(ECHO) Extracting bundled gem files... $(ECHO) Extracting bundled gem files...
$(Q) $(RUNRUBY) -C "$(srcdir)" \ $(Q) $(RUNRUBY) -C "$(srcdir)" \
-Itool -rfileutils -rgem-unpack -answ \ -Itool -rfileutils -rgem-unpack -answ \
-e 'BEGIN {FileUtils.mkdir_p(d = ".bundle/gems")}' \ -e 'BEGIN {d = ".bundle/gems"}' \
-e 'BEGIN {FileUtils.mkdir_p(s = ".bundle/specifications")}' \
-e 'gem, ver = *$$F' \ -e 'gem, ver = *$$F' \
-e 'next if !ver or /^#/=~gem' \ -e 'next if !ver or /^#/=~gem' \
-e 'g = "#{gem}-#{ver}"' \ -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")' \
-e 'FileUtils.rm_rf("#{d}/#{g}/.github")' \
gems/bundled_gems gems/bundled_gems
update-bundled_gems: PHONY update-bundled_gems: PHONY

View file

@ -298,8 +298,7 @@ extract-gems: | $(patsubst %,.bundle/gems/%,$(bundled-gems))
$(ECHO) Extracting bundle gem $*... $(ECHO) Extracting bundle gem $*...
$(Q) $(BASERUBY) -C "$(srcdir)" \ $(Q) $(BASERUBY) -C "$(srcdir)" \
-Itool -rgem-unpack \ -Itool -rgem-unpack \
-e 'Gem.unpack("gems/$(@F).gem", ".bundle/gems", ".bundle/specifications")' -e 'Gem.unpack("gems/$(@F).gem", ".bundle")'
$(RMALL) "$(srcdir)/$(@:.gem=)/".git*
$(srcdir)/.bundle/gems: $(srcdir)/.bundle/gems:
$(MAKEDIRS) $@ $(MAKEDIRS) $@

View file

@ -5,22 +5,30 @@ require 'rubygems/package'
# This library is used by "make extract-gems" to # This library is used by "make extract-gems" to
# unpack bundled gem files. # unpack bundled gem files.
def Gem.unpack(file, dir = nil, spec_dir = nil) def Gem.unpack(file, dir = ".")
pkg = Gem::Package.new(file) pkg = Gem::Package.new(file)
spec = pkg.spec spec = pkg.spec
target = spec.full_name target = spec.full_name
target = File.join(dir, target) if dir Gem.ensure_gem_subdirectories(dir)
pkg.extract_files target gem_dir = File.join(dir, "gems", target)
if spec.extensions.empty? pkg.extract_files gem_dir
spec_dir ||= target spec_dir = spec.extensions.empty? ? "specifications" : File.join("gems", target)
else File.binwrite(File.join(dir, spec_dir, "#{target}.gemspec"), spec.to_ruby)
spec_dir = target
end
FileUtils.mkdir_p(spec_dir)
File.binwrite(File.join(spec_dir, "#{spec.name}-#{spec.version}.gemspec"), spec.to_ruby)
unless spec.extensions.empty? unless spec.extensions.empty?
spec.dependencies.clear 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 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}" puts "Unpacked #{file}"
end end