2020-12-08 04:38:25 -05:00
|
|
|
require 'fileutils'
|
2015-01-15 23:52:59 -05:00
|
|
|
require 'rubygems'
|
|
|
|
require 'rubygems/package'
|
|
|
|
|
2016-07-02 17:01:04 -04:00
|
|
|
# This library is used by "make extract-gems" to
|
|
|
|
# unpack bundled gem files.
|
|
|
|
|
2022-07-17 03:05:16 -04:00
|
|
|
def Gem.unpack(file, dir = ".")
|
2015-01-15 23:52:59 -05:00
|
|
|
pkg = Gem::Package.new(file)
|
|
|
|
spec = pkg.spec
|
|
|
|
target = spec.full_name
|
2022-07-17 03:05:16 -04:00
|
|
|
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)
|
2022-07-16 21:30:56 -04:00
|
|
|
unless spec.extensions.empty?
|
2022-07-13 05:58:32 -04:00
|
|
|
spec.dependencies.clear
|
2022-07-17 03:05:16 -04:00
|
|
|
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
|
2022-07-13 05:58:32 -04:00
|
|
|
end
|
2022-07-17 03:05:16 -04:00
|
|
|
FileUtils.rm_rf(Dir.glob("#{gem_dir}/.git*"))
|
|
|
|
|
2015-01-15 23:52:59 -05:00
|
|
|
puts "Unpacked #{file}"
|
|
|
|
end
|