diff options
Diffstat (limited to 'lib/rubygems/commands/setup_command.rb')
-rw-r--r-- | lib/rubygems/commands/setup_command.rb | 193 |
1 files changed, 124 insertions, 69 deletions
diff --git a/lib/rubygems/commands/setup_command.rb b/lib/rubygems/commands/setup_command.rb index 2c29786224..f322ca9df5 100644 --- a/lib/rubygems/commands/setup_command.rb +++ b/lib/rubygems/commands/setup_command.rb @@ -15,10 +15,11 @@ class Gem::Commands::SetupCommand < Gem::Command super 'setup', 'Install RubyGems', :format_executable => true, :document => %w[ri], :site_or_vendor => 'sitelibdir', - :destdir => '', :prefix => '', :previous_version => '' + :destdir => '', :prefix => '', :previous_version => '', + :regenerate_binstubs => true add_option '--previous-version=VERSION', - 'Previous version of rubygems', + 'Previous version of RubyGems', 'Used for changelog processing' do |version, options| options[:previous_version] = version end @@ -42,7 +43,7 @@ class Gem::Commands::SetupCommand < Gem::Command add_option '--[no-]format-executable', 'Makes `gem` match ruby', - 'If ruby is ruby18, gem will be gem18' do |value, options| + 'If Ruby is ruby18, gem will be gem18' do |value, options| options[:format_executable] = value end @@ -79,6 +80,15 @@ class Gem::Commands::SetupCommand < Gem::Command options[:document].uniq! end + add_option '--[no-]regenerate-binstubs', + 'Regenerate gem binstubs' do |value, options| + if value then + options[:regenerate_binstubs] = true + else + options.delete(:regenerate_binstubs) + end + end + @verbose = nil end @@ -92,7 +102,7 @@ class Gem::Commands::SetupCommand < Gem::Command end def defaults_str # :nodoc: - "--format-executable --document ri" + "--format-executable --document ri --regenerate-binstubs" end def description # :nodoc: @@ -142,8 +152,12 @@ By default, this RubyGems will install gem as: remove_old_lib_files lib_dir + install_default_bundler_gem + say "RubyGems #{Gem::VERSION} installed" + regenerate_binstubs + uninstall_old_gemcutter documentation_success = install_rdoc @@ -190,7 +204,7 @@ By default, this RubyGems will install gem as: if options[:document].include? 'ri' then say "Ruby Interactive (ri) documentation was installed. ri is kind of like man " - say "pages for ruby libraries. You may access it like this:" + say "pages for Ruby libraries. You may access it like this:" say " ri Classname" say " ri Classname.class_method" say " ri Classname#instance_method" @@ -202,59 +216,64 @@ By default, this RubyGems will install gem as: end end - def install_executables(bin_dir) - say "Installing gem executable" if @verbose + def install_executables(bin_dir) @bin_file_names = [] - Dir.chdir 'bin' do - bin_files = Dir['*'] + executables = { 'gem' => 'bin' } + executables['bundler'] = 'bundler/exe' if Gem::USE_BUNDLER_FOR_GEMDEPS + executables.each do |tool, path| + say "Installing #{tool} executable" if @verbose - bin_files.delete 'update_rubygems' + Dir.chdir path do + bin_files = Dir['*'] - bin_files.each do |bin_file| - bin_file_formatted = if options[:format_executable] then - Gem.default_exec_format % bin_file - else - bin_file - end + bin_files -= %w[update_rubygems bundler bundle_ruby] - dest_file = File.join bin_dir, bin_file_formatted - bin_tmp_file = File.join Dir.tmpdir, "#{bin_file}.#{$$}" + bin_files.each do |bin_file| + bin_file_formatted = if options[:format_executable] then + Gem.default_exec_format % bin_file + else + bin_file + end - begin - bin = File.readlines bin_file - bin[0] = "#!#{Gem.ruby}\n" + dest_file = File.join bin_dir, bin_file_formatted + bin_tmp_file = File.join Dir.tmpdir, "#{bin_file}.#{$$}" - File.open bin_tmp_file, 'w' do |fp| - fp.puts bin.join - end - - install bin_tmp_file, dest_file, :mode => 0755 - @bin_file_names << dest_file - ensure - rm bin_tmp_file - end - - next unless Gem.win_platform? + begin + bin = File.readlines bin_file + bin[0] = "#!#{Gem.ruby}\n" - begin - bin_cmd_file = File.join Dir.tmpdir, "#{bin_file}.bat" + File.open bin_tmp_file, 'w' do |fp| + fp.puts bin.join + end - File.open bin_cmd_file, 'w' do |file| - file.puts <<-TEXT -@ECHO OFF -IF NOT "%~f0" == "~f0" GOTO :WinNT -@"#{File.basename(Gem.ruby).chomp('"')}" "#{dest_file}" %1 %2 %3 %4 %5 %6 %7 %8 %9 -GOTO :EOF -:WinNT -@"#{File.basename(Gem.ruby).chomp('"')}" "%~dpn0" %* -TEXT + install bin_tmp_file, dest_file, :mode => 0755 + @bin_file_names << dest_file + ensure + rm bin_tmp_file end - install bin_cmd_file, "#{dest_file}.bat", :mode => 0755 - ensure - rm bin_cmd_file + 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 + @"#{File.basename(Gem.ruby).chomp('"')}" "#{dest_file}" %1 %2 %3 %4 %5 %6 %7 %8 %9 + GOTO :EOF + :WinNT + @"#{File.basename(Gem.ruby).chomp('"')}" "%~dpn0" %* + TEXT + end + + install bin_cmd_file, "#{dest_file}.bat", :mode => 0755 + ensure + rm bin_cmd_file + end end end end @@ -269,18 +288,22 @@ TEXT end def install_lib(lib_dir) - say "Installing RubyGems" if @verbose + libs = { 'RubyGems' => 'lib' } + libs['Bundler'] = 'bundler/lib' if Gem::USE_BUNDLER_FOR_GEMDEPS + libs.each do |tool, path| + say "Installing #{tool}" if @verbose - lib_files = rb_files_in 'lib' - pem_files = pem_files_in 'lib' + lib_files = rb_files_in path + pem_files = pem_files_in path - Dir.chdir 'lib' do - lib_files.each do |lib_file| - install_file lib_file, lib_dir - end + Dir.chdir path do + lib_files.each do |lib_file| + install_file lib_file, lib_dir + end - pem_files.each do |pem_file| - install_file pem_file, lib_dir + pem_files.each do |pem_file| + install_file pem_file, lib_dir + end end end end @@ -326,6 +349,29 @@ TEXT return false end + def install_default_bundler_gem + return unless Gem::USE_BUNDLER_FOR_GEMDEPS + + bundler_spec = Gem::Specification.load("bundler/bundler.gemspec") + bundler_spec.files = Dir["bundler/{*.md,{lib,exe,man}/**/*}"] + bundler_spec.executables -= %w[bundler bundle_ruby] + Dir.entries(Gem::Specification.default_specifications_dir). + select {|gs| gs.start_with?("bundler-") }. + each {|gs| File.delete(File.join(Gem::Specification.default_specifications_dir, gs)) } + + default_spec_path = File.join(Gem::Specification.default_specifications_dir, "#{bundler_spec.full_name}.gemspec") + Gem.write_binary(default_spec_path, bundler_spec.to_ruby) + + bundler_spec = Gem::Specification.load(default_spec_path) + + Dir.entries(bundler_spec.gems_dir). + select {|default_gem| default_gem.start_with?("bundler-") }. + each {|default_gem| rm_r File.join(bundler_spec.gems_dir, default_gem) } + + mkdir_p bundler_spec.bin_dir + bundler_spec.executables.each {|e| cp File.join("bundler", bundler_spec.bindir, e), File.join(bundler_spec.bin_dir, e) } + end + def make_destination_dirs(install_destdir) lib_dir, bin_dir = Gem.default_rubygems_dirs @@ -397,7 +443,7 @@ TEXT 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." + deprecation_message = "`#{old_bin_file}` has been deprecated. Use `#{new_name}` instead." File.open old_bin_path, 'w' do |fp| fp.write <<-EOF @@ -416,23 +462,26 @@ abort "#{deprecation_message}" end def remove_old_lib_files lib_dir - rubygems_dir = File.join lib_dir, 'rubygems' - lib_files = rb_files_in 'lib/rubygems' + lib_dirs = { File.join(lib_dir, 'rubygems') => 'lib/rubygems' } + lib_dirs[File.join(lib_dir, 'bundler')] = 'bundler/lib/bundler' if Gem::USE_BUNDLER_FOR_GEMDEPS + lib_dirs.each do |old_lib_dir, new_lib_dir| + lib_files = rb_files_in(new_lib_dir) - old_lib_files = rb_files_in rubygems_dir + old_lib_files = rb_files_in(old_lib_dir) - to_remove = old_lib_files - lib_files + to_remove = old_lib_files - lib_files - to_remove.delete_if do |file| - file.start_with? 'defaults' - end + to_remove.delete_if do |file| + file.start_with? 'defaults' + end - Dir.chdir rubygems_dir do - to_remove.each do |file| - FileUtils.rm_f file + Dir.chdir old_lib_dir do + to_remove.each do |file| + FileUtils.rm_f file - warn "unable to remove old file #{file} please remove it by hand" if - File.exist? file + warn "unable to remove old file #{file} please remove it by hand" if + File.exist? file + end end end end @@ -480,5 +529,11 @@ abort "#{deprecation_message}" rescue Gem::InstallError end -end + def regenerate_binstubs + require "rubygems/commands/pristine_command" + say "Regenerating binstubs" + command = Gem::Commands::PristineCommand.new + command.invoke(*%w[--all --only-executables --silent]) + end +end |