mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
64cff78005
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.
34 lines
1.1 KiB
Ruby
34 lines
1.1 KiB
Ruby
require 'fileutils'
|
|
require 'rubygems'
|
|
require 'rubygems/package'
|
|
|
|
# This library is used by "make extract-gems" to
|
|
# unpack bundled gem files.
|
|
|
|
def Gem.unpack(file, dir = ".")
|
|
pkg = Gem::Package.new(file)
|
|
spec = pkg.spec
|
|
target = spec.full_name
|
|
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(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
|