2012-01-18 14:54:01 +00:00
|
|
|
module Gem
|
|
|
|
class << self
|
|
|
|
|
|
|
|
##
|
2013-01-08 15:23:30 +00:00
|
|
|
# Returns full path of previous but one directory of dir in path
|
|
|
|
# E.g. for '/usr/share/ruby', 'ruby', it returns '/usr'
|
2012-01-18 14:54:01 +00:00
|
|
|
|
2013-01-08 15:23:30 +00:00
|
|
|
def previous_but_one_dir_to(path, dir)
|
|
|
|
split_path = path.split(File::SEPARATOR)
|
|
|
|
File.join(split_path.take_while { |one_dir| one_dir !~ /^#{dir}$/ }[0..-2])
|
2012-01-18 14:54:01 +00:00
|
|
|
end
|
2013-01-08 15:23:30 +00:00
|
|
|
private :previous_but_one_dir_to
|
2012-01-18 14:54:01 +00:00
|
|
|
|
|
|
|
##
|
|
|
|
# Default gems locations allowed on FHS system (/usr, /usr/share).
|
|
|
|
# The locations are derived from directories specified during build
|
|
|
|
# configuration.
|
|
|
|
|
|
|
|
def default_locations
|
|
|
|
@default_locations ||= {
|
2013-01-08 15:23:30 +00:00
|
|
|
:system => previous_but_one_dir_to(ConfigMap[:vendordir], ConfigMap[:RUBY_INSTALL_NAME]),
|
|
|
|
:local => previous_but_one_dir_to(ConfigMap[:sitedir], ConfigMap[:RUBY_INSTALL_NAME])
|
2012-01-18 14:54:01 +00:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
##
|
|
|
|
# For each location provides set of directories for binaries (:bin_dir)
|
|
|
|
# platform independent (:gem_dir) and dependent (:ext_dir) files.
|
|
|
|
|
|
|
|
def default_dirs
|
2013-01-08 15:23:30 +00:00
|
|
|
@libdir ||= ConfigMap[:sitelibdir] == ConfigMap[:sitearchdir] ? ConfigMap[:datadir] : ConfigMap[:libdir]
|
2012-01-18 14:54:01 +00:00
|
|
|
@default_dirs ||= Hash[default_locations.collect do |destination, path|
|
|
|
|
[destination, {
|
|
|
|
:bin_dir => File.join(path, ConfigMap[:bindir].split(File::SEPARATOR).last),
|
|
|
|
:gem_dir => File.join(path, ConfigMap[:datadir].split(File::SEPARATOR).last, 'gems'),
|
2013-01-08 15:23:30 +00:00
|
|
|
:ext_dir => File.join(path, @libdir.split(File::SEPARATOR).last, 'gems')
|
2012-01-18 14:54:01 +00:00
|
|
|
}]
|
|
|
|
end]
|
|
|
|
end
|
|
|
|
|
|
|
|
##
|
|
|
|
# RubyGems default overrides.
|
|
|
|
|
|
|
|
def default_dir
|
|
|
|
if Process.uid == 0
|
|
|
|
Gem.default_dirs[:local][:gem_dir]
|
|
|
|
else
|
|
|
|
Gem.user_dir
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def default_path
|
|
|
|
path = default_dirs.collect {|location, paths| paths[:gem_dir]}
|
|
|
|
path.unshift Gem.user_dir if File.exist? Gem.user_home
|
|
|
|
end
|
|
|
|
|
|
|
|
def default_bindir
|
|
|
|
if Process.uid == 0
|
|
|
|
Gem.default_dirs[:local][:bin_dir]
|
|
|
|
else
|
|
|
|
File.join [Dir.home, 'bin']
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def default_ext_dir_for base_dir
|
|
|
|
dirs = Gem.default_dirs.detect {|location, paths| paths[:gem_dir] == base_dir}
|
2013-01-08 15:23:30 +00:00
|
|
|
dirs && File.join(dirs.last[:ext_dir], RbConfig::CONFIG['RUBY_INSTALL_NAME'])
|
2012-01-18 14:54:01 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|