diff options
author | hsbt <hsbt@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-05-30 13:01:35 +0000 |
---|---|---|
committer | hsbt <hsbt@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-05-30 13:01:35 +0000 |
commit | 8da8d4b043c37b53a69803c71ff36b478d4776d0 (patch) | |
tree | 7c8cec15645e74f19c88e4eb5b210b96174c7d03 /lib/rubygems/commands | |
parent | c5cb386eba6d9a2d9a8e6ffa8c30137d0c4660c1 (diff) | |
download | ruby-8da8d4b043c37b53a69803c71ff36b478d4776d0.tar.gz |
Merge RubyGems 3.0.0.beta1.
* It drop to support < Ruby 2.2
* Cleanup deprecated methods and classes.
* Mark obsoleted methods to deprecate.
* and other enhancements.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63528 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/rubygems/commands')
-rw-r--r-- | lib/rubygems/commands/build_command.rb | 14 | ||||
-rw-r--r-- | lib/rubygems/commands/environment_command.rb | 19 | ||||
-rw-r--r-- | lib/rubygems/commands/info_command.rb | 33 | ||||
-rw-r--r-- | lib/rubygems/commands/install_command.rb | 17 | ||||
-rw-r--r-- | lib/rubygems/commands/pristine_command.rb | 11 | ||||
-rw-r--r-- | lib/rubygems/commands/setup_command.rb | 68 | ||||
-rw-r--r-- | lib/rubygems/commands/uninstall_command.rb | 33 | ||||
-rw-r--r-- | lib/rubygems/commands/unpack_command.rb | 12 | ||||
-rw-r--r-- | lib/rubygems/commands/update_command.rb | 15 |
9 files changed, 176 insertions, 46 deletions
diff --git a/lib/rubygems/commands/build_command.rb b/lib/rubygems/commands/build_command.rb index 38c45e46f0..0ba24e5ea3 100644 --- a/lib/rubygems/commands/build_command.rb +++ b/lib/rubygems/commands/build_command.rb @@ -47,13 +47,15 @@ with gem spec: end if File.exist? gemspec then - spec = Gem::Specification.load gemspec + Dir.chdir(File.dirname(gemspec)) do + spec = Gem::Specification.load File.basename(gemspec) - if spec then - Gem::Package.build spec, options[:force] - else - alert_error "Error loading gemspec. Aborting." - terminate_interaction 1 + if spec then + Gem::Package.build spec, options[:force] + else + alert_error "Error loading gemspec. Aborting." + terminate_interaction 1 + end end else alert_error "Gemspec file not found: #{gemspec}" diff --git a/lib/rubygems/commands/environment_command.rb b/lib/rubygems/commands/environment_command.rb index e825c761ad..29c9d4d38f 100644 --- a/lib/rubygems/commands/environment_command.rb +++ b/lib/rubygems/commands/environment_command.rb @@ -120,6 +120,8 @@ lib/rubygems/defaults/operating_system.rb out << " - RUBY EXECUTABLE: #{Gem.ruby}\n" + out << " - GIT EXECUTABLE: #{git_path}\n" + out << " - EXECUTABLE DIRECTORY: #{Gem.bindir}\n" out << " - SPEC CACHE DIRECTORY: #{Gem.spec_cache_dir}\n" @@ -157,4 +159,21 @@ lib/rubygems/defaults/operating_system.rb out end + private + + ## + # Git binary path + + def git_path + exts = ENV["PATHEXT"] ? ENV["PATHEXT"].split(";") : [""] + ENV["PATH"].split(File::PATH_SEPARATOR).each do |path| + exts.each do |ext| + exe = File.join(path, "git#{ext}") + return exe if File.executable?(exe) && !File.directory?(exe) + end + end + + return nil + end + end diff --git a/lib/rubygems/commands/info_command.rb b/lib/rubygems/commands/info_command.rb new file mode 100644 index 0000000000..8d9611a957 --- /dev/null +++ b/lib/rubygems/commands/info_command.rb @@ -0,0 +1,33 @@ +# frozen_string_literal: true + +require 'rubygems/command' +require 'rubygems/commands/query_command' + +class Gem::Commands::InfoCommand < Gem::Commands::QueryCommand + def initialize + super "info", "Show information for the given gem" + + remove_option('--name-matches') + remove_option('-d') + + defaults[:details] = true + defaults[:exact] = true + end + + def description # :nodoc: + "Info prints information about the gem such as name,"\ + " description, website, license and installed paths" + end + + def usage # :nodoc: + "#{program_name} GEMNAME" + end + + def arguments # :nodoc: + "GEMNAME name of the gem to print information about" + end + + def defaults_str + "--local" + end +end diff --git a/lib/rubygems/commands/install_command.rb b/lib/rubygems/commands/install_command.rb index 3a7d50517f..c6abf9cd7c 100644 --- a/lib/rubygems/commands/install_command.rb +++ b/lib/rubygems/commands/install_command.rb @@ -134,7 +134,8 @@ to write the specification by hand. For example: def check_version # :nodoc: if options[:version] != Gem::Requirement.default and get_all_gem_names.size > 1 then - alert_error "Can't use --version w/ multiple gems. Use name:ver instead." + alert_error "Can't use --version with multiple gems. You can specify multiple gems with" \ + " version requirments using `gem install 'my_gem:1.0.0' 'my_other_gem:~>2.0.0'`" terminate_interaction 1 end end @@ -148,7 +149,7 @@ to write the specification by hand. For example: @installed_specs = [] - ENV.delete 'GEM_PATH' if options[:install_dir].nil? and RUBY_VERSION > '1.9' + ENV.delete 'GEM_PATH' if options[:install_dir].nil? check_install_dir check_version @@ -250,18 +251,23 @@ to write the specification by hand. For example: get_all_gem_names_and_versions.each do |gem_name, gem_version| gem_version ||= options[:version] + domain = options[:domain] + domain = :local unless options[:suggest_alternate] begin install_gem gem_name, gem_version rescue Gem::InstallError => e alert_error "Error installing #{gem_name}:\n\t#{e.message}" exit_code |= 1 - rescue Gem::GemNotFoundException, Gem::UnsatisfiableDependencyError => e - domain = options[:domain] - domain = :local unless options[:suggest_alternate] + rescue Gem::GemNotFoundException => e show_lookup_failure e.name, e.version, e.errors, domain exit_code |= 2 + rescue Gem::UnsatisfiableDependencyError => e + show_lookup_failure e.name, e.version, e.errors, domain, + "'#{gem_name}' (#{gem_version})" + + exit_code |= 2 end end @@ -300,4 +306,3 @@ to write the specification by hand. For example: end end - diff --git a/lib/rubygems/commands/pristine_command.rb b/lib/rubygems/commands/pristine_command.rb index fafe35bec1..817e752266 100644 --- a/lib/rubygems/commands/pristine_command.rb +++ b/lib/rubygems/commands/pristine_command.rb @@ -24,7 +24,8 @@ class Gem::Commands::PristineCommand < Gem::Command add_option('--skip=gem_name', 'used on --all, skip if name == gem_name') do |value, options| - options[:skip] = value + options[:skip] ||= [] + options[:skip] << value end add_option('--[no-]extensions', @@ -115,9 +116,11 @@ extensions will be restored. next end - if spec.name == options[:skip] - say "Skipped #{spec.full_name}, it was given through options" - next + if options.has_key? :skip + if options[:skip].include? spec.name + say "Skipped #{spec.full_name}, it was given through options" + next + end end if spec.bundled_gem_in_old_ruby? diff --git a/lib/rubygems/commands/setup_command.rb b/lib/rubygems/commands/setup_command.rb index b6690c9d54..fc87063fe3 100644 --- a/lib/rubygems/commands/setup_command.rb +++ b/lib/rubygems/commands/setup_command.rb @@ -6,8 +6,10 @@ require 'rubygems/command' # RubyGems checkout or tarball. class Gem::Commands::SetupCommand < Gem::Command - HISTORY_HEADER = /^===\s*[\d.]+\s*\/\s*\d{4}-\d{2}-\d{2}\s*$/ - VERSION_MATCHER = /^===\s*([\d.]+)\s*\/\s*\d{4}-\d{2}-\d{2}\s*$/ + HISTORY_HEADER = /^===\s*[\d.a-zA-Z]+\s*\/\s*\d{4}-\d{2}-\d{2}\s*$/ + VERSION_MATCHER = /^===\s*([\d.a-zA-Z]+)\s*\/\s*\d{4}-\d{2}-\d{2}\s*$/ + + ENV_PATHS = %w[/usr/bin/env /bin/env] def initialize require 'tmpdir' @@ -85,6 +87,12 @@ class Gem::Commands::SetupCommand < Gem::Command options[:regenerate_binstubs] = value end + add_option('-E', '--[no-]env-shebang', + 'Rewrite executables with a shebang', + 'of /usr/bin/env') do |value, options| + options[:env_shebang] = value + end + @verbose = nil end @@ -119,6 +127,13 @@ By default, this RubyGems will install gem as: EOF end + module MakeDirs + def mkdir_p(path, *opts) + super + (@mkdirs ||= []) << path + end + end + def execute @verbose = Gem.configuration.really_verbose @@ -137,6 +152,7 @@ By default, this RubyGems will install gem as: else extend FileUtils end + extend MakeDirs lib_dir, bin_dir = make_destination_dirs install_destdir @@ -150,6 +166,11 @@ By default, this RubyGems will install gem as: install_default_bundler_gem + if mode = options[:dir_mode] + @mkdirs.uniq! + File.chmod(mode, @mkdirs) + end + say "RubyGems #{Gem::VERSION} installed" regenerate_binstubs if options[:regenerate_binstubs] @@ -216,6 +237,8 @@ By default, this RubyGems will install gem as: def install_executables(bin_dir) @bin_file_names = [] + prog_mode = options[:prog_mode] || 0755 + executables = { 'gem' => 'bin' } executables['bundler'] = 'bundler/exe' if Gem::USE_BUNDLER_FOR_GEMDEPS executables.each do |tool, path| @@ -238,13 +261,13 @@ By default, this RubyGems will install gem as: begin bin = File.readlines bin_file - bin[0] = "#!#{Gem.ruby}\n" + bin[0] = shebang File.open bin_tmp_file, 'w' do |fp| fp.puts bin.join end - install bin_tmp_file, dest_file, :mode => 0755 + install bin_tmp_file, dest_file, :mode => prog_mode @bin_file_names << dest_file ensure rm bin_tmp_file @@ -266,7 +289,7 @@ By default, this RubyGems will install gem as: TEXT end - install bin_cmd_file, "#{dest_file}.bat", :mode => 0755 + install bin_cmd_file, "#{dest_file}.bat", :mode => prog_mode ensure rm bin_cmd_file end @@ -275,12 +298,24 @@ By default, this RubyGems will install gem as: end end + def shebang + if options[:env_shebang] + ruby_name = RbConfig::CONFIG['ruby_install_name'] + @env_path ||= ENV_PATHS.find {|env_path| File.executable? env_path } + "#!#{@env_path} #{ruby_name}\n" + else + "#!#{Gem.ruby}\n" + end + end + def install_file file, dest_dir dest_file = File.join dest_dir, file dest_dir = File.dirname dest_file - mkdir_p dest_dir unless File.directory? dest_dir + unless File.directory? dest_dir + mkdir_p dest_dir, :mode => 0700 + end - install file, dest_file, :mode => 0644 + install file, dest_file, :mode => options[:data_mode] || 0644 end def install_lib(lib_dir) @@ -352,7 +387,7 @@ By default, this RubyGems will install gem as: specs_dir = Gem::Specification.default_specifications_dir specs_dir = File.join(options[:destdir], specs_dir) unless Gem.win_platform? - mkdir_p specs_dir + mkdir_p specs_dir, :mode => 0700 # Workaround for non-git environment. gemspec = File.open('bundler/bundler.gemspec', 'rb'){|f| f.read.gsub(/`git ls-files -z`/, "''") } @@ -387,7 +422,7 @@ By default, this RubyGems will install gem as: bundler_bin_dir = bundler_spec.bin_dir bundler_bin_dir = File.join(options[:destdir], bundler_bin_dir) unless Gem.win_platform? - mkdir_p bundler_bin_dir + mkdir_p bundler_bin_dir, :mode => 0700 bundler_spec.executables.each do |e| cp File.join("bundler", bundler_spec.bindir, e), File.join(bundler_bin_dir, e) end @@ -411,8 +446,8 @@ By default, this RubyGems will install gem as: lib_dir, bin_dir = generate_default_dirs(install_destdir) end - mkdir_p lib_dir - mkdir_p bin_dir + mkdir_p lib_dir, :mode => 0700 + mkdir_p bin_dir, :mode => 0700 return lib_dir, bin_dir end @@ -543,8 +578,7 @@ abort "#{deprecation_message}" if File.exist? release_notes then history = File.read release_notes - history.force_encoding Encoding::UTF_8 if - Object.const_defined? :Encoding + history.force_encoding Encoding::UTF_8 history = history.sub(/^# coding:.*?(?=^=)/m, '') @@ -582,8 +616,14 @@ abort "#{deprecation_message}" def regenerate_binstubs require "rubygems/commands/pristine_command" say "Regenerating binstubs" + + args = %w[--all --only-executables --silent] + if options[:env_shebang] + args << "--env-shebang" + end + command = Gem::Commands::PristineCommand.new - command.invoke(*%w[--all --only-executables --silent]) + command.invoke(*args) end end diff --git a/lib/rubygems/commands/uninstall_command.rb b/lib/rubygems/commands/uninstall_command.rb index 20b3a7a1e4..55a052284a 100644 --- a/lib/rubygems/commands/uninstall_command.rb +++ b/lib/rubygems/commands/uninstall_command.rb @@ -129,11 +129,7 @@ that is a dependency of an existing gem. You can use the specs.each do |spec| options[:version] = spec.version - - begin - Gem::Uninstaller.new(spec.name, options).uninstall - rescue Gem::InstallError - end + uninstall_gem spec.name end alert "Uninstalled all gems in #{options[:install_dir]}" @@ -153,14 +149,27 @@ that is a dependency of an existing gem. You can use the deps = deplist.strongly_connected_components.flatten.reverse deps.map(&:name).uniq.each do |gem_name| - begin - Gem::Uninstaller.new(gem_name, options).uninstall - rescue Gem::GemNotInHomeException => e - spec = e.spec - alert("In order to remove #{spec.name}, please execute:\n" + - "\tgem uninstall #{spec.name} --install-dir=#{spec.installation_path}") - end + uninstall_gem(gem_name) end end + def uninstall_gem(gem_name) + uninstall(gem_name) + rescue Gem::InstallError + nil + rescue Gem::GemNotInHomeException => e + spec = e.spec + alert("In order to remove #{spec.name}, please execute:\n" + + "\tgem uninstall #{spec.name} --install-dir=#{spec.installation_path}") + rescue Gem::UninstallError => e + spec = e.spec + alert_error("Error: unable to successfully uninstall '#{spec.name}' which is " + + "located at '#{spec.full_gem_path}'. This is most likely because" + + "the current user does not have the appropriate permissions") + terminate_interaction 1 + end + + def uninstall(gem_name) + Gem::Uninstaller.new(gem_name, options).uninstall + end end diff --git a/lib/rubygems/commands/unpack_command.rb b/lib/rubygems/commands/unpack_command.rb index bdcfd524f1..b2edf7d349 100644 --- a/lib/rubygems/commands/unpack_command.rb +++ b/lib/rubygems/commands/unpack_command.rb @@ -94,7 +94,17 @@ command help for an example. spec_file = File.basename spec.spec_file - File.open spec_file, 'w' do |io| + FileUtils.mkdir_p @options[:target] if @options[:target] + + destination = begin + if @options[:target] + File.join @options[:target], spec_file + else + spec_file + end + end + + File.open destination, 'w' do |io| io.write metadata end else diff --git a/lib/rubygems/commands/update_command.rb b/lib/rubygems/commands/update_command.rb index 93ee60e1ab..1c86ba6753 100644 --- a/lib/rubygems/commands/update_command.rb +++ b/lib/rubygems/commands/update_command.rb @@ -85,18 +85,27 @@ command to remove old versions. end def execute - if options[:system] then update_rubygems return end - say "Updating installed gems" - hig = highest_installed_gems gems_to_update = which_to_update hig, options[:args].uniq + if options[:explain] + say "Gems to update:" + + gems_to_update.each do |(name, version)| + say " #{name}-#{version}" + end + + return + end + + say "Updating installed gems" + updated = update_gems gems_to_update updated_names = updated.map { |spec| spec.name } |