From ff3d7b720ec21e4856aac0b3c493bc78cbac83d4 Mon Sep 17 00:00:00 2001 From: Hiroshi SHIBATA Date: Mon, 28 Feb 2022 10:32:28 +0900 Subject: Merge RubyGems and Bundler master --- lib/bundler.rb | 2 +- lib/bundler/cli/config.rb | 11 ++++++++++- lib/bundler/cli/install.rb | 31 ++++++------------------------- lib/bundler/fetcher.rb | 10 +++++----- lib/bundler/psyched_yaml.rb | 10 ---------- lib/bundler/rubygems_ext.rb | 23 +++++++++++++---------- lib/bundler/rubygems_integration.rb | 16 ++-------------- lib/bundler/settings.rb | 2 +- 8 files changed, 38 insertions(+), 67 deletions(-) delete mode 100644 lib/bundler/psyched_yaml.rb (limited to 'lib') diff --git a/lib/bundler.rb b/lib/bundler.rb index 89865a8254..8688206285 100644 --- a/lib/bundler.rb +++ b/lib/bundler.rb @@ -654,7 +654,7 @@ EOF private def eval_yaml_gemspec(path, contents) - require_relative "bundler/psyched_yaml" + Kernel.require "psych" Gem::Specification.from_yaml(contents) rescue ::Psych::SyntaxError, ArgumentError, Gem::EndOfYAMLException, Gem::Exception diff --git a/lib/bundler/cli/config.rb b/lib/bundler/cli/config.rb index 8d2aba0916..e1222c75dd 100644 --- a/lib/bundler/cli/config.rb +++ b/lib/bundler/cli/config.rb @@ -180,7 +180,7 @@ module Bundler scopes = %w[global local].select {|s| options[s] } case scopes.size when 0 - @scope = "global" + @scope = inside_app? ? "local" : "global" @explicit_scope = false when 1 @scope = scopes.first @@ -189,6 +189,15 @@ module Bundler "The options #{scopes.join " and "} were specified. Please only use one of the switches at a time." end end + + private + + def inside_app? + Bundler.root + true + rescue GemfileNotFound + false + end end end end diff --git a/lib/bundler/cli/install.rb b/lib/bundler/cli/install.rb index c3400c3959..e9b85f7f6f 100644 --- a/lib/bundler/cli/install.rb +++ b/lib/bundler/cli/install.rb @@ -135,32 +135,13 @@ module Bundler end def normalize_groups - options[:with] &&= options[:with].join(":").tr(" ", ":").split(":") - options[:without] &&= options[:without].join(":").tr(" ", ":").split(":") - check_for_group_conflicts_in_cli_options - Bundler.settings.set_command_option :with, nil if options[:with] == [] - Bundler.settings.set_command_option :without, nil if options[:without] == [] - - with = options.fetch(:with, []) - with |= Bundler.settings[:with].map(&:to_s) - with -= options[:without] if options[:without] - - without = options.fetch(:without, []) - without |= Bundler.settings[:without].map(&:to_s) - without -= options[:with] if options[:with] - - options[:with] = with - options[:without] = without - - unless Bundler.settings[:without] == options[:without] && Bundler.settings[:with] == options[:with] - # need to nil them out first to get around validation for backwards compatibility - Bundler.settings.set_command_option :without, nil - Bundler.settings.set_command_option :with, nil - Bundler.settings.set_command_option :without, options[:without] - options[:with] - Bundler.settings.set_command_option :with, options[:with] - end + # need to nil them out first to get around validation for backwards compatibility + Bundler.settings.set_command_option :without, nil + Bundler.settings.set_command_option :with, nil + Bundler.settings.set_command_option :without, options[:without] + Bundler.settings.set_command_option :with, options[:with] end def normalize_settings @@ -184,7 +165,7 @@ module Bundler Bundler.settings.set_command_option_if_given :clean, options["clean"] - normalize_groups + normalize_groups if options[:without] || options[:with] options[:force] = options[:redownload] end diff --git a/lib/bundler/fetcher.rb b/lib/bundler/fetcher.rb index 89103fe1ec..e07f925107 100644 --- a/lib/bundler/fetcher.rb +++ b/lib/bundler/fetcher.rb @@ -240,7 +240,7 @@ module Bundler raise SSLError if needs_ssl && !defined?(OpenSSL::SSL) con = PersistentHTTP.new :name => "bundler", :proxy => :ENV - if gem_proxy = Bundler.rubygems.configuration[:http_proxy] + if gem_proxy = Gem.configuration[:http_proxy] con.proxy = Bundler::URI.parse(gem_proxy) if gem_proxy != :no_proxy end @@ -251,8 +251,8 @@ module Bundler end ssl_client_cert = Bundler.settings[:ssl_client_cert] || - (Bundler.rubygems.configuration.ssl_client_cert if - Bundler.rubygems.configuration.respond_to?(:ssl_client_cert)) + (Gem.configuration.ssl_client_cert if + Gem.configuration.respond_to?(:ssl_client_cert)) if ssl_client_cert pem = File.read(ssl_client_cert) con.cert = OpenSSL::X509::Certificate.new(pem) @@ -283,8 +283,8 @@ module Bundler def bundler_cert_store store = OpenSSL::X509::Store.new ssl_ca_cert = Bundler.settings[:ssl_ca_cert] || - (Bundler.rubygems.configuration.ssl_ca_cert if - Bundler.rubygems.configuration.respond_to?(:ssl_ca_cert)) + (Gem.configuration.ssl_ca_cert if + Gem.configuration.respond_to?(:ssl_ca_cert)) if ssl_ca_cert if File.directory? ssl_ca_cert store.add_path ssl_ca_cert diff --git a/lib/bundler/psyched_yaml.rb b/lib/bundler/psyched_yaml.rb deleted file mode 100644 index 3d9893031f..0000000000 --- a/lib/bundler/psyched_yaml.rb +++ /dev/null @@ -1,10 +0,0 @@ -# frozen_string_literal: true - -begin - require "psych" -rescue LoadError - # Apparently Psych wasn't available. Oh well. -end - -# At least load the YAML stdlib, whatever that may be -require "yaml" unless defined?(YAML.dump) diff --git a/lib/bundler/rubygems_ext.rb b/lib/bundler/rubygems_ext.rb index 5d572aa73d..cc06b9ee93 100644 --- a/lib/bundler/rubygems_ext.rb +++ b/lib/bundler/rubygems_ext.rb @@ -4,14 +4,12 @@ require "pathname" require "rubygems/specification" -# Possible use in Gem::Specification#source below and require -# shouldn't be deferred. -require "rubygems/source" - require_relative "match_platform" module Gem class Specification + include ::Bundler::MatchPlatform + attr_accessor :remote, :location, :relative_loaded_from remove_method :source @@ -81,6 +79,17 @@ module Gem gemfile end + # Backfill missing YAML require when not defined. Fixed since 3.1.0.pre1. + module YamlBackfiller + def to_yaml(opts = {}) + Gem.load_yaml unless defined?(::YAML) + + super(opts) + end + end + + prepend YamlBackfiller + def nondevelopment_dependencies dependencies - development_dependencies end @@ -228,9 +237,3 @@ module Gem end end end - -module Gem - class Specification - include ::Bundler::MatchPlatform - end -end diff --git a/lib/bundler/rubygems_integration.rb b/lib/bundler/rubygems_integration.rb index 785f7fa360..1c2b374d8b 100644 --- a/lib/bundler/rubygems_integration.rb +++ b/lib/bundler/rubygems_integration.rb @@ -104,18 +104,6 @@ module Bundler obj.to_s end - def configuration - require_relative "psyched_yaml" - Gem.configuration - rescue Gem::SystemExitException, LoadError => e - Bundler.ui.error "#{e.class}: #{e.message}" - Bundler.ui.trace e - raise - rescue ::Psych::SyntaxError => e - raise YamlSyntaxError.new(e, "Your RubyGems configuration, which is " \ - "usually located in ~/.gemrc, contains invalid YAML syntax.") - end - def ruby_engine Gem.ruby_engine end @@ -217,7 +205,7 @@ module Bundler def spec_from_gem(path, policy = nil) require "rubygems/security" - require_relative "psyched_yaml" + require "psych" gem_from_path(path, security_policies[policy]).spec rescue Exception, Gem::Exception, Gem::Security::Exception => e # rubocop:disable Lint/RescueException if e.is_a?(Gem::Security::Exception) || @@ -522,7 +510,7 @@ module Bundler def gem_remote_fetcher require "rubygems/remote_fetcher" - proxy = configuration[:http_proxy] + proxy = Gem.configuration[:http_proxy] Gem::RemoteFetcher.new(proxy) end diff --git a/lib/bundler/settings.rb b/lib/bundler/settings.rb index 72728fb20f..8f263cd012 100644 --- a/lib/bundler/settings.rb +++ b/lib/bundler/settings.rb @@ -367,7 +367,7 @@ module Bundler def to_array(value) return [] unless value - value.split(":").map(&:to_sym) + value.tr(" ", ":").split(":").map(&:to_sym) end def array_to_s(array) -- cgit v1.2.3