Installs RubyGems itself. This command is ordinarily only available from a RubyGems checkout or tarball.
# File lib/rubygems/commands/setup_command.rb, line 12 12: def initialize 13: super 'setup', 'Install RubyGems', 14: :format_executable => true, :rdoc => true, :ri => true, 15: :site_or_vendor => :sitelibdir, 16: :destdir => '', :prefix => '' 17: 18: add_option '--prefix=PREFIX', 19: 'Prefix path for installing RubyGems', 20: 'Will not affect gem repository location' do |prefix, options| 21: options[:prefix] = File.expand_path prefix 22: end 23: 24: add_option '--destdir=DESTDIR', 25: 'Root directory to install RubyGems into', 26: 'Mainly used for packaging RubyGems' do |destdir, options| 27: options[:destdir] = File.expand_path destdir 28: end 29: 30: add_option '--[no-]vendor', 31: 'Install into vendorlibdir not sitelibdir', 32: '(Requires Ruby 1.8.7)' do |vendor, options| 33: if vendor and Gem.ruby_version < Gem::Version.new('1.8.7') then 34: raise OptionParser::InvalidOption, 35: "requires ruby 1.8.7+ (you have #{Gem.ruby_version})" 36: end 37: 38: options[:site_or_vendor] = vendor ? :vendorlibdir : :sitelibdir 39: end 40: 41: add_option '--[no-]format-executable', 42: 'Makes `gem` match ruby', 43: 'If ruby is ruby18, gem will be gem18' do |value, options| 44: options[:format_executable] = value 45: end 46: 47: add_option '--[no-]rdoc', 48: 'Generate RDoc documentation for RubyGems' do |value, options| 49: options[:rdoc] = value 50: end 51: 52: add_option '--[no-]ri', 53: 'Generate RI documentation for RubyGems' do |value, options| 54: options[:ri] = value 55: end 56: end
# File lib/rubygems/commands/setup_command.rb, line 58 58: def check_ruby_version 59: required_version = Gem::Requirement.new '>= 1.8.6' 60: 61: unless required_version.satisfied_by? Gem.ruby_version then 62: alert_error "Expected Ruby version #{required_version}, is #{Gem.ruby_version}" 63: terminate_interaction 1 64: end 65: end
# File lib/rubygems/commands/setup_command.rb, line 89 89: def execute 90: @verbose = Gem.configuration.really_verbose 91: 92: install_destdir = options[:destdir] 93: 94: unless install_destdir.empty? then 95: ENV['GEM_HOME'] ||= File.join(install_destdir, 96: Gem.default_dir.gsub(/^[a-zA-Z]:/, '')) 97: end 98: 99: check_ruby_version 100: 101: if Gem.configuration.really_verbose then 102: extend FileUtils::Verbose 103: else 104: extend FileUtils 105: end 106: 107: lib_dir, bin_dir = make_destination_dirs install_destdir 108: 109: install_lib lib_dir 110: 111: install_executables bin_dir 112: 113: remove_old_bin_files bin_dir 114: 115: remove_source_caches install_destdir 116: 117: say "RubyGems #{Gem::VERSION} installed" 118: 119: uninstall_old_gemcutter 120: 121: install_rdoc 122: 123: say 124: if @verbose then 125: say "-" * 78 126: say 127: end 128: 129: release_notes = File.join Dir.pwd, 'History.txt' 130: 131: release_notes = if File.exist? release_notes then 132: open release_notes do |io| 133: text = io.gets '===' 134: text << io.gets('===') 135: text[0...3] 136: end 137: else 138: "Oh-no! Unable to find release notes!" 139: end 140: 141: say release_notes 142: 143: say 144: say "-" * 78 145: say 146: 147: say "RubyGems installed the following executables:" 148: say @bin_file_names.map { |name| "\t#{name}\n" } 149: say 150: 151: unless @bin_file_names.grep(/#{File::SEPARATOR}gem$/) then 152: say "If `gem` was installed by a previous RubyGems installation, you may need" 153: say "to remove it by hand." 154: say 155: end 156: end
# File lib/rubygems/commands/setup_command.rb, line 158 158: def install_executables(bin_dir) 159: say "Installing gem executable" if @verbose 160: 161: @bin_file_names = [] 162: 163: Dir.chdir 'bin' do 164: bin_files = Dir['*'] 165: 166: bin_files.delete 'update_rubygems' 167: 168: bin_files.each do |bin_file| 169: bin_file_formatted = if options[:format_executable] then 170: Gem.default_exec_format % bin_file 171: else 172: bin_file 173: end 174: 175: dest_file = File.join bin_dir, bin_file_formatted 176: bin_tmp_file = File.join Dir.tmpdir, bin_file 177: 178: begin 179: bin = File.readlines bin_file 180: bin[0] = "#!#{Gem.ruby}\n" 181: 182: File.open bin_tmp_file, 'w' do |fp| 183: fp.puts bin.join 184: end 185: 186: install bin_tmp_file, dest_file, :mode => 0755 187: @bin_file_names << dest_file 188: ensure 189: rm bin_tmp_file 190: end 191: 192: next unless Gem.win_platform? 193: 194: begin 195: bin_cmd_file = File.join Dir.tmpdir, "#{bin_file}.bat" 196: 197: File.open bin_cmd_file, 'w' do |file| 198: file.puts @ECHO OFFIF NOT "%~f0" == "~f0" GOTO :WinNT@"#{File.basename(Gem.ruby).chomp('"')}" "#{dest_file}" %1 %2 %3 %4 %5 %6 %7 %8 %9GOTO :EOF:WinNT@"#{File.basename(Gem.ruby).chomp('"')}" "%~dpn0" %* 199: end 200: 201: install bin_cmd_file, "#{dest_file}.bat", :mode => 0755 202: ensure 203: rm bin_cmd_file 204: end 205: end 206: end 207: end
# File lib/rubygems/commands/setup_command.rb, line 216 216: def install_lib(lib_dir) 217: say "Installing RubyGems" if @verbose 218: 219: Dir.chdir 'lib' do 220: lib_files = Dir[File.join('**', '*rb')] 221: 222: lib_files.each do |lib_file| 223: dest_file = File.join lib_dir, lib_file 224: dest_dir = File.dirname dest_file 225: mkdir_p dest_dir unless File.directory? dest_dir 226: 227: install lib_file, dest_file, :mode => 0644 228: end 229: end 230: end
# File lib/rubygems/commands/setup_command.rb, line 232 232: def install_rdoc 233: gem_doc_dir = File.join Gem.dir, 'doc' 234: rubygems_name = "rubygems-#{Gem::VERSION}" 235: rubygems_doc_dir = File.join gem_doc_dir, rubygems_name 236: 237: if File.writable? gem_doc_dir and 238: (not File.exist? rubygems_doc_dir or 239: File.writable? rubygems_doc_dir) then 240: say "Removing old RubyGems RDoc and ri" if @verbose 241: Dir[File.join(Gem.dir, 'doc', 'rubygems-[0-9]*')].each do |dir| 242: rm_rf dir 243: end 244: 245: if options[:ri] then 246: ri_dir = File.join rubygems_doc_dir, 'ri' 247: say "Installing #{rubygems_name} ri into #{ri_dir}" if @verbose 248: run_rdoc '--ri', '--op', ri_dir 249: end 250: 251: if options[:rdoc] then 252: rdoc_dir = File.join rubygems_doc_dir, 'rdoc' 253: say "Installing #{rubygems_name} rdoc into #{rdoc_dir}" if @verbose 254: run_rdoc '--op', rdoc_dir 255: end 256: elsif @verbose then 257: say "Skipping RDoc generation, #{gem_doc_dir} not writable" 258: say "Set the GEM_HOME environment variable if you want RDoc generated" 259: end 260: end
# File lib/rubygems/commands/setup_command.rb, line 262 262: def make_destination_dirs(install_destdir) 263: lib_dir = nil 264: bin_dir = nil 265: 266: prefix = options[:prefix] 267: site_or_vendor = options[:site_or_vendor] 268: 269: if prefix.empty? then 270: lib_dir = Gem::ConfigMap[site_or_vendor] 271: bin_dir = Gem::ConfigMap[:bindir] 272: else 273: # Apple installed RubyGems into libdir, and RubyGems <= 1.1.0 gets 274: # confused about installation location, so switch back to 275: # sitelibdir/vendorlibdir. 276: if defined?(APPLE_GEM_HOME) and 277: # just in case Apple and RubyGems don't get this patched up proper. 278: (prefix == Gem::ConfigMap[:libdir] or 279: # this one is important 280: prefix == File.join(Gem::ConfigMap[:libdir], 'ruby')) then 281: lib_dir = Gem::ConfigMap[site_or_vendor] 282: bin_dir = Gem::ConfigMap[:bindir] 283: else 284: lib_dir = File.join prefix, 'lib' 285: bin_dir = File.join prefix, 'bin' 286: end 287: end 288: 289: unless install_destdir.empty? then 290: lib_dir = File.join install_destdir, lib_dir.gsub(/^[a-zA-Z]:/, '') 291: bin_dir = File.join install_destdir, bin_dir.gsub(/^[a-zA-Z]:/, '') 292: end 293: 294: mkdir_p lib_dir 295: mkdir_p bin_dir 296: 297: return lib_dir, bin_dir 298: end
# File lib/rubygems/commands/setup_command.rb, line 300 300: def remove_old_bin_files(bin_dir) 301: old_bin_files = { 302: 'gem_mirror' => 'gem mirror', 303: 'gem_server' => 'gem server', 304: 'gemlock' => 'gem lock', 305: 'gemri' => 'ri', 306: 'gemwhich' => 'gem which', 307: 'index_gem_repository.rb' => 'gem generate_index', 308: } 309: 310: old_bin_files.each do |old_bin_file, new_name| 311: old_bin_path = File.join bin_dir, old_bin_file 312: next unless File.exist? old_bin_path 313: 314: deprecation_message = "`#{old_bin_file}` has been deprecated. Use `#{new_name}` instead." 315: 316: File.open old_bin_path, 'w' do |fp| 317: fp.write #!#{Gem.ruby}abort "#{deprecation_message}" 318: end 319: 320: next unless Gem.win_platform? 321: 322: File.open "#{old_bin_path}.bat", 'w' do |fp| 323: fp.puts %{@ECHO.#{deprecation_message}} 324: end 325: end 326: end
# File lib/rubygems/commands/setup_command.rb, line 332 332: def remove_source_caches(install_destdir) 333: if install_destdir.empty? 334: require 'rubygems/source_info_cache' 335: 336: user_cache_file = File.join(install_destdir, 337: Gem::SourceInfoCache.user_cache_file) 338: system_cache_file = File.join(install_destdir, 339: Gem::SourceInfoCache.system_cache_file) 340: 341: say "Removing old source_cache files" if Gem.configuration.really_verbose 342: rm_f user_cache_file if File.writable? File.dirname(user_cache_file) 343: rm_f system_cache_file if File.writable? File.dirname(system_cache_file) 344: end 345: end
# File lib/rubygems/commands/setup_command.rb, line 347 347: def run_rdoc(*args) 348: begin 349: gem 'rdoc' 350: rescue Gem::LoadError 351: end 352: 353: require 'rdoc/rdoc' 354: 355: args << '--quiet' 356: args << '--main' << 'README' 357: args << '.' << 'README' << 'LICENSE.txt' << 'GPL.txt' 358: 359: r = RDoc::RDoc.new 360: r.document args 361: end
# File lib/rubygems/commands/setup_command.rb, line 363 363: def uninstall_old_gemcutter 364: require 'rubygems/uninstaller' 365: 366: ui = Gem::Uninstaller.new('gemcutter', :all => true, :ignore => true, 367: :version => '< 0.4') 368: ui.uninstall 369: rescue Gem::InstallError 370: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.