Skip to content

Commit

Permalink
Merge rubygems master from upstream.
Browse files Browse the repository at this point in the history
  I picked the commit from 3c469e0da538428a0ddd94f99aa73c32da22e8ba
  • Loading branch information
hsbt committed Jun 1, 2019
1 parent 560cd5b commit 56660de
Show file tree
Hide file tree
Showing 55 changed files with 1,024 additions and 1,026 deletions.
24 changes: 23 additions & 1 deletion lib/rubygems.rb
Original file line number Diff line number Diff line change
Expand Up @@ -670,6 +670,21 @@ def self.load_path_insert_index
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

##
Expand Down Expand Up @@ -1083,6 +1098,13 @@ def self.win_platform?
@@win_platform
end

##
# Is this a java platform?

def self.java_platform?
RUBY_PLATFORM == "java"
end

##
# Load +plugins+ as Ruby files

Expand Down Expand Up @@ -1243,7 +1265,7 @@ class << self
#

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("|")
Expand Down
2 changes: 1 addition & 1 deletion lib/rubygems/commands/pristine_command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def execute
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,
Expand Down
170 changes: 92 additions & 78 deletions lib/rubygems/commands/query_command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,46 +78,58 @@ def description # :nodoc:
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?
Expand All @@ -128,56 +140,57 @@ def display_header(type)
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

Expand Down Expand Up @@ -235,7 +248,7 @@ def entry_details(entry, detail_tuple, specs, platforms)

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"

Expand Down Expand Up @@ -285,8 +298,8 @@ def make_entry(entry_tuples, platforms)

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
Expand Down Expand Up @@ -337,12 +350,13 @@ def spec_platforms(entry, platforms)

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
Expand Down
2 changes: 1 addition & 1 deletion lib/rubygems/commands/setup_command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ def install_default_bundler_gem(bin_dir)
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], format_executable: options[:format_executable], install_as_default: true, bin_dir: bin_dir, wrappers: true)
installer.install
ensure
FileUtils.rm_f built_gem
Expand Down
4 changes: 1 addition & 3 deletions lib/rubygems/commands/update_command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -254,9 +254,7 @@ def update_rubygems
def update_rubygems_arguments # :nodoc:
args = []
args << '--prefix' << Gem.prefix if Gem.prefix
# TODO use --document for >= 1.9 , --no-rdoc --no-ri < 1.9
args << '--no-rdoc' unless options[:document].include? 'rdoc'
args << '--no-ri' unless options[:document].include? 'ri'
args << '--no-document' unless options[:document].include?('rdoc') || options[:document].include?('ri')
args << '--no-format-executable' if options[:no_format_executable]
args << '--previous-version' << Gem::VERSION if
options[:system] == true or
Expand Down
3 changes: 0 additions & 3 deletions lib/rubygems/core_ext/kernel_gem.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@

module Kernel

# REFACTOR: This should be pulled out into some kind of hacks file.
remove_method :gem if 'method' == defined? gem # from gem_prelude.rb on 1.9

##
# Use Kernel#gem to activate a specific version of +gem_name+.
#
Expand Down
7 changes: 0 additions & 7 deletions lib/rubygems/defaults.rb
Original file line number Diff line number Diff line change
Expand Up @@ -147,13 +147,6 @@ def self.default_cert_path
File.join Gem.user_home, ".gem", "gem-public_cert.pem"
end

##
# Whether to expect full paths in default gems - true for non-MRI
# ruby implementations
def self.default_gems_use_full_paths?
ruby_engine != 'ruby'
end

##
# Install extensions into lib as well as into the extension directory.

Expand Down
2 changes: 1 addition & 1 deletion lib/rubygems/ext/rake_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def self.build(extension, dest_path, results, args=[], lib_dir=nil)
rake = rake.shellsplit
else
begin
rake = [Gem.ruby, "-rrubygems", Gem.bin_path('rake', 'rake')]
rake = [Gem.ruby, "-I#{File.expand_path("..", __dir__)}", "-rrubygems", Gem.bin_path('rake', 'rake')]
rescue Gem::Exception
rake = [Gem.default_exec_format % 'rake']
end
Expand Down
Loading

0 comments on commit 56660de

Please sign in to comment.