Blame SOURCES/operating_system.rb

79386f
module Gem
79386f
  class << self
79386f
79386f
    ##
79386f
    # Returns a string representing that part or the directory tree that is
79386f
    # common to all specified directories.
79386f
79386f
    def common_path(dirs)
79386f
      paths = dirs.collect {|dir| dir.split(File::SEPARATOR)}
79386f
      uncommon_idx = paths.transpose.each_with_index.find {|dirnames, idx| dirnames.uniq.length > 1}.last
79386f
      paths[0][0 ... uncommon_idx].join(File::SEPARATOR)
79386f
    end
79386f
    private :common_path
79386f
79386f
    ##
79386f
    # Default gems locations allowed on FHS system (/usr, /usr/share).
79386f
    # The locations are derived from directories specified during build
79386f
    # configuration.
79386f
79386f
    def default_locations
79386f
      return @default_locations unless @default_locations.nil?
79386f
79386f
      @default_locations = {
79386f
        :system => common_path([ConfigMap[:vendorlibdir], ConfigMap[:vendorarchdir]]),
79386f
        :local => common_path([ConfigMap[:sitelibdir], ConfigMap[:sitearchdir]])
79386f
      }
79386f
79386f
      # Add additional default locations for enabled software collections
79386f
      # Dependent scls needs to add themselves on $GEM_PATH
79386f
      if ENV['GEM_PATH']
79386f
        gem_paths = ENV['GEM_PATH'].split(':')
79386f
79386f
        ENV['X_SCLS'].split(' ').each do |scl|
79386f
          next if scl == 'ruby200'
79386f
79386f
          regexp = /#{scl}\/root\/usr\/share\/gems/
79386f
          scl_gem_path = gem_paths.grep(regexp)[0]
79386f
          if scl_gem_path
79386f
            prefix = scl_gem_path.gsub(/\A(.*)#{regexp}\z/, "\\1")
79386f
            @default_locations["#{scl}_system".to_sym] = "#{prefix}#{scl}/root/usr"
79386f
            @default_locations["#{scl}_local".to_sym] = "#{prefix}#{scl}/root/usr/local"
79386f
          end
79386f
        end if ENV['X_SCLS']
79386f
      end
79386f
79386f
      @default_locations
79386f
    end
79386f
79386f
    ##
79386f
    # For each location provides set of directories for binaries (:bin_dir)
79386f
    # platform independent (:gem_dir) and dependent (:ext_dir) files.
79386f
79386f
    def default_dirs
79386f
      @libdir ||= case RUBY_PLATFORM
79386f
      when 'java'
79386f
        ConfigMap[:datadir]
79386f
      else
79386f
        ConfigMap[:libdir]
79386f
      end
79386f
79386f
      @default_dirs ||= Hash[default_locations.collect do |destination, path|
79386f
        [destination, {
79386f
          :bin_dir => File.join(path, ConfigMap[:bindir].split(File::SEPARATOR).last),
79386f
          :gem_dir => File.join(path, ConfigMap[:datadir].split(File::SEPARATOR).last, 'gems'),
79386f
          :ext_dir => File.join(path, ConfigMap[:libdir].split(File::SEPARATOR).last, 'gems')
79386f
        }]
79386f
      end]
79386f
    end
79386f
79386f
    ##
79386f
    # RubyGems default overrides.
79386f
79386f
    def default_dir
79386f
      if Process.uid == 0
79386f
        Gem.default_dirs[:local][:gem_dir]
79386f
      else
79386f
        Gem.user_dir
79386f
      end
79386f
    end
79386f
79386f
    def default_path
79386f
      path = default_dirs.collect {|location, paths| paths[:gem_dir]}
79386f
      path.unshift Gem.user_dir if File.exist? Gem.user_home
79386f
    end
79386f
79386f
    def default_bindir
79386f
      if Process.uid == 0
79386f
        Gem.default_dirs[:local][:bin_dir]
79386f
      else
79386f
        File.join [Dir.home, 'bin']
79386f
      end
79386f
    end
79386f
79386f
    def default_ext_dir_for base_dir
79386f
      dirs = Gem.default_dirs.detect {|location, paths| paths[:gem_dir] == base_dir}
79386f
      dirs && File.join(dirs.last[:ext_dir], RbConfig::CONFIG['RUBY_INSTALL_NAME'])
79386f
    end
79386f
  end
79386f
end