2000-08-31 23:31:05 -04:00
|
|
|
#!./miniruby
|
1999-01-19 23:59:39 -05:00
|
|
|
|
2016-07-02 17:01:04 -04:00
|
|
|
# Used by the "make install" target to install Ruby.
|
|
|
|
# See common.mk for more details.
|
|
|
|
|
2009-09-14 17:43:00 -04:00
|
|
|
begin
|
|
|
|
load "./rbconfig.rb"
|
|
|
|
rescue LoadError
|
|
|
|
CONFIG = Hash.new {""}
|
|
|
|
else
|
|
|
|
include RbConfig
|
|
|
|
$".unshift File.expand_path("./rbconfig.rb")
|
|
|
|
end
|
1998-01-16 07:19:09 -05:00
|
|
|
|
2009-05-24 22:47:07 -04:00
|
|
|
srcdir = File.expand_path('../..', __FILE__)
|
2009-01-07 03:13:07 -05:00
|
|
|
unless defined?(CROSS_COMPILING) and CROSS_COMPILING
|
2009-05-24 22:47:07 -04:00
|
|
|
$:.replace([srcdir+"/lib", Dir.pwd])
|
2009-01-07 03:13:07 -05:00
|
|
|
end
|
2002-12-26 13:01:34 -05:00
|
|
|
require 'fileutils'
|
|
|
|
require 'shellwords'
|
2004-02-22 19:09:48 -05:00
|
|
|
require 'optparse'
|
|
|
|
require 'optparse/shellwords'
|
2011-08-04 02:44:13 -04:00
|
|
|
require 'ostruct'
|
2013-07-09 21:21:44 -04:00
|
|
|
require 'rubygems'
|
2015-01-16 19:00:53 -05:00
|
|
|
begin
|
|
|
|
require "zlib"
|
|
|
|
rescue LoadError
|
|
|
|
$" << "zlib.rb"
|
|
|
|
end
|
2002-12-26 13:01:34 -05:00
|
|
|
|
2017-10-30 01:45:20 -04:00
|
|
|
INDENT = " "*36
|
2005-03-03 04:44:33 -05:00
|
|
|
STDOUT.sync = true
|
2018-01-05 04:41:21 -05:00
|
|
|
File.umask(022)
|
2002-10-22 00:19:26 -04:00
|
|
|
|
2008-02-19 23:08:54 -05:00
|
|
|
def parse_args(argv = ARGV)
|
2004-02-22 19:09:48 -05:00
|
|
|
$mantype = 'doc'
|
|
|
|
$destdir = nil
|
2006-09-16 03:06:57 -04:00
|
|
|
$extout = nil
|
2004-02-22 19:09:48 -05:00
|
|
|
$make = 'make'
|
|
|
|
$mflags = []
|
2005-03-03 04:44:33 -05:00
|
|
|
$install = []
|
2006-09-16 03:06:57 -04:00
|
|
|
$installed_list = nil
|
|
|
|
$dryrun = false
|
2006-09-17 04:43:19 -04:00
|
|
|
$rdocdir = nil
|
2008-02-13 10:49:56 -05:00
|
|
|
$data_mode = 0644
|
|
|
|
$prog_mode = 0755
|
2008-02-19 23:08:54 -05:00
|
|
|
$dir_mode = nil
|
|
|
|
$script_mode = nil
|
2009-01-11 22:43:57 -05:00
|
|
|
$strip = false
|
2010-11-09 17:20:12 -05:00
|
|
|
$cmdtype = (if File::ALT_SEPARATOR == '\\'
|
2015-01-31 23:46:55 -05:00
|
|
|
File.exist?("rubystub.exe") ? 'exe' : 'cmd'
|
2010-11-09 17:20:12 -05:00
|
|
|
end)
|
2008-02-19 23:08:54 -05:00
|
|
|
mflags = []
|
2004-02-22 19:09:48 -05:00
|
|
|
opt = OptionParser.new
|
2009-09-14 17:43:00 -04:00
|
|
|
opt.on('-n', '--dry-run') {$dryrun = true}
|
2004-02-22 19:09:48 -05:00
|
|
|
opt.on('--dest-dir=DIR') {|dir| $destdir = dir}
|
2006-09-16 03:06:57 -04:00
|
|
|
opt.on('--extout=DIR') {|dir| $extout = (dir unless dir.empty?)}
|
2004-02-22 19:09:48 -05:00
|
|
|
opt.on('--make=COMMAND') {|make| $make = make}
|
|
|
|
opt.on('--mantype=MAN') {|man| $mantype = man}
|
2006-09-10 09:59:59 -04:00
|
|
|
opt.on('--make-flags=FLAGS', '--mflags', Shellwords) do |v|
|
2004-02-22 19:09:48 -05:00
|
|
|
if arg = v.first
|
|
|
|
arg.insert(0, '-') if /\A[^-][^=]*\Z/ =~ arg
|
|
|
|
end
|
|
|
|
$mflags.concat(v)
|
2003-01-27 14:48:02 -05:00
|
|
|
end
|
2009-09-14 17:24:39 -04:00
|
|
|
opt.on('-i', '--install=TYPE', $install_procs.keys) do |ins|
|
2006-09-16 03:06:57 -04:00
|
|
|
$install << ins
|
|
|
|
end
|
2008-02-13 10:49:56 -05:00
|
|
|
opt.on('--data-mode=OCTAL-MODE', OptionParser::OctalInteger) do |mode|
|
|
|
|
$data_mode = mode
|
|
|
|
end
|
|
|
|
opt.on('--prog-mode=OCTAL-MODE', OptionParser::OctalInteger) do |mode|
|
|
|
|
$prog_mode = mode
|
|
|
|
end
|
2008-02-19 23:08:54 -05:00
|
|
|
opt.on('--dir-mode=OCTAL-MODE', OptionParser::OctalInteger) do |mode|
|
|
|
|
$dir_mode = mode
|
|
|
|
end
|
|
|
|
opt.on('--script-mode=OCTAL-MODE', OptionParser::OctalInteger) do |mode|
|
|
|
|
$script_mode = mode
|
|
|
|
end
|
2006-09-16 03:06:57 -04:00
|
|
|
opt.on('--installed-list [FILENAME]') {|name| $installed_list = name}
|
2006-09-21 09:58:33 -04:00
|
|
|
opt.on('--rdoc-output [DIR]') {|dir| $rdocdir = dir}
|
2015-01-31 23:46:55 -05:00
|
|
|
opt.on('--cmd-type=TYPE', %w[cmd plain]) {|cmd| $cmdtype = (cmd unless cmd == 'plain')}
|
2009-01-11 22:43:57 -05:00
|
|
|
opt.on('--[no-]strip') {|strip| $strip = strip}
|
2008-02-19 23:08:54 -05:00
|
|
|
|
|
|
|
opt.order!(argv) do |v|
|
|
|
|
case v
|
|
|
|
when /\AINSTALL[-_]([-\w]+)=(.*)/
|
|
|
|
argv.unshift("--#{$1.tr('_', '-')}=#{$2}")
|
|
|
|
when /\A\w[-\w+]*=\z/
|
|
|
|
mflags << v
|
|
|
|
when /\A\w[-\w+]*\z/
|
|
|
|
$install << v.intern
|
|
|
|
else
|
|
|
|
raise OptionParser::InvalidArgument, v
|
|
|
|
end
|
2009-09-14 17:24:39 -04:00
|
|
|
end rescue abort "#{$!.message}\n#{opt.help}"
|
2003-01-27 14:48:02 -05:00
|
|
|
|
2009-09-14 17:43:00 -04:00
|
|
|
unless defined?(RbConfig)
|
|
|
|
puts opt.help
|
|
|
|
exit
|
|
|
|
end
|
|
|
|
|
2003-01-25 13:59:34 -05:00
|
|
|
$make, *rest = Shellwords.shellwords($make)
|
|
|
|
$mflags.unshift(*rest) unless rest.empty?
|
2008-02-19 23:08:54 -05:00
|
|
|
$mflags.unshift(*mflags)
|
2003-01-25 13:59:34 -05:00
|
|
|
|
2003-01-26 03:56:01 -05:00
|
|
|
def $mflags.set?(flag)
|
2008-03-20 20:24:30 -04:00
|
|
|
grep(/\A-(?!-).*#{flag.chr}/i) { return true }
|
2003-01-27 14:48:02 -05:00
|
|
|
false
|
2003-01-26 03:56:01 -05:00
|
|
|
end
|
2006-09-16 03:06:57 -04:00
|
|
|
def $mflags.defined?(var)
|
2008-02-19 23:08:54 -05:00
|
|
|
grep(/\A#{var}=(.*)/) {return block_given? ? yield($1) : $1}
|
2006-09-16 03:06:57 -04:00
|
|
|
false
|
|
|
|
end
|
2003-01-26 03:56:01 -05:00
|
|
|
|
|
|
|
if $mflags.set?(?n)
|
|
|
|
$dryrun = true
|
|
|
|
else
|
|
|
|
$mflags << '-n' if $dryrun
|
|
|
|
end
|
2003-01-25 13:59:34 -05:00
|
|
|
|
2006-09-16 03:06:57 -04:00
|
|
|
$destdir ||= $mflags.defined?("DESTDIR")
|
2006-09-17 04:43:19 -04:00
|
|
|
if $extout ||= $mflags.defined?("EXTOUT")
|
2009-04-30 12:34:01 -04:00
|
|
|
RbConfig.expand($extout)
|
2006-09-17 04:43:19 -04:00
|
|
|
end
|
2003-01-25 13:59:34 -05:00
|
|
|
|
2003-01-26 03:56:01 -05:00
|
|
|
$continue = $mflags.set?(?k)
|
2006-09-16 03:06:57 -04:00
|
|
|
|
|
|
|
if $installed_list ||= $mflags.defined?('INSTALLED_LIST')
|
2009-04-30 12:34:01 -04:00
|
|
|
RbConfig.expand($installed_list, RbConfig::CONFIG)
|
2006-09-16 03:06:57 -04:00
|
|
|
$installed_list = open($installed_list, "ab")
|
|
|
|
$installed_list.sync = true
|
|
|
|
end
|
2006-09-17 04:43:19 -04:00
|
|
|
|
|
|
|
$rdocdir ||= $mflags.defined?('RDOCOUT')
|
2008-02-19 23:08:54 -05:00
|
|
|
|
|
|
|
$dir_mode ||= $prog_mode | 0700
|
|
|
|
$script_mode ||= $prog_mode
|
2003-01-25 13:59:34 -05:00
|
|
|
end
|
|
|
|
|
2006-09-17 04:43:19 -04:00
|
|
|
$install_procs = Hash.new {[]}
|
|
|
|
def install?(*types, &block)
|
|
|
|
$install_procs[:all] <<= block
|
|
|
|
types.each do |type|
|
|
|
|
$install_procs[type] <<= block
|
|
|
|
end
|
2005-03-03 04:44:33 -05:00
|
|
|
end
|
|
|
|
|
2011-07-22 03:12:22 -04:00
|
|
|
def strip_file(files)
|
2009-01-11 22:43:57 -05:00
|
|
|
if !defined?($strip_command) and (cmd = CONFIG["STRIP"])
|
|
|
|
case cmd
|
|
|
|
when "", "true", ":" then return
|
|
|
|
else $strip_command = Shellwords.shellwords(cmd)
|
|
|
|
end
|
|
|
|
elsif !$strip_command
|
|
|
|
return
|
|
|
|
end
|
2011-07-22 03:12:22 -04:00
|
|
|
system(*($strip_command + [files].flatten))
|
2009-01-11 22:43:57 -05:00
|
|
|
end
|
|
|
|
|
2003-07-29 03:08:04 -04:00
|
|
|
def install(src, dest, options = {})
|
2009-01-11 22:43:57 -05:00
|
|
|
options = options.clone
|
|
|
|
strip = options.delete(:strip)
|
2003-07-29 06:24:28 -04:00
|
|
|
options[:preserve] = true
|
2009-01-11 22:43:57 -05:00
|
|
|
d = with_destdir(dest)
|
|
|
|
super(src, d, options)
|
2011-07-22 03:12:22 -04:00
|
|
|
srcs = Array(src)
|
2009-01-12 02:49:22 -05:00
|
|
|
if strip
|
2015-01-13 03:21:44 -05:00
|
|
|
d = srcs.map {|s| File.join(d, File.basename(s))} if $made_dirs[dest]
|
2009-01-11 22:43:57 -05:00
|
|
|
strip_file(d)
|
|
|
|
end
|
2006-09-16 03:06:57 -04:00
|
|
|
if $installed_list
|
2015-01-13 03:21:44 -05:00
|
|
|
dest = srcs.map {|s| File.join(dest, File.basename(s))} if $made_dirs[dest]
|
2006-09-16 03:06:57 -04:00
|
|
|
$installed_list.puts dest
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def ln_sf(src, dest)
|
2006-09-17 04:43:19 -04:00
|
|
|
super(src, with_destdir(dest))
|
2006-09-16 03:06:57 -04:00
|
|
|
$installed_list.puts dest if $installed_list
|
2003-01-25 16:42:42 -05:00
|
|
|
end
|
2003-07-29 03:08:04 -04:00
|
|
|
|
2003-01-25 17:23:17 -05:00
|
|
|
$made_dirs = {}
|
|
|
|
def makedirs(dirs)
|
|
|
|
dirs = fu_list(dirs)
|
2006-09-17 04:43:19 -04:00
|
|
|
dirs.collect! do |dir|
|
|
|
|
realdir = with_destdir(dir)
|
|
|
|
realdir unless $made_dirs.fetch(dir) do
|
2003-01-25 17:23:17 -05:00
|
|
|
$made_dirs[dir] = true
|
2006-09-21 09:58:33 -04:00
|
|
|
$installed_list.puts(File.join(dir, "")) if $installed_list
|
2006-09-17 04:43:19 -04:00
|
|
|
File.directory?(realdir)
|
2003-01-25 17:23:17 -05:00
|
|
|
end
|
2006-09-17 04:43:19 -04:00
|
|
|
end.compact!
|
2008-02-19 23:08:54 -05:00
|
|
|
super(dirs, :mode => $dir_mode) unless dirs.empty?
|
2003-01-25 17:23:17 -05:00
|
|
|
end
|
2000-02-17 02:11:22 -05:00
|
|
|
|
2009-01-11 22:39:58 -05:00
|
|
|
FalseProc = proc {false}
|
|
|
|
def path_matcher(pat)
|
|
|
|
if pat and !pat.empty?
|
|
|
|
proc {|f| pat.any? {|n| File.fnmatch?(n, f)}}
|
|
|
|
else
|
|
|
|
FalseProc
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2006-12-04 09:49:47 -05:00
|
|
|
def install_recursive(srcdir, dest, options = {})
|
2008-02-11 22:16:07 -05:00
|
|
|
opts = options.clone
|
|
|
|
noinst = opts.delete(:no_install)
|
|
|
|
glob = opts.delete(:glob) || "*"
|
2013-05-27 04:33:47 -04:00
|
|
|
maxdepth = opts.delete(:maxdepth)
|
2009-01-11 22:39:58 -05:00
|
|
|
subpath = (srcdir.size+1)..-1
|
2010-12-10 04:27:53 -05:00
|
|
|
prune = []
|
|
|
|
skip = []
|
2009-01-11 22:39:58 -05:00
|
|
|
if noinst
|
|
|
|
if Array === noinst
|
|
|
|
prune = noinst.grep(/#{File::SEPARATOR}/o).map!{|f| f.chomp(File::SEPARATOR)}
|
|
|
|
skip = noinst.grep(/\A[^#{File::SEPARATOR}]*\z/o)
|
|
|
|
else
|
|
|
|
if noinst.index(File::SEPARATOR)
|
|
|
|
prune = [noinst]
|
2007-06-09 23:06:15 -04:00
|
|
|
else
|
2009-01-11 22:39:58 -05:00
|
|
|
skip = [noinst]
|
2007-06-09 23:06:15 -04:00
|
|
|
end
|
|
|
|
end
|
2009-01-11 22:39:58 -05:00
|
|
|
end
|
2010-12-10 04:27:53 -05:00
|
|
|
skip |= %w"#*# *~ *.old *.bak *.orig *.rej *.diff *.patch *.core"
|
|
|
|
prune = path_matcher(prune)
|
|
|
|
skip = path_matcher(skip)
|
2009-01-11 22:39:58 -05:00
|
|
|
File.directory?(srcdir) or return rescue return
|
2013-05-27 04:33:47 -04:00
|
|
|
paths = [[srcdir, dest, 0]]
|
2009-01-11 22:39:58 -05:00
|
|
|
found = []
|
|
|
|
while file = paths.shift
|
|
|
|
found << file
|
|
|
|
file, d, dir = *file
|
|
|
|
if dir
|
2013-05-27 04:33:47 -04:00
|
|
|
depth = dir + 1
|
|
|
|
next if maxdepth and maxdepth < depth
|
2009-01-11 22:39:58 -05:00
|
|
|
files = []
|
|
|
|
Dir.foreach(file) do |f|
|
|
|
|
src = File.join(file, f)
|
|
|
|
d = File.join(dest, dir = src[subpath])
|
2012-09-03 21:40:11 -04:00
|
|
|
stat = File.lstat(src) rescue next
|
2009-01-11 22:39:58 -05:00
|
|
|
if stat.directory?
|
2013-05-27 04:33:47 -04:00
|
|
|
files << [src, d, depth] if maxdepth != depth and /\A\./ !~ f and !prune[dir]
|
2012-09-03 21:40:11 -04:00
|
|
|
elsif stat.symlink?
|
|
|
|
# skip
|
2009-01-11 22:39:58 -05:00
|
|
|
else
|
|
|
|
files << [src, d, false] if File.fnmatch?(glob, f) and !skip[f]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
paths.insert(0, *files)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
for src, d, dir in found
|
|
|
|
if dir
|
2006-09-17 04:43:19 -04:00
|
|
|
makedirs(d)
|
|
|
|
else
|
2011-10-29 21:50:38 -04:00
|
|
|
makedirs(d[/.*(?=\/)/m])
|
2010-12-10 04:27:53 -05:00
|
|
|
if block_given?
|
|
|
|
yield src, d, opts
|
|
|
|
else
|
|
|
|
install src, d, opts
|
|
|
|
end
|
2006-09-17 04:43:19 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2008-03-20 20:24:30 -04:00
|
|
|
def open_for_install(path, mode)
|
|
|
|
data = open(realpath = with_destdir(path), "rb") {|f| f.read} rescue nil
|
|
|
|
newdata = yield
|
2006-09-17 04:43:19 -04:00
|
|
|
unless $dryrun
|
2008-03-20 20:24:30 -04:00
|
|
|
unless newdata == data
|
|
|
|
open(realpath, "wb", mode) {|f| f.write newdata}
|
|
|
|
end
|
2008-02-19 23:08:54 -05:00
|
|
|
File.chmod(mode, realpath)
|
2006-09-17 04:43:19 -04:00
|
|
|
end
|
2008-02-19 23:08:54 -05:00
|
|
|
$installed_list.puts path if $installed_list
|
2006-09-17 04:43:19 -04:00
|
|
|
end
|
|
|
|
|
2004-02-22 19:09:48 -05:00
|
|
|
def with_destdir(dir)
|
2005-07-05 10:45:33 -04:00
|
|
|
return dir if !$destdir or $destdir.empty?
|
2004-02-22 19:09:48 -05:00
|
|
|
dir = dir.sub(/\A\w:/, '') if File::PATH_SEPARATOR == ';'
|
|
|
|
$destdir + dir
|
2003-12-28 12:25:31 -05:00
|
|
|
end
|
|
|
|
|
2015-01-15 23:48:56 -05:00
|
|
|
def without_destdir(dir)
|
2016-02-15 12:50:08 -05:00
|
|
|
return dir if !$destdir or $destdir.empty?
|
|
|
|
dir.start_with?($destdir) ? dir[$destdir.size..-1] : dir
|
2015-01-15 23:48:56 -05:00
|
|
|
end
|
|
|
|
|
2009-03-09 01:33:59 -04:00
|
|
|
def prepare(mesg, basedir, subdirs=nil)
|
2012-03-12 21:59:54 -04:00
|
|
|
return unless basedir
|
2009-03-09 01:33:59 -04:00
|
|
|
case
|
|
|
|
when !subdirs
|
|
|
|
dirs = basedir
|
|
|
|
when subdirs.size == 0
|
|
|
|
subdirs = nil
|
|
|
|
when subdirs.size == 1
|
|
|
|
dirs = [basedir = File.join(basedir, subdirs)]
|
|
|
|
subdirs = nil
|
|
|
|
else
|
|
|
|
dirs = [basedir, *subdirs.collect {|dir| File.join(basedir, dir)}]
|
|
|
|
end
|
2017-10-30 01:45:20 -04:00
|
|
|
printf("%-*s%s%s\n", INDENT.size, "installing #{mesg}:", basedir,
|
2009-03-09 01:33:59 -04:00
|
|
|
(subdirs ? " (#{subdirs.join(', ')})" : ""))
|
|
|
|
makedirs(dirs)
|
|
|
|
end
|
|
|
|
|
2012-03-12 21:59:54 -04:00
|
|
|
def CONFIG.[](name, mandatory = false)
|
|
|
|
value = super(name)
|
|
|
|
if mandatory
|
|
|
|
raise "CONFIG['#{name}'] must be set" if !value or value.empty?
|
|
|
|
end
|
|
|
|
value
|
|
|
|
end
|
|
|
|
|
2002-10-22 00:19:26 -04:00
|
|
|
exeext = CONFIG["EXEEXT"]
|
|
|
|
|
2012-03-12 21:59:54 -04:00
|
|
|
ruby_install_name = CONFIG["ruby_install_name", true]
|
2002-10-22 00:19:26 -04:00
|
|
|
rubyw_install_name = CONFIG["rubyw_install_name"]
|
2007-12-26 00:39:03 -05:00
|
|
|
goruby_install_name = "go" + ruby_install_name
|
2000-02-17 02:11:22 -05:00
|
|
|
|
2012-03-12 21:59:54 -04:00
|
|
|
bindir = CONFIG["bindir", true]
|
2013-02-25 00:41:16 -05:00
|
|
|
libdir = CONFIG[CONFIG.fetch("libdirname", "libdir"), true]
|
2013-02-06 03:32:58 -05:00
|
|
|
rubyhdrdir = CONFIG["rubyhdrdir", true]
|
2013-02-07 03:02:31 -05:00
|
|
|
archhdrdir = CONFIG["rubyarchhdrdir"] || (rubyhdrdir + "/" + CONFIG['arch'])
|
2012-03-12 21:59:54 -04:00
|
|
|
rubylibdir = CONFIG["rubylibdir", true]
|
2013-02-06 03:32:53 -05:00
|
|
|
archlibdir = CONFIG["rubyarchdir", true]
|
2006-09-17 04:43:19 -04:00
|
|
|
sitelibdir = CONFIG["sitelibdir"]
|
|
|
|
sitearchlibdir = CONFIG["sitearchdir"]
|
2007-11-03 07:35:59 -04:00
|
|
|
vendorlibdir = CONFIG["vendorlibdir"]
|
|
|
|
vendorarchlibdir = CONFIG["vendorarchdir"]
|
2012-03-12 21:59:54 -04:00
|
|
|
mandir = CONFIG["mandir", true]
|
2012-05-03 10:56:39 -04:00
|
|
|
docdir = CONFIG["docdir", true]
|
2002-11-04 06:06:03 -05:00
|
|
|
enable_shared = CONFIG["ENABLE_SHARED"] == 'yes'
|
2012-03-12 21:59:54 -04:00
|
|
|
dll = CONFIG["LIBRUBY_SO", enable_shared]
|
|
|
|
lib = CONFIG["LIBRUBY", true]
|
|
|
|
arc = CONFIG["LIBRUBY_A", true]
|
2017-01-13 00:58:44 -05:00
|
|
|
load_relative = CONFIG["LIBRUBY_RELATIVE"] == 'yes'
|
2002-10-22 00:19:26 -04:00
|
|
|
|
2008-02-19 23:08:54 -05:00
|
|
|
install?(:local, :arch, :bin, :'bin-arch') do
|
2009-03-09 01:33:59 -04:00
|
|
|
prepare "binary commands", bindir
|
2003-01-21 03:03:05 -05:00
|
|
|
|
2009-01-11 22:43:57 -05:00
|
|
|
install ruby_install_name+exeext, bindir, :mode => $prog_mode, :strip => $strip
|
2006-02-23 22:12:27 -05:00
|
|
|
if rubyw_install_name and !rubyw_install_name.empty?
|
2009-01-11 22:43:57 -05:00
|
|
|
install rubyw_install_name+exeext, bindir, :mode => $prog_mode, :strip => $strip
|
2006-02-23 22:12:27 -05:00
|
|
|
end
|
2007-12-26 00:39:03 -05:00
|
|
|
if File.exist? goruby_install_name+exeext
|
2009-01-11 22:43:57 -05:00
|
|
|
install goruby_install_name+exeext, bindir, :mode => $prog_mode, :strip => $strip
|
2007-12-26 00:39:03 -05:00
|
|
|
end
|
2006-02-23 22:12:27 -05:00
|
|
|
if enable_shared and dll != lib
|
2009-01-11 22:43:57 -05:00
|
|
|
install dll, bindir, :mode => $prog_mode, :strip => $strip
|
2006-02-23 22:12:27 -05:00
|
|
|
end
|
2009-03-09 01:33:59 -04:00
|
|
|
end
|
|
|
|
|
2017-02-05 11:23:12 -05:00
|
|
|
install?(:local, :arch, :lib, :'lib-arch') do
|
2009-03-09 01:33:59 -04:00
|
|
|
prepare "base libraries", libdir
|
|
|
|
|
2009-01-11 22:43:57 -05:00
|
|
|
install lib, libdir, :mode => $prog_mode, :strip => $strip unless lib == arc
|
2016-10-17 03:17:07 -04:00
|
|
|
install arc, libdir, :mode => $data_mode unless CONFIG["INSTALL_STATIC_LIBRARY"] == "no"
|
2009-03-09 01:33:59 -04:00
|
|
|
if dll == lib and dll != arc
|
|
|
|
for link in CONFIG["LIBRUBY_ALIASES"].split
|
|
|
|
ln_sf(dll, File.join(libdir, link))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
prepare "arch files", archlibdir
|
2008-02-13 10:49:56 -05:00
|
|
|
install "rbconfig.rb", archlibdir, :mode => $data_mode
|
2006-02-23 22:12:27 -05:00
|
|
|
if CONFIG["ARCHFILE"]
|
|
|
|
for file in CONFIG["ARCHFILE"].split
|
2008-02-13 10:49:56 -05:00
|
|
|
install file, archlibdir, :mode => $data_mode
|
2006-02-23 22:12:27 -05:00
|
|
|
end
|
1999-01-19 23:59:39 -05:00
|
|
|
end
|
1999-08-13 01:45:20 -04:00
|
|
|
end
|
2002-09-08 05:08:15 -04:00
|
|
|
|
2010-10-25 11:29:32 -04:00
|
|
|
install?(:local, :arch, :data) do
|
|
|
|
pc = CONFIG["ruby_pc"]
|
2010-10-25 23:47:15 -04:00
|
|
|
if pc and File.file?(pc) and File.size?(pc)
|
2010-10-25 11:29:32 -04:00
|
|
|
prepare "pkgconfig data", pkgconfigdir = File.join(libdir, "pkgconfig")
|
|
|
|
install pc, pkgconfigdir, :mode => $data_mode
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2009-09-14 17:24:39 -04:00
|
|
|
install?(:ext, :arch, :'ext-arch') do
|
|
|
|
prepare "extension objects", archlibdir
|
2010-07-15 23:06:10 -04:00
|
|
|
noinst = %w[-* -*/] | (CONFIG["no_install_files"] || "").split
|
2009-09-14 17:24:39 -04:00
|
|
|
install_recursive("#{$extout}/#{CONFIG['arch']}", archlibdir, :no_install => noinst, :mode => $prog_mode, :strip => $strip)
|
|
|
|
prepare "extension objects", sitearchlibdir
|
|
|
|
prepare "extension objects", vendorarchlibdir
|
2016-09-24 09:26:21 -04:00
|
|
|
if extso = File.read("exts.mk")[/^EXTSO[ \t]*=[ \t]*((?:.*\\\n)*.*)/, 1] and
|
|
|
|
!(extso = extso.gsub(/\\\n/, '').split).empty?
|
|
|
|
libpathenv = CONFIG["LIBPATHENV"]
|
|
|
|
dest = CONFIG[!libpathenv || libpathenv == "PATH" ? "bindir" : "libdir"]
|
|
|
|
prepare "external libraries", dest
|
|
|
|
for file in extso
|
|
|
|
install file, dest, :mode => $prog_mode
|
|
|
|
end
|
|
|
|
end
|
2009-09-14 17:24:39 -04:00
|
|
|
end
|
2017-02-05 11:23:12 -05:00
|
|
|
install?(:ext, :arch, :hdr, :'arch-hdr', :'hdr-arch') do
|
2009-09-14 17:24:39 -04:00
|
|
|
prepare "extension headers", archhdrdir
|
2010-01-05 00:59:23 -05:00
|
|
|
install_recursive("#{$extout}/include/#{CONFIG['arch']}", archhdrdir, :glob => "*.h", :mode => $data_mode)
|
2009-09-14 17:24:39 -04:00
|
|
|
end
|
|
|
|
install?(:ext, :comm, :'ext-comm') do
|
|
|
|
prepare "extension scripts", rubylibdir
|
|
|
|
install_recursive("#{$extout}/common", rubylibdir, :mode => $data_mode)
|
|
|
|
prepare "extension scripts", sitelibdir
|
|
|
|
prepare "extension scripts", vendorlibdir
|
|
|
|
end
|
2017-02-05 11:23:12 -05:00
|
|
|
install?(:ext, :comm, :hdr, :'comm-hdr', :'hdr-comm') do
|
2009-09-14 17:24:39 -04:00
|
|
|
hdrdir = rubyhdrdir + "/ruby"
|
|
|
|
prepare "extension headers", hdrdir
|
|
|
|
install_recursive("#{$extout}/include/ruby", hdrdir, :glob => "*.h", :mode => $data_mode)
|
2006-09-16 03:06:57 -04:00
|
|
|
end
|
|
|
|
|
2008-12-22 08:19:08 -05:00
|
|
|
install?(:doc, :rdoc) do
|
2006-09-17 04:43:19 -04:00
|
|
|
if $rdocdir
|
2009-05-23 12:07:46 -04:00
|
|
|
ridatadir = File.join(CONFIG['ridir'], CONFIG['ruby_version'], "system")
|
2009-03-09 01:33:59 -04:00
|
|
|
prepare "rdoc", ridatadir
|
2008-02-13 10:49:56 -05:00
|
|
|
install_recursive($rdocdir, ridatadir, :mode => $data_mode)
|
2006-09-17 04:43:19 -04:00
|
|
|
end
|
|
|
|
end
|
2008-12-22 08:19:08 -05:00
|
|
|
install?(:doc, :capi) do
|
2012-05-03 10:56:39 -04:00
|
|
|
prepare "capi-docs", docdir
|
|
|
|
install_recursive "doc/capi", docdir+"/capi", :mode => $data_mode
|
2008-12-22 08:19:08 -05:00
|
|
|
end
|
1999-08-13 01:45:20 -04:00
|
|
|
|
2017-10-12 21:26:51 -04:00
|
|
|
prolog_script = <<EOS
|
2016-09-01 02:10:25 -04:00
|
|
|
bindir="#{load_relative ? '${0%/*}' : bindir.gsub(/\"/, '\\\\"')}"
|
2010-11-05 18:30:13 -04:00
|
|
|
EOS
|
2017-10-12 21:26:51 -04:00
|
|
|
if CONFIG["LIBRUBY_RELATIVE"] != 'yes' and libpathenv = CONFIG["LIBPATHENV"]
|
|
|
|
pathsep = File::PATH_SEPARATOR
|
|
|
|
prolog_script << <<EOS
|
|
|
|
libdir="#{load_relative ? '$\{bindir%/bin\}/lib' : libdir.gsub(/\"/, '\\\\"')}"
|
2016-09-01 02:10:25 -04:00
|
|
|
export #{libpathenv}="$libdir${#{libpathenv}:+#{pathsep}$#{libpathenv}}"
|
2010-11-05 18:30:13 -04:00
|
|
|
EOS
|
|
|
|
end
|
2017-10-12 21:26:51 -04:00
|
|
|
prolog_script << %Q[exec "$bindir/#{ruby_install_name}" "-x" "$0" "$@"\n]
|
|
|
|
PROLOG_SCRIPT = {}
|
|
|
|
PROLOG_SCRIPT["exe"] = "#!#{bindir}/#{ruby_install_name}"
|
|
|
|
PROLOG_SCRIPT["cmd"] = <<EOS
|
|
|
|
:""||{ ""=> %q<-*- ruby -*-
|
|
|
|
@"%~dp0#{ruby_install_name}" -x "%~f0" %*
|
|
|
|
@exit /b %ERRORLEVEL%
|
|
|
|
};{#\n#{prolog_script.gsub(/(?=\n)/, ' #')}>,\n}
|
|
|
|
EOS
|
|
|
|
PROLOG_SCRIPT.default = (load_relative || /\s/ =~ bindir) ?
|
|
|
|
<<EOS : PROLOG_SCRIPT["exe"]
|
|
|
|
#!/bin/sh
|
|
|
|
# -*- ruby -*-
|
|
|
|
_=_\\
|
|
|
|
=begin
|
|
|
|
#{prolog_script}=end
|
|
|
|
EOS
|
2010-11-05 18:30:13 -04:00
|
|
|
|
2018-04-26 21:58:29 -04:00
|
|
|
installer = Struct.new(:ruby_shebang, :ruby_bin, :ruby_install_name, :stub, :trans)
|
|
|
|
$script_installer = Class.new(installer) do
|
2006-09-17 04:43:19 -04:00
|
|
|
ruby_shebang = File.join(bindir, ruby_install_name)
|
2008-03-20 20:24:30 -04:00
|
|
|
if File::ALT_SEPARATOR
|
2008-02-19 23:08:54 -05:00
|
|
|
ruby_bin = ruby_shebang.tr(File::SEPARATOR, File::ALT_SEPARATOR)
|
2006-09-16 03:06:57 -04:00
|
|
|
end
|
2009-04-09 14:01:26 -04:00
|
|
|
if trans = CONFIG["program_transform_name"]
|
|
|
|
exp = []
|
|
|
|
trans.gsub!(/\$\$/, '$')
|
2009-08-26 06:56:55 -04:00
|
|
|
trans.scan(%r[\G[\s;]*(/(?:\\.|[^/])*/)?([sy])(\\?\W)((?:(?!\3)(?:\\.|.))*)\3((?:(?!\3)(?:\\.|.))*)\3([gi]*)]) do
|
2009-04-09 14:01:26 -04:00
|
|
|
|addr, cmd, sep, pat, rep, opt|
|
|
|
|
addr &&= Regexp.new(addr[/\A\/(.*)\/\z/, 1])
|
|
|
|
case cmd
|
|
|
|
when 's'
|
|
|
|
next if pat == '^' and rep.empty?
|
|
|
|
exp << [addr, (opt.include?('g') ? :gsub! : :sub!),
|
2009-06-25 00:10:21 -04:00
|
|
|
Regexp.new(pat, opt.include?('i')), rep.gsub(/&/){'\&'}]
|
2009-04-09 14:01:26 -04:00
|
|
|
when 'y'
|
|
|
|
exp << [addr, :tr!, Regexp.quote(pat), rep]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
trans = proc do |base|
|
|
|
|
exp.each {|addr, opt, pat, rep| base.__send__(opt, pat, rep) if !addr or addr =~ base}
|
|
|
|
base
|
|
|
|
end
|
|
|
|
elsif /ruby/ =~ ruby_install_name
|
|
|
|
trans = proc {|base| ruby_install_name.sub(/ruby/, base)}
|
|
|
|
else
|
|
|
|
trans = proc {|base| base}
|
|
|
|
end
|
2003-01-21 03:03:05 -05:00
|
|
|
|
2017-01-13 09:15:00 -05:00
|
|
|
def prolog(shebang)
|
2008-02-19 23:08:54 -05:00
|
|
|
shebang.sub!(/\r$/, '')
|
2017-10-12 21:26:51 -04:00
|
|
|
script = PROLOG_SCRIPT[$cmdtype]
|
|
|
|
shebang.sub!(/\A(\#!.*?ruby\b)?/) do
|
|
|
|
if script.end_with?("\n")
|
|
|
|
script + ($1 || "#!ruby\n")
|
|
|
|
else
|
|
|
|
$1 ? script : "#{script}\n"
|
|
|
|
end
|
|
|
|
end
|
2017-01-13 09:15:00 -05:00
|
|
|
shebang
|
|
|
|
end
|
|
|
|
|
|
|
|
def install(src, cmd)
|
|
|
|
cmd = cmd.sub(/[^\/]*\z/m) {|n| RbConfig.expand(trans[n])}
|
|
|
|
|
|
|
|
shebang, body = open(src, "rb") do |f|
|
|
|
|
next f.gets, f.read
|
|
|
|
end
|
|
|
|
shebang or raise "empty file - #{src}"
|
|
|
|
shebang = prolog(shebang)
|
2008-02-19 23:08:54 -05:00
|
|
|
body.gsub!(/\r$/, '')
|
|
|
|
|
|
|
|
cmd << ".#{$cmdtype}" if $cmdtype
|
2008-03-20 20:24:30 -04:00
|
|
|
open_for_install(cmd, $script_mode) do
|
2008-02-19 23:08:54 -05:00
|
|
|
case $cmdtype
|
2010-11-09 17:20:12 -05:00
|
|
|
when "exe"
|
|
|
|
stub + shebang + body
|
2008-02-19 23:08:54 -05:00
|
|
|
else
|
2008-03-20 20:24:30 -04:00
|
|
|
shebang + body
|
2008-02-19 23:08:54 -05:00
|
|
|
end
|
2006-09-16 03:06:57 -04:00
|
|
|
end
|
2003-01-21 03:03:05 -05:00
|
|
|
end
|
2017-01-13 09:15:00 -05:00
|
|
|
|
2018-04-26 21:58:29 -04:00
|
|
|
def self.get_rubystub
|
|
|
|
stubfile = "rubystub.exe"
|
|
|
|
stub = File.open(stubfile, "rb") {|f| f.read} << "\n"
|
|
|
|
rescue => e
|
|
|
|
abort "No #{stubfile}: #{e}"
|
|
|
|
else
|
|
|
|
stub
|
|
|
|
end
|
|
|
|
|
|
|
|
def stub
|
|
|
|
super or self.stub = self.class.get_rubystub
|
|
|
|
end
|
|
|
|
|
|
|
|
break new(ruby_shebang, ruby_bin, ruby_install_name, nil, trans)
|
2017-01-13 09:15:00 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
install?(:local, :comm, :bin, :'bin-comm') do
|
|
|
|
prepare "command scripts", bindir
|
|
|
|
|
|
|
|
install_recursive(File.join(srcdir, "bin"), bindir, :maxdepth => 1) do |src, cmd|
|
|
|
|
$script_installer.install(src, cmd)
|
|
|
|
end
|
2006-09-21 09:58:33 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
install?(:local, :comm, :lib) do
|
2009-03-09 01:33:59 -04:00
|
|
|
prepare "library scripts", rubylibdir
|
2017-10-05 04:32:01 -04:00
|
|
|
noinst = %w[*.txt *.rdoc *.gemspec]
|
2008-10-16 01:30:38 -04:00
|
|
|
install_recursive(File.join(srcdir, "lib"), rubylibdir, :no_install => noinst, :mode => $data_mode)
|
2006-09-21 09:58:33 -04:00
|
|
|
end
|
|
|
|
|
2014-09-27 04:17:43 -04:00
|
|
|
install?(:local, :comm, :hdr, :'comm-hdr') do
|
2009-03-09 01:33:59 -04:00
|
|
|
prepare "common headers", rubyhdrdir
|
1999-01-19 23:59:39 -05:00
|
|
|
|
2007-06-09 23:06:15 -04:00
|
|
|
noinst = []
|
2009-02-01 18:12:52 -05:00
|
|
|
unless RUBY_PLATFORM =~ /mswin|mingw|bccwin/
|
2007-06-09 23:06:15 -04:00
|
|
|
noinst << "win32.h"
|
2006-09-16 03:06:57 -04:00
|
|
|
end
|
2007-06-09 23:06:15 -04:00
|
|
|
noinst = nil if noinst.empty?
|
2009-03-09 01:33:59 -04:00
|
|
|
install_recursive(File.join(srcdir, "include"), rubyhdrdir, :no_install => noinst, :glob => "*.h", :mode => $data_mode)
|
2005-03-03 04:44:33 -05:00
|
|
|
end
|
1999-01-19 23:59:39 -05:00
|
|
|
|
2006-09-16 03:06:57 -04:00
|
|
|
install?(:local, :comm, :man) do
|
2009-03-09 01:33:59 -04:00
|
|
|
mdocs = Dir["#{srcdir}/man/*.[1-9]"]
|
|
|
|
prepare "manpages", mandir, ([] | mdocs.collect {|mdoc| mdoc[/\d+$/]}).sort.collect {|sec| "man#{sec}"}
|
2006-09-21 09:58:33 -04:00
|
|
|
|
2015-11-06 00:09:42 -05:00
|
|
|
case $mantype
|
|
|
|
when /\.(?:(gz)|bz2)\z/
|
|
|
|
compress = $1 ? "gzip" : "bzip2"
|
|
|
|
suffix = $&
|
|
|
|
end
|
2009-03-09 01:33:59 -04:00
|
|
|
mandir = File.join(mandir, "man")
|
2008-10-25 11:15:24 -04:00
|
|
|
has_goruby = File.exist?(goruby_install_name+exeext)
|
2015-11-06 00:09:42 -05:00
|
|
|
require File.join(srcdir, "tool/mdoc2man.rb") if /\Adoc\b/ !~ $mantype
|
2009-03-09 01:33:59 -04:00
|
|
|
mdocs.each do |mdoc|
|
2006-09-16 03:06:57 -04:00
|
|
|
next unless File.file?(mdoc) and open(mdoc){|fh| fh.read(1) == '.'}
|
2009-03-09 02:19:57 -04:00
|
|
|
base = File.basename(mdoc)
|
|
|
|
if base == "goruby.1"
|
2008-10-25 11:15:24 -04:00
|
|
|
next unless has_goruby
|
|
|
|
end
|
2003-07-09 02:45:45 -04:00
|
|
|
|
2009-03-09 01:33:59 -04:00
|
|
|
destdir = mandir + (section = mdoc[/\d+$/])
|
2009-03-09 02:19:57 -04:00
|
|
|
destname = ruby_install_name.sub(/ruby/, base.chomp(".#{section}"))
|
2008-10-25 11:15:24 -04:00
|
|
|
destfile = File.join(destdir, "#{destname}.#{section}")
|
2003-01-20 07:51:50 -05:00
|
|
|
|
2015-11-05 23:42:37 -05:00
|
|
|
if /\Adoc\b/ =~ $mantype
|
2015-11-06 00:09:42 -05:00
|
|
|
if compress
|
|
|
|
w = open(mdoc) {|f|
|
|
|
|
stdin = STDIN.dup
|
|
|
|
STDIN.reopen(f)
|
|
|
|
begin
|
|
|
|
destfile << suffix
|
2018-05-17 20:40:06 -04:00
|
|
|
IO.popen(compress, &:read)
|
2015-11-06 00:09:42 -05:00
|
|
|
ensure
|
|
|
|
STDIN.reopen(stdin)
|
|
|
|
stdin.close
|
|
|
|
end
|
|
|
|
}
|
|
|
|
open_for_install(destfile, $data_mode) {w}
|
|
|
|
else
|
|
|
|
install mdoc, destfile, :mode => $data_mode
|
2015-11-05 23:42:37 -05:00
|
|
|
end
|
2006-09-16 03:06:57 -04:00
|
|
|
else
|
2010-05-06 22:30:57 -04:00
|
|
|
class << (w = [])
|
|
|
|
alias print push
|
2009-01-07 03:13:07 -05:00
|
|
|
end
|
2010-05-06 22:30:57 -04:00
|
|
|
open(mdoc) {|r| Mdoc2Man.mdoc2man(r, w)}
|
2015-07-10 08:49:55 -04:00
|
|
|
w = w.join("")
|
2015-11-06 00:09:42 -05:00
|
|
|
if compress
|
2015-07-10 08:49:55 -04:00
|
|
|
require 'tmpdir'
|
|
|
|
Dir.mktmpdir("man") {|d|
|
|
|
|
dest = File.join(d, File.basename(destfile))
|
|
|
|
File.open(dest, "wb") {|f| f.write w}
|
|
|
|
if system(compress, dest)
|
|
|
|
w = File.open(dest+suffix, "rb") {|f| f.read}
|
|
|
|
destfile << suffix
|
|
|
|
end
|
|
|
|
}
|
|
|
|
end
|
|
|
|
open_for_install(destfile, $data_mode) {w}
|
2006-09-16 03:06:57 -04:00
|
|
|
end
|
2003-01-20 07:51:50 -05:00
|
|
|
end
|
|
|
|
end
|
2002-10-22 00:19:26 -04:00
|
|
|
|
2011-08-03 14:08:57 -04:00
|
|
|
module RbInstall
|
2015-01-15 23:48:56 -05:00
|
|
|
class UnpackedInstaller < Gem::Installer
|
|
|
|
module DirPackage
|
|
|
|
def extract_files(destination_dir, pattern = "*")
|
|
|
|
path = File.dirname(@gem.path)
|
|
|
|
return if path == destination_dir
|
2015-03-03 11:27:34 -05:00
|
|
|
File.chmod(0700, destination_dir)
|
2015-04-07 12:05:21 -04:00
|
|
|
mode = pattern == "bin/*" ? $script_mode : $data_mode
|
2017-04-11 08:20:21 -04:00
|
|
|
spec.files.each do |f|
|
|
|
|
src = File.join(path, f)
|
|
|
|
dest = File.join(without_destdir(destination_dir), f)
|
|
|
|
makedirs(dest[/.*(?=\/)/m])
|
|
|
|
install src, dest, :mode => mode
|
|
|
|
end
|
2015-03-03 11:27:34 -05:00
|
|
|
File.chmod($dir_mode, destination_dir)
|
2015-01-15 23:48:56 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def initialize(spec, *options)
|
|
|
|
super(spec.loaded_from, *options)
|
|
|
|
@package.extend(DirPackage).spec = spec
|
|
|
|
end
|
|
|
|
|
|
|
|
def write_cache_file
|
|
|
|
end
|
2016-08-17 10:14:44 -04:00
|
|
|
|
|
|
|
def build_extensions
|
|
|
|
end
|
2017-01-13 09:15:00 -05:00
|
|
|
|
|
|
|
def shebang(bin_file_name)
|
|
|
|
path = File.join(gem_dir, spec.bindir, bin_file_name)
|
|
|
|
first_line = File.open(path, "rb") {|file| file.gets}
|
2017-01-15 00:50:41 -05:00
|
|
|
$script_installer.prolog(first_line).chomp
|
|
|
|
end
|
|
|
|
|
|
|
|
def app_script_text(bin_file_name)
|
|
|
|
# move shell script part after comments generated by RubyGems.
|
|
|
|
super.sub(/\A
|
|
|
|
(\#!\/bin\/sh\n\#.*-\*-\s*ruby\s*-\*-.*\n)
|
|
|
|
((?:.*\n)*?\#!.*ruby.*\n)
|
|
|
|
\#\n
|
|
|
|
((?:\#.*\n)+)/x, '\1\3\2')
|
2017-01-13 09:15:00 -05:00
|
|
|
end
|
2017-01-14 19:45:10 -05:00
|
|
|
|
|
|
|
def check_executable_overwrite(filename)
|
|
|
|
return if @wrappers and same_bin_script?(filename, @bin_dir)
|
|
|
|
super
|
|
|
|
end
|
|
|
|
|
|
|
|
def generate_bin_script(filename, bindir)
|
|
|
|
return if same_bin_script?(filename, bindir)
|
|
|
|
super
|
|
|
|
end
|
|
|
|
|
|
|
|
def same_bin_script?(filename, bindir)
|
|
|
|
path = File.join(bindir, formatted_program_filename(filename))
|
|
|
|
begin
|
|
|
|
return true if File.binread(path) == app_script_text(filename)
|
|
|
|
rescue
|
|
|
|
end
|
|
|
|
false
|
|
|
|
end
|
2015-01-15 23:48:56 -05:00
|
|
|
end
|
2011-08-03 14:08:57 -04:00
|
|
|
end
|
2015-04-07 12:05:21 -04:00
|
|
|
|
|
|
|
class Gem::Installer
|
2015-04-07 12:05:32 -04:00
|
|
|
install = instance_method(:install)
|
|
|
|
define_method(:install) do
|
|
|
|
spec.post_install_message = nil
|
2017-02-06 21:49:02 -05:00
|
|
|
begin
|
|
|
|
u = File.umask(0022)
|
|
|
|
install.bind(self).call
|
|
|
|
ensure
|
|
|
|
File.umask(u)
|
|
|
|
end
|
2015-04-07 12:05:32 -04:00
|
|
|
end
|
|
|
|
|
2015-04-07 12:05:21 -04:00
|
|
|
generate_bin_script = instance_method(:generate_bin_script)
|
|
|
|
define_method(:generate_bin_script) do |filename, bindir|
|
|
|
|
generate_bin_script.bind(self).call(filename, bindir)
|
|
|
|
File.chmod($script_mode, File.join(bindir, formatted_program_filename(filename)))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-08-03 14:08:57 -04:00
|
|
|
# :startdoc:
|
|
|
|
|
2017-02-05 18:52:48 -05:00
|
|
|
install?(:ext, :comm, :gem, :'default-gems', :'default-gems-comm') do
|
2017-02-05 11:23:12 -05:00
|
|
|
install_default_gem('lib', srcdir)
|
|
|
|
end
|
2017-02-05 18:52:48 -05:00
|
|
|
install?(:ext, :arch, :gem, :'default-gems', :'default-gems-arch') do
|
2017-04-13 20:45:49 -04:00
|
|
|
install_default_gem('ext', srcdir) do |path|
|
|
|
|
# assume that gemspec and extconf.rb are placed in the same directory
|
2017-04-16 10:54:59 -04:00
|
|
|
success = false
|
|
|
|
begin
|
|
|
|
IO.foreach(File.dirname(path[(srcdir.size+1)..-1]) + "/Makefile") do |l|
|
|
|
|
break success = true if /^TARGET\s*=/ =~ l
|
|
|
|
end
|
|
|
|
rescue Errno::ENOENT
|
2017-04-13 20:45:49 -04:00
|
|
|
end
|
2017-04-16 10:54:59 -04:00
|
|
|
success
|
2017-04-13 20:45:49 -04:00
|
|
|
end
|
2017-02-05 11:23:12 -05:00
|
|
|
end
|
|
|
|
|
2017-04-12 04:39:19 -04:00
|
|
|
def load_gemspec(file)
|
|
|
|
code = File.read(file, encoding: "utf-8:-")
|
|
|
|
code.gsub!(/`git.*?`/m, '""')
|
|
|
|
begin
|
|
|
|
spec = eval(code, binding, file)
|
|
|
|
rescue SignalException, SystemExit
|
|
|
|
raise
|
|
|
|
rescue SyntaxError, Exception
|
|
|
|
end
|
|
|
|
raise("invalid spec in #{file}") unless spec
|
|
|
|
spec.loaded_from = file
|
|
|
|
spec
|
|
|
|
end
|
|
|
|
|
2017-02-05 11:23:12 -05:00
|
|
|
def install_default_gem(dir, srcdir)
|
2011-07-21 23:16:48 -04:00
|
|
|
gem_dir = Gem.default_dir
|
2013-03-06 20:39:13 -05:00
|
|
|
directories = Gem.ensure_gem_subdirectories(gem_dir, :mode => $dir_mode)
|
2017-10-30 01:45:20 -04:00
|
|
|
prepare "default gems from #{dir}", gem_dir, directories
|
2009-03-09 01:55:28 -04:00
|
|
|
|
2011-07-21 23:16:48 -04:00
|
|
|
spec_dir = File.join(gem_dir, directories.grep(/^spec/)[0])
|
2012-11-30 22:35:36 -05:00
|
|
|
default_spec_dir = "#{spec_dir}/default"
|
|
|
|
makedirs(default_spec_dir)
|
|
|
|
|
2017-02-05 11:23:12 -05:00
|
|
|
gems = Dir.glob("#{srcdir}/#{dir}/**/*.gemspec").map {|src|
|
2017-04-13 20:45:49 -04:00
|
|
|
next if block_given? and !yield(src)
|
|
|
|
load_gemspec(src)
|
2016-09-25 22:50:31 -04:00
|
|
|
}
|
|
|
|
gems.compact.sort_by(&:name).each do |gemspec|
|
2011-08-03 14:08:57 -04:00
|
|
|
full_name = "#{gemspec.name}-#{gemspec.version}"
|
|
|
|
|
2017-10-30 01:45:20 -04:00
|
|
|
puts "#{INDENT}#{gemspec.name} #{gemspec.version}"
|
2012-11-30 22:35:36 -05:00
|
|
|
gemspec_path = File.join(default_spec_dir, "#{full_name}.gemspec")
|
|
|
|
open_for_install(gemspec_path, $data_mode) do
|
2017-04-19 07:50:03 -04:00
|
|
|
gemspec.to_ruby
|
2009-03-09 01:55:28 -04:00
|
|
|
end
|
2011-07-21 23:16:48 -04:00
|
|
|
|
2011-08-03 14:08:57 -04:00
|
|
|
unless gemspec.executables.empty? then
|
2016-09-08 04:40:16 -04:00
|
|
|
bin_dir = File.join(gem_dir, 'gems', full_name, gemspec.bindir)
|
2011-07-21 23:16:48 -04:00
|
|
|
makedirs(bin_dir)
|
|
|
|
|
2017-01-13 09:15:00 -05:00
|
|
|
gemspec.executables.map {|exec|
|
|
|
|
$script_installer.install(File.join(srcdir, 'bin', exec),
|
|
|
|
File.join(bin_dir, exec))
|
|
|
|
}
|
2011-07-21 23:16:48 -04:00
|
|
|
end
|
2009-03-09 01:55:28 -04:00
|
|
|
end
|
2009-01-04 03:07:22 -05:00
|
|
|
end
|
|
|
|
|
2017-09-08 01:18:18 -04:00
|
|
|
install?(:ext, :comm, :gem, :'bundled-gems') do
|
2015-01-15 23:35:18 -05:00
|
|
|
gem_dir = Gem.default_dir
|
|
|
|
directories = Gem.ensure_gem_subdirectories(gem_dir, :mode => $dir_mode)
|
2017-09-08 01:18:18 -04:00
|
|
|
prepare "bundled gems", gem_dir, directories
|
2015-01-15 23:35:18 -05:00
|
|
|
install_dir = with_destdir(gem_dir)
|
2015-01-15 23:48:56 -05:00
|
|
|
installed_gems = {}
|
2015-04-04 20:34:27 -04:00
|
|
|
options = {
|
|
|
|
:install_dir => install_dir,
|
|
|
|
:bin_dir => with_destdir(bindir),
|
|
|
|
:domain => :local,
|
|
|
|
:ignore_dependencies => true,
|
|
|
|
:dir_mode => $dir_mode,
|
|
|
|
:data_mode => $data_mode,
|
|
|
|
:prog_mode => $prog_mode,
|
|
|
|
:wrappers => true,
|
|
|
|
:format_executable => true,
|
|
|
|
}
|
2016-08-17 10:14:44 -04:00
|
|
|
gem_ext_dir = "#$extout/gems/#{CONFIG['arch']}"
|
|
|
|
extensions_dir = Gem::StubSpecification.gemspec_stub("", gem_dir, gem_dir).extensions_dir
|
2016-09-04 02:15:58 -04:00
|
|
|
Gem::Specification.each_gemspec([srcdir+'/gems/*']) do |path|
|
2017-04-12 04:39:19 -04:00
|
|
|
spec = load_gemspec(path)
|
2016-09-04 02:25:38 -04:00
|
|
|
next unless spec.platform == Gem::Platform::RUBY
|
2016-09-04 20:58:23 -04:00
|
|
|
next unless spec.full_name == path[srcdir.size..-1][/\A\/gems\/([^\/]+)/, 1]
|
2016-08-17 10:14:44 -04:00
|
|
|
spec.extension_dir = "#{extensions_dir}/#{spec.full_name}"
|
|
|
|
if File.directory?(ext = "#{gem_ext_dir}/#{spec.full_name}")
|
|
|
|
spec.extensions[0] ||= "-"
|
|
|
|
end
|
2015-04-04 20:34:27 -04:00
|
|
|
ins = RbInstall::UnpackedInstaller.new(spec, options)
|
2017-10-30 01:45:20 -04:00
|
|
|
puts "#{INDENT}#{spec.name} #{spec.version}"
|
2015-01-15 23:48:56 -05:00
|
|
|
ins.install
|
2015-11-16 01:33:17 -05:00
|
|
|
File.chmod($data_mode, File.join(install_dir, "specifications", "#{spec.full_name}.gemspec"))
|
2016-08-17 10:14:44 -04:00
|
|
|
unless spec.extensions.empty?
|
|
|
|
install_recursive(ext, spec.extension_dir)
|
|
|
|
end
|
2015-01-15 23:48:56 -05:00
|
|
|
installed_gems[spec.full_name] = true
|
|
|
|
end
|
|
|
|
installed_gems, gems = Dir.glob(srcdir+'/gems/*.gem').partition {|gem| installed_gems.key?(File.basename(gem, '.gem'))}
|
|
|
|
unless installed_gems.empty?
|
|
|
|
install installed_gems, gem_dir+"/cache"
|
2014-12-25 11:48:32 -05:00
|
|
|
end
|
2015-01-15 23:48:56 -05:00
|
|
|
next if gems.empty?
|
2014-12-25 11:48:32 -05:00
|
|
|
if defined?(Zlib)
|
2015-04-11 19:31:48 -04:00
|
|
|
Gem.instance_variable_set(:@ruby, with_destdir(File.join(bindir, ruby_install_name)))
|
2016-08-17 13:36:28 -04:00
|
|
|
silent = Gem::SilentUI.new
|
2015-01-15 23:48:56 -05:00
|
|
|
gems.each do |gem|
|
2016-08-17 13:36:28 -04:00
|
|
|
inst = Gem::Installer.new(gem, options)
|
|
|
|
inst.spec.extension_dir = with_destdir(inst.spec.extension_dir)
|
|
|
|
begin
|
2017-02-06 21:49:02 -05:00
|
|
|
Gem::DefaultUserInteraction.use_ui(silent) {inst.install}
|
2018-05-17 20:38:00 -04:00
|
|
|
rescue Gem::InstallError
|
2016-08-17 13:36:28 -04:00
|
|
|
next
|
|
|
|
end
|
2015-01-15 23:35:18 -05:00
|
|
|
gemname = File.basename(gem)
|
2017-10-30 01:45:20 -04:00
|
|
|
puts "#{INDENT}#{gemname}"
|
2014-12-25 11:48:32 -05:00
|
|
|
end
|
|
|
|
# fix directory permissions
|
|
|
|
# TODO: Gem.install should accept :dir_mode option or something
|
2015-01-15 23:35:18 -05:00
|
|
|
File.chmod($dir_mode, *Dir.glob(install_dir+"/**/"))
|
2014-12-25 11:48:32 -05:00
|
|
|
# fix .gemspec permissions
|
2015-01-15 23:35:18 -05:00
|
|
|
File.chmod($data_mode, *Dir.glob(install_dir+"/specifications/*.gemspec"))
|
2014-12-25 11:48:32 -05:00
|
|
|
else
|
2017-09-08 01:18:18 -04:00
|
|
|
puts "skip installing bundled gems because of lacking zlib"
|
2014-12-25 11:48:32 -05:00
|
|
|
end
|
2014-06-23 05:13:14 -04:00
|
|
|
end
|
|
|
|
|
2009-09-14 17:24:39 -04:00
|
|
|
parse_args()
|
|
|
|
|
|
|
|
include FileUtils
|
|
|
|
include FileUtils::NoWrite if $dryrun
|
|
|
|
@fileutils_output = STDOUT
|
|
|
|
@fileutils_label = ''
|
|
|
|
|
2013-10-02 14:37:52 -04:00
|
|
|
all = $install.delete(:all)
|
2006-09-17 04:43:19 -04:00
|
|
|
$install << :local << :ext if $install.empty?
|
2013-10-02 14:37:52 -04:00
|
|
|
installs = $install.map do |inst|
|
2008-02-19 23:08:54 -05:00
|
|
|
if !(procs = $install_procs[inst]) || procs.empty?
|
|
|
|
next warn("unknown install target - #{inst}")
|
|
|
|
end
|
2013-10-02 14:37:52 -04:00
|
|
|
procs
|
|
|
|
end
|
|
|
|
installs.flatten!
|
|
|
|
installs.uniq!
|
|
|
|
installs |= $install_procs[:all] if all
|
|
|
|
installs.each do |block|
|
|
|
|
dir = Dir.pwd
|
|
|
|
begin
|
|
|
|
block.call
|
|
|
|
ensure
|
|
|
|
Dir.chdir(dir)
|
2006-09-17 04:43:19 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
1998-01-16 07:19:09 -05:00
|
|
|
# vi:set sw=2:
|