pvalena / rpms / ruby

Forked from rpms/ruby 6 years ago
Clone
117278a
module Gem
117278a
  class << self
117278a
117278a
    ##
117278a
    # Returns a string representing that part or the directory tree that is
117278a
    # common to all specified directories.
117278a
117278a
    def common_path(dirs)
117278a
      paths = dirs.collect {|dir| dir.split(File::SEPARATOR)}
117278a
      uncommon_idx = paths.transpose.each_with_index.find {|dirnames, idx| dirnames.uniq.length > 1}.last
117278a
      paths[0][0 ... uncommon_idx].join(File::SEPARATOR)
117278a
    end
117278a
    private :common_path
117278a
117278a
    ##
117278a
    # Default gems locations allowed on FHS system (/usr, /usr/share).
117278a
    # The locations are derived from directories specified during build
117278a
    # configuration.
117278a
117278a
    def default_locations
117278a
      @default_locations ||= {
117278a
        :system => common_path([ConfigMap[:vendorlibdir], ConfigMap[:vendorarchdir]]),
117278a
        :local => common_path([ConfigMap[:sitelibdir], ConfigMap[:sitearchdir]])
117278a
      }
117278a
    end
117278a
117278a
    ##
117278a
    # For each location provides set of directories for binaries (:bin_dir)
117278a
    # platform independent (:gem_dir) and dependent (:ext_dir) files.
117278a
117278a
    def default_dirs
117278a
      @default_dirs ||= Hash[default_locations.collect do |destination, path|
117278a
        [destination, {
117278a
          :bin_dir => File.join(path, ConfigMap[:bindir].split(File::SEPARATOR).last),
117278a
          :gem_dir => File.join(path, ConfigMap[:datadir].split(File::SEPARATOR).last, 'gems'),
117278a
          :ext_dir => File.join(path, ConfigMap[:libdir].split(File::SEPARATOR).last, 'gems')
117278a
        }]
117278a
      end]
117278a
    end
117278a
117278a
    ##
117278a
    # RubyGems default overrides.
117278a
117278a
    def default_dir
117278a
      if Process.uid == 0
117278a
        Gem.default_dirs[:local][:gem_dir]
117278a
      else
117278a
        Gem.user_dir
117278a
      end
117278a
    end
117278a
117278a
    def default_path
117278a
      path = default_dirs.collect {|location, paths| paths[:gem_dir]}
117278a
      path.unshift Gem.user_dir if File.exist? Gem.user_home
117278a
    end
117278a
117278a
    def default_bindir
117278a
      if Process.uid == 0
117278a
        Gem.default_dirs[:local][:bin_dir]
117278a
      else
117278a
        File.join [Dir.home, 'bin']
117278a
      end
117278a
    end
117278a
117278a
    def default_ext_dir_for base_dir
117278a
      dirs = Gem.default_dirs.detect {|location, paths| paths[:gem_dir] == base_dir}
117278a
      dirs && File.join(dirs.last[:ext_dir], 'exts')
117278a
    end
117278a
  end
117278a
end