5 # Returns full path of previous but one directory of dir in path
6 # E.g. for '/usr/share/ruby', 'ruby', it returns '/usr'
8 def previous_but_one_dir_to(path, dir)
9 split_path = path.split(File::SEPARATOR)
10 File.join(split_path.take_while { |one_dir| one_dir !~ /^#{dir}$/ }[0..-2])
12 private :previous_but_one_dir_to
15 # Tries to detect, if arguments and environment variables suggest that
16 # 'gem install' is executed from rpmbuild.
19 (ARGV.include?('--install-dir') || ARGV.include?('-i')) && ENV['RPM_PACKAGE_NAME']
24 # Default gems locations allowed on FHS system (/usr, /usr/share).
25 # The locations are derived from directories specified during build
29 @default_locations ||= {
30 :system => previous_but_one_dir_to(ConfigMap[:vendordir], ConfigMap[:RUBY_INSTALL_NAME]),
31 :local => previous_but_one_dir_to(ConfigMap[:sitedir], ConfigMap[:RUBY_INSTALL_NAME])
36 # For each location provides set of directories for binaries (:bin_dir)
37 # platform independent (:gem_dir) and dependent (:ext_dir) files.
40 @libdir ||= case RUBY_PLATFORM
47 @default_dirs ||= Hash[default_locations.collect do |destination, path|
49 :bin_dir => File.join(path, ConfigMap[:bindir].split(File::SEPARATOR).last),
50 :gem_dir => File.join(path, ConfigMap[:datadir].split(File::SEPARATOR).last, 'gems'),
51 :ext_dir => File.join(path, @libdir.split(File::SEPARATOR).last, 'gems')
57 # Remove methods we are going to override. This avoids "method redefined;"
58 # warnings otherwise issued by Ruby.
60 remove_method :default_dir if method_defined? :default_dir
61 remove_method :default_path if method_defined? :default_path
62 remove_method :default_bindir if method_defined? :default_bindir
63 remove_method :default_ext_dir_for if method_defined? :default_ext_dir_for
66 # RubyGems default overrides.
70 Gem.default_dirs[:local][:gem_dir]
77 path = default_dirs.collect {|location, paths| paths[:gem_dir]}
78 path.unshift Gem.user_dir if File.exist? Gem.user_home
83 Gem.default_dirs[:local][:bin_dir]
85 File.join [Dir.home, 'bin']
89 def default_ext_dir_for base_dir
91 build_dir = base_dir.chomp Gem.default_dirs[:system][:gem_dir]
92 if build_dir != base_dir
93 File.join build_dir, Gem.default_dirs[:system][:ext_dir]
96 dirs = Gem.default_dirs.detect {|location, paths| paths[:gem_dir] == base_dir}
97 dirs && dirs.last[:ext_dir]
99 dir && File.join(dir, RbConfig::CONFIG['RUBY_INSTALL_NAME'])
102 # This method should be available since RubyGems 2.2 until RubyGems 3.0.
103 # https://github.com/rubygems/rubygems/issues/749
104 if method_defined? :install_extension_in_lib
105 remove_method :install_extension_in_lib
107 def install_extension_in_lib