summaryrefslogtreecommitdiff
path: root/tool
diff options
context:
space:
mode:
authornagachika <nagachika@ruby-lang.org>2022-10-16 19:37:57 +0900
committernagachika <nagachika@ruby-lang.org>2022-10-16 19:37:57 +0900
commitc1129491bbf072862d10caa5b97acaa59437ecf3 (patch)
tree311d3b87ad571f5b9d036ccf301e32ee05f64e30 /tool
parent174594cf77bed6c3899af4ef14f6c7d257e6461d (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(-)
Diffstat (limited to 'tool')
-rw-r--r--tool/gem-unpack.rb30
1 files changed, 19 insertions, 11 deletions
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