Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

file 245 lines (185 sloc) 5.586 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245
#--
# Copyright 2006, 2007 by Chad Fowler, Rich Kilmer, Jim Weirich, Eric Hodel
# and others.
# All rights reserved.
# See LICENSE.txt for permissions.
#++

# Make sure rubygems isn't already loaded.
if ENV['RUBYOPT'] =~ /rubygems/ then
  ENV.delete 'RUBYOPT'

  ruby = File.join Config::CONFIG['bindir'], Config::CONFIG['ruby_install_name']
  ruby << Config::CONFIG['EXEEXT']

  exec(ruby, 'setup.rb', *ARGV)
end

$:.unshift 'lib'
require 'rubygems'

require 'fileutils'
require 'rbconfig'
require 'rdoc/rdoc'
require 'tmpdir'

include FileUtils::Verbose

# check ruby version

required_version = Gem::Version::Requirement.create(">= 1.8.2")

unless required_version.satisfied_by? Gem::Version.new(RUBY_VERSION) then
  abort "Expected Ruby version #{required_version}, was #{RUBY_VERSION}"
end

# install stuff

lib_dir = nil
bin_dir = nil

if ARGV.grep(/^--prefix/).empty? then
  lib_dir = Config::CONFIG['sitelibdir']
  bin_dir = Config::CONFIG['bindir']
else
  prefix = nil

  ARGV.grep(/^--prefix=(.*)/)
  if $1.nil? or $1.empty? then
    path_index = ARGV.index '--prefix'
    prefix = ARGV[path_index + 1]
  else
    prefix = $1
  end

  raise "invalid --prefix #{prefix.inspect}" if prefix.nil?

  lib_dir = File.join prefix, 'lib'
  bin_dir = File.join prefix, 'bin'

  mkdir_p lib_dir
  mkdir_p bin_dir
end

Dir.chdir 'lib' do
  lib_files = Dir[File.join('**', '*rb')]

  lib_files.each do |lib_file|
    dest_file = File.join lib_dir, lib_file
    dest_dir = File.dirname dest_file
    mkdir_p dest_dir unless File.directory? dest_dir

    install lib_file, dest_file, :mode => 0644
  end
end

Dir.chdir 'bin' do
  bin_files = Dir['*']

  bin_files.each do |bin_file|
    dest_file = File.join bin_dir, bin_file
    bin_tmp_file = File.join Dir.tmpdir, bin_file

    begin
      cp bin_file, bin_tmp_file
      bin = File.readlines bin_tmp_file
      bin[0] = "#!#{Gem.ruby}\n"

      File.open bin_tmp_file, 'w' do |fp|
        fp.puts bin.join
      end

      install bin_tmp_file, dest_file, :mode => 0755
    ensure
      rm bin_tmp_file
    end

    next unless Gem.win_platform?

    begin
      bin_cmd_file = File.join Dir.tmpdir, "#{bin_file}.bat"

      File.open bin_cmd_file, 'w' do |file|
        file.puts <<-TEXT
@ECHO OFF
IF NOT "%~f0" == "~f0" GOTO :WinNT
@"#{Gem.ruby}" "#{bin_file}" %1 %2 %3 %4 %5 %6 %7 %8 %9
GOTO :EOF
:WinNT
"%~d0%~p0ruby.exe" "%~d0%~p0%~n0" %*
TEXT
      end

      install bin_cmd_file, "#{dest_file}.bat", :mode => 0755
    ensure
      rm bin_cmd_file
    end
  end
end

# Replace old bin files with ones that abort.

old_bin_files = {
  'gem_mirror' => 'gem mirror',
  'gem_server' => 'gem server',
  'gemlock' => 'gem lock',
  'gemri' => 'ri',
  'gemwhich' => 'gem which',
  'index_gem_repository.rb' => 'gem generate_index',
}

old_bin_files.each do |old_bin_file, new_name|
  old_bin_path = File.join bin_dir, old_bin_file
  next unless File.exist? old_bin_path

  deprecation_message = "`#{old_bin_file}` has been deprecated. Use `#{new_name}` instead."

  File.open old_bin_path, 'w' do |fp|
    fp.write <<-EOF
#!#{Gem.ruby}

abort "#{deprecation_message}"
EOF
  end

  next unless Gem.win_platform?

  File.open "#{old_bin_path}.bat", 'w' do |fp|
    fp.puts %{@ECHO.#{deprecation_message}}
  end
end

# Remove source caches

require 'rubygems/source_info_cache'

user_cache_file = Gem::SourceInfoCache.user_cache_file
system_cache_file = Gem::SourceInfoCache.system_cache_file

rm user_cache_file if File.writable? user_cache_file
rm system_cache_file if File.writable? system_cache_file

# install RDoc

gem_doc_dir = File.join Gem.dir, 'doc'

if File.writable? gem_doc_dir then
  puts "Removing old RubyGems RDoc and ri..."
  Dir[File.join(Gem.dir, 'doc', 'rubygems-[0-9]*')].each do |dir|
    rm_rf dir
  end

  def run_rdoc(*args)
    args << '--quiet'
    args << '--main' << 'README'
    args << '.' << 'README' << 'LICENSE.txt' << 'GPL.txt'

    r = RDoc::RDoc.new
    r.document args
  end

  rubygems_name = "rubygems-#{Gem::RubyGemsVersion}"

  doc_dir = File.join Gem.dir, 'doc', rubygems_name

  unless ARGV.include? '--no-ri' then
    ri_dir = File.join doc_dir, 'ri'
    puts "Installing #{rubygems_name} ri into #{ri_dir}..."
    run_rdoc '--ri', '--op', ri_dir
  end

  unless ARGV.include? '--no-rdoc' then
    rdoc_dir = File.join(doc_dir, 'rdoc')
    puts "Installing #{rubygems_name} rdoc into #{rdoc_dir}..."
    run_rdoc '--op', rdoc_dir
  end
else
  puts "Skipping RDoc generation, #{gem_doc_dir} not writable"
  puts "Set the GEM_HOME environment variable if you want RDoc generated"
end

# Remove stubs

def stub?(path)
  return unless File.readable? path
  File.read(path, 40) =~ /^# This file was generated by RubyGems/ and
  File.readlines(path).size < 20
end

puts <<-EOF.gsub(/^ */, '')
As of RubyGems 0.8.0, library stubs are no longer needed.
Searching $LOAD_PATH for stubs to optionally delete (may take a while)...
EOF

gemfiles = Dir[File.join("{#{($LOAD_PATH).join(',')}}", '**', '*.rb')]
gemfiles = gemfiles.map { |file| File.expand_path file }.uniq

puts "...done."

seen_stub = false

gemfiles.each do |file|
  next if File.directory? file
  next unless stub? file

  unless seen_stub then
    puts "\nRubyGems has detected stubs that can be removed. Confirm their removal:"
  end
  seen_stub = true

  print " * remove #{file}? [y/n] "
  answer = gets

  if answer =~ /y/i then
    unlink file
    puts " (removed)"
  else
    puts " (skipping)"
  end
end

if seen_stub then
  puts "Finished with library stubs."
else
  puts "No library stubs found."
end
Something went wrong with that request. Please try again.