ruby-changes:55947
From: Hiroshi <ko1@a...>
Date: Sat, 1 Jun 2019 19:51:12 +0900 (JST)
Subject: [ruby-changes:55947] Hiroshi SHIBATA: 56660de3c6 (trunk): Merge rubygems master from upstream.
https://git.ruby-lang.org/ruby.git/commit/?id=56660de3c6 From 56660de3c6df7a4ff8667ef4047d30d0de169935 Mon Sep 17 00:00:00 2001 From: Hiroshi SHIBATA <hsbt@r...> Date: Sat, 1 Jun 2019 12:45:11 +0300 Subject: Merge rubygems master from upstream. I picked the commit from 3c469e0da538428a0ddd94f99aa73c32da22e8ba diff --git a/lib/rubygems.rb b/lib/rubygems.rb index 193e8d3..c013e4b 100644 --- a/lib/rubygems.rb +++ b/lib/rubygems.rb @@ -670,6 +670,21 @@ An Array (#{env.inspect}) was passed in from #{caller[3]} https://github.com/ruby/ruby/blob/trunk/lib/rubygems.rb#L670 index end + ## + # Add a list of paths to the $LOAD_PATH at the proper place. + + def self.add_to_load_path(*paths) + insert_index = load_path_insert_index + + if insert_index + # gem directories must come after -I and ENV['RUBYLIB'] + $LOAD_PATH.insert(insert_index, *paths) + else + # we are probably testing in core, -I and RUBYLIB don't apply + $LOAD_PATH.unshift(*paths) + end + end + @yaml_loaded = false ## @@ -1084,6 +1099,13 @@ An Array (#{env.inspect}) was passed in from #{caller[3]} https://github.com/ruby/ruby/blob/trunk/lib/rubygems.rb#L1099 end ## + # Is this a java platform? + + def self.java_platform? + RUBY_PLATFORM == "java" + end + + ## # Load +plugins+ as Ruby files def self.load_plugin_files(plugins) # :nodoc: @@ -1243,7 +1265,7 @@ An Array (#{env.inspect}) was passed in from #{caller[3]} https://github.com/ruby/ruby/blob/trunk/lib/rubygems.rb#L1265 # def register_default_spec(spec) - new_format = Gem.default_gems_use_full_paths? || spec.require_paths.any? {|path| spec.files.any? {|f| f.start_with? path } } + new_format = spec.require_paths.any? {|path| spec.files.any? {|f| f.start_with? path } } if new_format prefix_group = spec.require_paths.map {|f| f + "/"}.join("|") diff --git a/lib/rubygems/commands/pristine_command.rb b/lib/rubygems/commands/pristine_command.rb index a25b690..e4628bd 100644 --- a/lib/rubygems/commands/pristine_command.rb +++ b/lib/rubygems/commands/pristine_command.rb @@ -104,7 +104,7 @@ extensions will be restored. https://github.com/ruby/ruby/blob/trunk/lib/rubygems/commands/pristine_command.rb#L104 end.flatten end - specs = specs.select{|spec| RUBY_ENGINE == spec.platform || Gem::Platform.local === spec.platform } + specs = specs.select{|spec| RUBY_ENGINE == spec.platform || Gem::Platform.local === spec.platform || spec.platform == Gem::Platform::RUBY } if specs.to_a.empty? raise Gem::Exception, diff --git a/lib/rubygems/commands/query_command.rb b/lib/rubygems/commands/query_command.rb index 5a42d45..4fb23bc 100644 --- a/lib/rubygems/commands/query_command.rb +++ b/lib/rubygems/commands/query_command.rb @@ -78,46 +78,58 @@ is too hard to use. https://github.com/ruby/ruby/blob/trunk/lib/rubygems/commands/query_command.rb#L78 end def execute + gem_names = Array(options[:name]) + + if !args.empty? + gem_names = options[:exact] ? args.map{|arg| /\A#{Regexp.escape(arg)}\Z/ } : args.map{|arg| /#{arg}/i } + end + + terminate_interaction(check_installed_gems(gem_names)) if check_installed_gems? + + gem_names.each { |n| show_gems(n) } + end + + private + + def check_installed_gems(gem_names) exit_code = 0 - if options[:args].to_a.empty? and options[:name].source.empty? - name = options[:name] - no_name = true - elsif !options[:name].source.empty? - name = Array(options[:name]) + + if args.empty? && !gem_name? + alert_error "You must specify a gem name" + exit_code = 4 + elsif gem_names.count > 1 + alert_error "You must specify only ONE gem!" + exit_code = 4 else - args = options[:args].to_a - name = options[:exact] ? args.map{|arg| /\A#{Regexp.escape(arg)}\Z/ } : args.map{|arg| /#{arg}/i } + installed = installed?(gem_names.first, options[:version]) + installed = !installed unless options[:installed] + + say(installed) + exit_code = 1 if !installed end - prerelease = options[:prerelease] + exit_code + end - unless options[:installed].nil? - if no_name - alert_error "You must specify a gem name" - exit_code |= 4 - elsif name.count > 1 - alert_error "You must specify only ONE gem!" - exit_code |= 4 - else - installed = installed? name.first, options[:version] - installed = !installed unless options[:installed] + def check_installed_gems? + !options[:installed].nil? + end - if installed - say "true" - else - say "false" - exit_code |= 1 - end - end + def gem_name? + !options[:name].source.empty? + end - terminate_interaction exit_code - end + def prerelease + options[:prerelease] + end - names = Array(name) - names.each { |n| show_gems n, prerelease } + def show_prereleases? + prerelease.nil? || prerelease end - private + def args + options[:args].to_a + end def display_header(type) if (ui.outs.tty? and Gem.configuration.verbose) or both? @@ -128,56 +140,57 @@ is too hard to use. https://github.com/ruby/ruby/blob/trunk/lib/rubygems/commands/query_command.rb#L140 end #Guts of original execute - def show_gems(name, prerelease) - req = Gem::Requirement.default - # TODO: deprecate for real + def show_gems(name) + show_local_gems(name) if local? + show_remote_gems(name) if remote? + end + + def show_local_gems(name, req = Gem::Requirement.default) + display_header("LOCAL") + + specs = Gem::Specification.find_all do |s| + s.name =~ name and req =~ s.version + end + dep = Gem::Deprecate.skip_during { Gem::Dependency.new name, req } - dep.prerelease = prerelease + specs.select! do |s| + dep.match?(s.name, s.version, show_prereleases?) + end - if local? - if prerelease and not both? - alert_warning "prereleases are always shown locally" - end + spec_tuples = specs.map do |spec| + [spec.name_tuple, spec] + end + + output_query_results(spec_tuples) + end - display_header 'LOCAL' + def show_remote_gems(name) + display_header("REMOTE") - specs = Gem::Specification.find_all do |s| - s.name =~ name and req =~ s.version - end + fetcher = Gem::SpecFetcher.fetcher - spec_tuples = specs.map do |spec| - [spec.name_tuple, spec] - end + spec_tuples = if name.respond_to?(:source) && name.source.empty? + fetcher.detect(specs_type) { true } + else + fetcher.detect(specs_type) do |name_tuple| + name === name_tuple.name + end + end - output_query_results spec_tuples - end + output_query_results(spec_tuples) + end - if remote? - display_header 'REMOTE' - - fetcher = Gem::SpecFetcher.fetcher - - type = if options[:all] - if options[:prerelease] - :complete - else - :released - end - elsif options[:prerelease] - :prerelease - else - :latest - end - - if name.respond_to?(:source) && name.source.empty? - spec_tuples = fetcher.detect(type) { true } + def specs_type + if options[:all] + if options[:prerelease] + :complete else - spec_tuples = fetcher.detect(type) do |name_tuple| - name === name_tuple.name - end + :released end - - output_query_results spec_tuples + elsif options[:prerelease] + :prerelease + else + :latest end end @@ -235,7 +248,7 @@ is too hard to use. https://github.com/ruby/ruby/blob/trunk/lib/rubygems/commands/query_command.rb#L248 name_tuple, spec = detail_tuple - spec = spec.fetch_spec name_tuple if spec.respond_to? :fetch_spec + spec = spec.fetch_spec(name_tuple)if spec.respond_to?(:fetch_spec) entry << "\n" @@ -285,8 +298,8 @@ is too hard to use. https://github.com/ruby/ruby/blob/trunk/lib/rubygems/commands/query_command.rb#L298 entry = [name_tuples.first.name] - entry_versions entry, name_tuples, platforms, specs - entry_details entry, detail_tuple, specs, platforms + entry_versions(entry, name_tuples, platforms, specs) + entry_details(entry, detail_tuple, specs, platforms) entry.join end @@ -337,12 +350,13 @@ is too hard to use. https://github.com/ruby/ruby/blob/trunk/lib/rubygems/commands/query_command.rb#L350 if platforms.length == 1 title = platforms.values.length == 1 ? 'Platform' : 'Platforms' - entry << " #{title}: #{platforms.values.sort.join ', '}\n" + entry << " #{title}: #{platforms.values.sort.join(', ')}\n" else entry << " Platforms:\n" - platforms.sort_by do |version,| - version - end.each do |version, pls| + + sorted_platforms = platforms.sort_by { |version,| version } + + sorted_platforms.each do |version, pls| label = " #{version}: " data = format_text pls.sort.join(', '), 68, label.length data[0, label.length] = label diff --git a/lib/rubygems/commands/setup_command.rb b/lib/rubygems/commands/setup_command.rb index f5e5236..1754630 100644 --- a/lib/rubygems/commands/setup_command.rb +++ b/lib/rubygems/commands/setup_command.rb @@ -429,7 +429,7 @@ By default, this RubyGems will install gem as: https://github.com/ruby/ruby/blob/trunk/lib/rubygems/commands/setup_command.rb#L429 Dir.chdir("bundler") do built_gem = Gem::Package.build(bundler_spec) begin - installer = Gem::Installer.at(built_gem, env_shebang: options[:env_shebang], install_as_default: true, bin_dir: bin_dir, wrappers: true) + installer = Gem::Installer.at(built_gem, env_shebang: options[:env_shebang], forma (... truncated) -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/