Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge RubyGems and Bundler master #5265

Merged
merged 2 commits into from Dec 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -32,13 +32,13 @@ def respond_to?(id, *args)

# rubocop:disable Style/MethodMissingSuper
# rubocop:disable Style/MissingRespondToMissing
if ::Gem.ruby_version >= ::Gem::Version.new("3.0.0")
if ::RUBY_VERSION >= "3.0.0"
def method_missing(name, *args, **kwargs, &block)
with do |connection|
connection.send(name, *args, **kwargs, &block)
end
end
elsif ::Gem.ruby_version >= ::Gem::Version.new("2.7.0")
elsif ::RUBY_VERSION >= "2.7.0"
ruby2_keywords def method_missing(name, *args, &block)
with do |connection|
connection.send(name, *args, &block)
Expand Down
43 changes: 23 additions & 20 deletions lib/rubygems.rb
Expand Up @@ -1293,7 +1293,12 @@ def already_loaded?(file)
end

def default_gem_load_paths
@default_gem_load_paths ||= $LOAD_PATH[load_path_insert_index..-1]
@default_gem_load_paths ||= $LOAD_PATH[load_path_insert_index..-1].map do |lp|
expanded = File.expand_path(lp)
next expanded unless File.exist?(expanded)

File.realpath(expanded)
end
end
end

Expand All @@ -1310,37 +1315,19 @@ def default_gem_load_paths
autoload :Licenses, File.expand_path('rubygems/util/licenses', __dir__)
autoload :NameTuple, File.expand_path('rubygems/name_tuple', __dir__)
autoload :PathSupport, File.expand_path('rubygems/path_support', __dir__)
autoload :Platform, File.expand_path('rubygems/platform', __dir__)
autoload :RequestSet, File.expand_path('rubygems/request_set', __dir__)
autoload :Requirement, File.expand_path('rubygems/requirement', __dir__)
autoload :Resolver, File.expand_path('rubygems/resolver', __dir__)
autoload :Source, File.expand_path('rubygems/source', __dir__)
autoload :SourceList, File.expand_path('rubygems/source_list', __dir__)
autoload :SpecFetcher, File.expand_path('rubygems/spec_fetcher', __dir__)
autoload :Specification, File.expand_path('rubygems/specification', __dir__)
autoload :Util, File.expand_path('rubygems/util', __dir__)
autoload :Version, File.expand_path('rubygems/version', __dir__)
end

require_relative 'rubygems/exceptions'
require_relative 'rubygems/specification'

# REFACTOR: This should be pulled out into some kind of hacks file.
begin
##
# Defaults the Ruby implementation wants to provide for RubyGems

require "rubygems/defaults/#{RUBY_ENGINE}"
rescue LoadError
end

##
# Loads the default specs.
Gem::Specification.load_defaults

require_relative 'rubygems/core_ext/kernel_gem'
require_relative 'rubygems/core_ext/kernel_require'
require_relative 'rubygems/core_ext/kernel_warn'

begin
##
# Defaults the operating system (or packager) wants to provide for RubyGems.
Expand All @@ -1356,3 +1343,19 @@ def default_gem_load_paths
"the problem and ask for help."
raise e.class, msg
end

begin
##
# Defaults the Ruby implementation wants to provide for RubyGems

require "rubygems/defaults/#{RUBY_ENGINE}"
rescue LoadError
end

##
# Loads the default specs.
Gem::Specification.load_defaults

require_relative 'rubygems/core_ext/kernel_gem'
require_relative 'rubygems/core_ext/kernel_require'
require_relative 'rubygems/core_ext/kernel_warn'
4 changes: 2 additions & 2 deletions lib/rubygems/commands/setup_command.rb
Expand Up @@ -12,8 +12,6 @@ class Gem::Commands::SetupCommand < Gem::Command
ENV_PATHS = %w[/usr/bin/env /bin/env].freeze

def initialize
require 'tmpdir'

super 'setup', 'Install RubyGems',
:format_executable => false, :document => %w[ri],
:force => true,
Expand Down Expand Up @@ -253,6 +251,8 @@ def install_executables(bin_dir)
Dir.chdir path do
bin_file = "gem"

require 'tmpdir'

dest_file = target_bin_path(bin_dir, bin_file)
bin_tmp_file = File.join Dir.tmpdir, "#{bin_file}.#{$$}"

Expand Down
2 changes: 1 addition & 1 deletion lib/rubygems/requirement.rb
@@ -1,5 +1,5 @@
# frozen_string_literal: true
require_relative "deprecate"
require_relative "version"

##
# A Requirement is a set of one or more version restrictions. It supports a
Expand Down
20 changes: 9 additions & 11 deletions lib/rubygems/specification.rb
Expand Up @@ -9,6 +9,8 @@
require_relative 'deprecate'
require_relative 'basic_specification'
require_relative 'stub_specification'
require_relative 'platform'
require_relative 'requirement'
require_relative 'specification_policy'
require_relative 'util/list'

Expand Down Expand Up @@ -179,18 +181,14 @@ class Gem::Specification < Gem::BasicSpecification
end

def self.clear_specs # :nodoc:
@@all_specs_mutex.synchronize do
@@all = nil
@@stubs = nil
@@stubs_by_name = {}
@@spec_with_requirable_file = {}
@@active_stub_with_requirable_file = {}
end
@@all = nil
@@stubs = nil
@@stubs_by_name = {}
@@spec_with_requirable_file = {}
@@active_stub_with_requirable_file = {}
end
private_class_method :clear_specs

@@all_specs_mutex = Thread::Mutex.new

clear_specs

# Sentinel object to represent "not found" stubs
Expand Down Expand Up @@ -758,7 +756,7 @@ def test_files=(files) # :nodoc:
attr_accessor :specification_version

def self._all # :nodoc:
@@all_specs_mutex.synchronize { @@all ||= Gem.loaded_specs.values | stubs.map(&:to_spec) }
@@all ||= Gem.loaded_specs.values | stubs.map(&:to_spec)
end

def self.clear_load_cache # :nodoc:
Expand Down Expand Up @@ -1086,7 +1084,7 @@ def self.from_yaml(input)
# +prerelease+ is true.

def self.latest_specs(prerelease = false)
_latest_specs Gem::Specification._all, prerelease
_latest_specs Gem::Specification.stubs, prerelease
end

##
Expand Down
7 changes: 0 additions & 7 deletions lib/rubygems/version.rb
Expand Up @@ -149,13 +149,6 @@
# For the last example, single-digit versions are automatically extended with
# a zero to give a sensible result.

# Our code style opens classes directly without opening the intermediate
# modules. This works because tha main entrypoint `rubygems.rb`, which defines
# the root `Gem` module, is usually required first. But in this case we want to
# allow using `Gem::Version` without loading the rest of rubygems, so we
# explicit define the `Gem` placeholder module first.
module Gem; end

require_relative "deprecate"

class Gem::Version
Expand Down
2 changes: 1 addition & 1 deletion spec/bundler/commands/clean_spec.rb
Expand Up @@ -638,7 +638,7 @@ def should_not_have_gems(*gems)
s.executables = "irb"
end

realworld_system_gems "fiddle --version 1.0.6", "tsort --version 0.1.0", "pathname --version 0.1.0", "set --version 1.0.1"
realworld_system_gems "fiddle --version 1.0.8", "tsort --version 0.1.0", "pathname --version 0.1.0", "set --version 1.0.1"

install_gemfile <<-G
source "#{file_uri_for(gem_repo2)}"
Expand Down
12 changes: 6 additions & 6 deletions spec/bundler/commands/exec_spec.rb
Expand Up @@ -614,20 +614,20 @@

it "loads the correct optparse when `auto_install` is set, and optparse is a dependency" do
if Gem.ruby_version >= Gem::Version.new("3.0.0") && Gem.rubygems_version < Gem::Version.new("3.3.0.a")
skip "optparse is a default gem, and rubygems loads install during install"
skip "optparse is a default gem, and rubygems loads it during install"
end

build_repo4 do
build_gem "fastlane", "2.192.0" do |s|
s.executables = "fastlane"
s.add_dependency "optparse", "~> 0.1.1"
s.add_dependency "optparse", "~> 999.999.999"
end

build_gem "optparse", "0.1.0"
build_gem "optparse", "0.1.1"
build_gem "optparse", "999.999.998"
build_gem "optparse", "999.999.999"
end

system_gems "optparse-0.1.0", :gem_repo => gem_repo4
system_gems "optparse-999.999.998", :gem_repo => gem_repo4

bundle "config set auto_install 1"
bundle "config set --local path vendor/bundle"
Expand All @@ -638,7 +638,7 @@
G

bundle "exec fastlane"
expect(out).to include("Installing optparse 0.1.1")
expect(out).to include("Installing optparse 999.999.999")
expect(out).to include("2.192.0")
end

Expand Down
2 changes: 1 addition & 1 deletion spec/bundler/install/gems/standalone_spec.rb
Expand Up @@ -113,7 +113,7 @@
skip "does not work on rubygems versions where `--install_dir` doesn't respect --default" unless Gem::Installer.for_spec(loaded_gemspec, :install_dir => "/foo").default_spec_file == "/foo/specifications/default/bundler-#{Bundler::VERSION}.gemspec" # Since rubygems 3.2.0.rc.2
skip "does not work on old rubies because the realworld gems that need to be installed don't support them" if RUBY_VERSION < "2.7.0"

realworld_system_gems "fiddle --version 1.0.6", "tsort --version 0.1.0"
realworld_system_gems "fiddle --version 1.0.8", "tsort --version 0.1.0"

necessary_system_gems = ["optparse --version 0.1.1", "psych --version 3.3.2", "yaml --version 0.1.1", "logger --version 1.4.3", "etc --version 1.2.0", "stringio --version 3.0.0"]
necessary_system_gems += ["shellwords --version 0.1.0", "base64 --version 0.1.0", "resolv --version 0.2.1"] if Gem.rubygems_version < Gem::Version.new("3.3.3.a")
Expand Down
6 changes: 3 additions & 3 deletions test/rubygems/test_gem_specification.rb
Expand Up @@ -944,7 +944,7 @@ def test_self_outdated
end

def test_self_outdated_and_latest_remotes
specs = spec_fetcher do |fetcher|
spec_fetcher do |fetcher|
fetcher.download 'a', 4
fetcher.download 'b', 3

Expand All @@ -953,8 +953,8 @@ def test_self_outdated_and_latest_remotes
end

expected = [
[specs['a-3.a'], v(4)],
[specs['b-2'], v(3)],
[Gem::Specification.stubs.find {|s| s.full_name == 'a-3.a' }, v(4)],
[Gem::Specification.stubs.find {|s| s.full_name == 'b-2' }, v(3)],
]

assert_equal expected, Gem::Specification.outdated_and_latest_version.to_a
Expand Down
12 changes: 0 additions & 12 deletions test/rubygems/test_project_sanity.rb
Expand Up @@ -17,16 +17,4 @@ def test_require_rubygems_package

assert status.success?, err
end

def test_require_and_use_rubygems_version
err, status = Open3.capture2e(
*ruby_with_rubygems_in_load_path,
"--disable-gems",
"-rrubygems/version",
"-e",
"Gem::Version.new('2.7.0.preview1') >= Gem::Version.new(RUBY_VERSION)"
)

assert status.success?, err
end
end
24 changes: 24 additions & 0 deletions test/rubygems/test_rubygems.rb
Expand Up @@ -22,6 +22,30 @@ def test_operating_system_other_exceptions
"the problem and ask for help."
end

def test_operating_system_customizing_default_dir
pend "does not apply to truffleruby" if RUBY_ENGINE == 'truffleruby'
pend "loads a custom defaults/jruby file that gets in the middle" if RUBY_ENGINE == 'jruby'
pend if RUBY_PLATFORM =~ /s390x/

# On a non existing default dir, there should be no gems

path = util_install_operating_system_rb <<-RUBY
module Gem
def self.default_dir
File.expand_path("foo")
end
end
RUBY

output = Gem::Util.popen(
*ruby_with_rubygems_and_fake_operating_system_in_load_path(path),
'-e',
"require \"rubygems\"; puts Gem::Specification.stubs.map(&:full_name)",
{:err => [:child, :out]}
).strip
assert_empty output
end

private

def util_install_operating_system_rb(content)
Expand Down
1 change: 1 addition & 0 deletions tool/bundler/rubocop_gems.rb.lock
Expand Up @@ -45,6 +45,7 @@ GEM

PLATFORMS
arm64-darwin-20
arm64-darwin-21
universal-java-11
x86_64-darwin-19
x86_64-darwin-20
Expand Down
1 change: 1 addition & 0 deletions tool/bundler/standard_gems.rb.lock
Expand Up @@ -51,6 +51,7 @@ GEM

PLATFORMS
arm64-darwin-20
arm64-darwin-21
universal-java-11
x86_64-darwin-19
x86_64-darwin-20
Expand Down