def install_to_staging(gem_path)
if attributes.include?(:prefix) && ! attributes[:prefix].nil?
installdir = "#{staging_path}/#{attributes[:prefix]}"
else
gemdir = safesystemout(*[attributes[:gem_gem], 'env', 'gemdir']).chomp
installdir = File.join(staging_path, gemdir)
end
::FileUtils.mkdir_p(installdir)
args = [attributes[:gem_gem], "install", "--quiet", "--no-ri", "--no-rdoc",
"--no-user-install", "--install-dir", installdir]
if !attributes[:gem_embed_dependencies?]
args += ["--ignore-dependencies"]
end
if attributes[:gem_env_shebang?]
args += ["-E"]
end
if attributes.include?(:gem_bin_path) && ! attributes[:gem_bin_path].nil?
bin_path = File.join(staging_path, attributes[:gem_bin_path])
else
gem_env = safesystemout(*[attributes[:gem_gem], 'env']).split("\n")
gem_bin = gem_env.select{ |line| line =~ /EXECUTABLE DIRECTORY/ }.first.split(': ').last
bin_path = File.join(staging_path, gem_bin)
end
args += ["--bindir", bin_path]
::FileUtils.mkdir_p(bin_path)
args << gem_path
safesystem(*args)
if attributes[:gem_shebang]
::Dir.entries(bin_path).each do |file_name|
next if ['.', '..'].include?(file_name)
file_path = File.join(bin_path, file_name)
next unless File.ftype(file_path) == 'file'
file = File.read(file_path)
if file.gsub!(/\A#!.*$/, "#!#{attributes[:gem_shebang]}")
File.open(file_path, 'w'){|f| f << file}
end
end
end
tmp = bin_path
while ::Dir.entries(tmp).size == 2 || tmp == "/"
logger.info("Deleting empty bin_path", :path => tmp)
::Dir.rmdir(tmp)
tmp = File.dirname(tmp)
end
if attributes[:gem_version_bins?] and File.directory?(bin_path)
(::Dir.entries(bin_path) - ['.','..']).each do |bin|
FileUtils.mv("#{bin_path}/#{bin}", "#{bin_path}/#{bin}-#{self.version}")
end
end
if attributes[:source_date_epoch_from_changelog?]
detect_source_date_from_changelog(installdir)
end
Find.find(installdir) do |path|
if path =~ /.*(gem_make.out|Makefile|mkmf.log)$/
logger.info("Removing no longer needed file %s to reduce nondeterminism" % path)
File.unlink(path)
end
end
end