diff options
author | Hiroshi SHIBATA <hsbt@ruby-lang.org> | 2021-08-02 12:07:39 +0900 |
---|---|---|
committer | nagachika <nagachika@ruby-lang.org> | 2021-08-19 15:46:40 +0900 |
commit | 41a28637807bef9b15c404c93a778aaa6266ace7 (patch) | |
tree | 5a85615a3ff7fa753540f095f446babc1b5fe162 /lib/bundler | |
parent | 679185d6c87e0f2e4f6a5da5ce50d02c80ab31b1 (diff) |
Merge RubyGems 3.2.25 and Bundler 2.2.25
Diffstat (limited to 'lib/bundler')
-rw-r--r-- | lib/bundler/cli.rb | 6 | ||||
-rw-r--r-- | lib/bundler/cli/cache.rb | 2 | ||||
-rw-r--r-- | lib/bundler/cli/doctor.rb | 2 | ||||
-rw-r--r-- | lib/bundler/cli/install.rb | 21 | ||||
-rw-r--r-- | lib/bundler/cli/list.rb | 8 | ||||
-rw-r--r-- | lib/bundler/cli/open.rb | 3 | ||||
-rw-r--r-- | lib/bundler/cli/update.rb | 2 | ||||
-rw-r--r-- | lib/bundler/definition.rb | 52 | ||||
-rw-r--r-- | lib/bundler/dsl.rb | 15 | ||||
-rw-r--r-- | lib/bundler/installer/gem_installer.rb | 19 | ||||
-rw-r--r-- | lib/bundler/lockfile_parser.rb | 1 | ||||
-rw-r--r-- | lib/bundler/rubygems_gem_installer.rb | 6 | ||||
-rw-r--r-- | lib/bundler/runtime.rb | 21 | ||||
-rw-r--r-- | lib/bundler/settings.rb | 2 | ||||
-rw-r--r-- | lib/bundler/setup.rb | 4 | ||||
-rw-r--r-- | lib/bundler/shared_helpers.rb | 7 | ||||
-rw-r--r-- | lib/bundler/source/git/git_proxy.rb | 3 | ||||
-rw-r--r-- | lib/bundler/source/rubygems.rb | 4 | ||||
-rw-r--r-- | lib/bundler/source_list.rb | 19 | ||||
-rw-r--r-- | lib/bundler/spec_set.rb | 46 | ||||
-rw-r--r-- | lib/bundler/templates/Executable.bundler | 12 | ||||
-rw-r--r-- | lib/bundler/version.rb | 2 | ||||
-rw-r--r-- | lib/bundler/worker.rb | 19 |
23 files changed, 144 insertions, 132 deletions
diff --git a/lib/bundler/cli.rb b/lib/bundler/cli.rb index 177f362070..f054a2bfed 100644 --- a/lib/bundler/cli.rb +++ b/lib/bundler/cli.rb @@ -456,6 +456,12 @@ module Bundler "do in future versions. Instead please use `bundle config set cache_all true`, " \ "and stop using this flag" if ARGV.include?("--all") + SharedHelpers.major_deprecation 2, + "The `--path` flag is deprecated because its semantics are unclear. " \ + "Use `bundle config cache_path` to configure the path of your cache of gems, " \ + "and `bundle config path` to configure the path where your gems are installed, " \ + "and stop using this flag" if ARGV.include?("--path") + require_relative "cli/cache" Cache.new(options).run end diff --git a/lib/bundler/cli/cache.rb b/lib/bundler/cli/cache.rb index 9cd6133879..c8698ed7e3 100644 --- a/lib/bundler/cli/cache.rb +++ b/lib/bundler/cli/cache.rb @@ -9,7 +9,7 @@ module Bundler end def run - Bundler.ui.level = "error" if options[:quiet] + Bundler.ui.level = "warn" if options[:quiet] Bundler.settings.set_command_option_if_given :path, options[:path] Bundler.settings.set_command_option_if_given :cache_path, options["cache-path"] diff --git a/lib/bundler/cli/doctor.rb b/lib/bundler/cli/doctor.rb index 959b1b5e04..c28997bc7d 100644 --- a/lib/bundler/cli/doctor.rb +++ b/lib/bundler/cli/doctor.rb @@ -61,7 +61,7 @@ module Bundler end def run - Bundler.ui.level = "error" if options[:quiet] + Bundler.ui.level = "warn" if options[:quiet] Bundler.settings.validate! check! diff --git a/lib/bundler/cli/install.rb b/lib/bundler/cli/install.rb index 5e39e2a36d..4c1915fea6 100644 --- a/lib/bundler/cli/install.rb +++ b/lib/bundler/cli/install.rb @@ -8,7 +8,7 @@ module Bundler end def run - Bundler.ui.level = "error" if options[:quiet] + Bundler.ui.level = "warn" if options[:quiet] warn_if_root @@ -60,7 +60,7 @@ module Bundler installer = Installer.install(Bundler.root, definition, options) Bundler.settings.temporary(:cache_all_platforms => options[:local] ? false : Bundler.settings[:cache_all_platforms]) do - Bundler.load.cache if Bundler.app_cache.exist? && !options["no-cache"] && !Bundler.frozen_bundle? + Bundler.load.cache(nil, options[:local]) if Bundler.app_cache.exist? && !options["no-cache"] && !Bundler.frozen_bundle? end Bundler.ui.confirm "Bundle complete! #{dependencies_count_for(definition)}, #{gems_installed_for(definition)}." @@ -83,22 +83,9 @@ module Bundler end Bundler::CLI::Common.output_fund_metadata_summary - rescue GemNotFound, VersionConflict => e - if options[:local] && Bundler.app_cache.exist? - Bundler.ui.warn "Some gems seem to be missing from your #{Bundler.settings.app_cache_path} directory." - end - - unless Bundler.definition.has_rubygems_remotes? - Bundler.ui.warn <<-WARN, :wrap => true - Your Gemfile has no gem server sources. If you need gems that are \ - not already on your machine, add a line like this to your Gemfile: - source 'https://rubygems.org' - WARN - end - raise e - rescue Gem::InvalidSpecificationException => e + rescue Gem::InvalidSpecificationException Bundler.ui.warn "You have one or more invalid gemspecs that need to be fixed." - raise e + raise end private diff --git a/lib/bundler/cli/list.rb b/lib/bundler/cli/list.rb index 66abd32650..f56bf5b86a 100644 --- a/lib/bundler/cli/list.rb +++ b/lib/bundler/cli/list.rb @@ -16,7 +16,13 @@ module Bundler specs = if @only_group.any? || @without_group.any? filtered_specs_by_groups else - Bundler.load.specs + begin + Bundler.load.specs + rescue GemNotFound => e + Bundler.ui.error e.message + Bundler.ui.warn "Install missing gems with `bundle install`." + exit 1 + end end.reject {|s| s.name == "bundler" }.sort_by(&:name) return Bundler.ui.info "No gems in the Gemfile" if specs.empty? diff --git a/lib/bundler/cli/open.rb b/lib/bundler/cli/open.rb index df32e2f38b..ea504344f3 100644 --- a/lib/bundler/cli/open.rb +++ b/lib/bundler/cli/open.rb @@ -1,7 +1,5 @@ # frozen_string_literal: true -require "shellwords" - module Bundler class CLI::Open attr_reader :options, :name @@ -19,6 +17,7 @@ module Bundler else path = spec.full_gem_path Dir.chdir(path) do + require "shellwords" command = Shellwords.split(editor) + [path] Bundler.with_original_env do system(*command) diff --git a/lib/bundler/cli/update.rb b/lib/bundler/cli/update.rb index cf6a5b26d3..1adcaef67c 100644 --- a/lib/bundler/cli/update.rb +++ b/lib/bundler/cli/update.rb @@ -9,7 +9,7 @@ module Bundler end def run - Bundler.ui.level = "error" if options[:quiet] + Bundler.ui.level = "warn" if options[:quiet] Plugin.gemfile_install(Bundler.default_gemfile) if Bundler.feature_flag.plugins? diff --git a/lib/bundler/definition.rb b/lib/bundler/definition.rb index 94b8bc4057..f987d85f5b 100644 --- a/lib/bundler/definition.rb +++ b/lib/bundler/definition.rb @@ -133,7 +133,7 @@ module Bundler @unlock[:gems] ||= @dependencies.map(&:name) else eager_unlock = expand_dependencies(@unlock[:gems] || [], true) - @unlock[:gems] = @locked_specs.for(eager_unlock, false, false, false).map(&:name) + @unlock[:gems] = @locked_specs.for(eager_unlock, false, false).map(&:name) end @dependency_changes = converge_dependencies @@ -185,15 +185,7 @@ module Bundler # # @return [Bundler::SpecSet] def specs - @specs ||= add_bundler_to(resolve.materialize(requested_dependencies)) - rescue GemNotFound => e # Handle yanked gem - gem_name, gem_version = extract_gem_info(e) - locked_gem = @locked_specs[gem_name].last - raise if locked_gem.nil? || locked_gem.version.to_s != gem_version || !@remote - raise GemNotFound, "Your bundle is locked to #{locked_gem} from #{locked_gem.source}, but that version can " \ - "no longer be found in that source. That means the author of #{locked_gem} has removed it. " \ - "You'll need to update your bundle to a version other than #{locked_gem} that hasn't been " \ - "removed in order to install." + @specs ||= materialize(requested_dependencies) end def new_specs @@ -205,9 +197,7 @@ module Bundler end def missing_specs - missing = [] - resolve.materialize(requested_dependencies, missing) - missing + resolve.materialize(requested_dependencies).missing_specs end def missing_specs? @@ -241,7 +231,7 @@ module Bundler def specs_for(groups) groups = requested_groups if groups.empty? deps = dependencies_for(groups) - add_bundler_to(resolve.materialize(expand_dependencies(deps))) + materialize(expand_dependencies(deps)) end def dependencies_for(groups) @@ -274,10 +264,6 @@ module Bundler end end - def has_rubygems_remotes? - sources.rubygems_sources.any? {|s| s.remotes.any? } - end - def spec_git_paths sources.git_sources.map {|s| File.realpath(s.path) if File.exist?(s.path) }.compact end @@ -493,7 +479,23 @@ module Bundler private - def add_bundler_to(specs) + def materialize(dependencies) + specs = resolve.materialize(dependencies) + missing_specs = specs.missing_specs + + if missing_specs.any? + missing_specs.each do |s| + locked_gem = @locked_specs[s.name].last + next if locked_gem.nil? || locked_gem.version != s.version || !@remote + raise GemNotFound, "Your bundle is locked to #{locked_gem} from #{locked_gem.source}, but that version can " \ + "no longer be found in that source. That means the author of #{locked_gem} has removed it. " \ + "You'll need to update your bundle to a version other than #{locked_gem} that hasn't been " \ + "removed in order to install." + end + + raise GemNotFound, "Could not find #{missing_specs.map(&:full_name).join(", ")} in any of the sources" + end + unless specs["bundler"].any? bundler = sources.metadata_source.specs.search(Gem::Dependency.new("bundler", VERSION)).last specs["bundler"] = bundler @@ -712,7 +714,7 @@ module Bundler @locked_specs.each do |s| # Replace the locked dependency's source with the equivalent source from the Gemfile dep = @dependencies.find {|d| s.satisfies?(d) } - s.source = (dep && dep.source) || sources.get(s.source) + s.source = (dep && dep.source) || sources.get(s.source) unless multisource_allowed? # Don't add a spec to the list if its source is expired. For example, # if you change a Git gem to RubyGems. @@ -730,7 +732,7 @@ module Bundler # if we won't need the source (according to the lockfile), # don't error if the path/git source isn't available next if @locked_specs. - for(requested_dependencies, false, true, false). + for(requested_dependencies, false, true). none? {|locked_spec| locked_spec.source == s.source } raise @@ -750,7 +752,7 @@ module Bundler resolve = SpecSet.new(converged) @locked_specs_incomplete_for_platform = !resolve.for(expand_dependencies(requested_dependencies & deps), true, true) - resolve = SpecSet.new(resolve.for(expand_dependencies(deps, true), false, false, false).reject{|s| @unlock[:gems].include?(s.name) }) + resolve = SpecSet.new(resolve.for(expand_dependencies(deps, true), false, false).reject{|s| @unlock[:gems].include?(s.name) }) diff = nil # Now, we unlock any sources that do not have anymore gems pinned to it @@ -854,12 +856,6 @@ module Bundler current == proposed end - def extract_gem_info(error) - # This method will extract the error message like "Could not find foo-1.2.3 in any of the sources" - # to an array. The first element will be the gem name (e.g. foo), the second will be the version number. - error.message.scan(/Could not find (\w+)-(\d+(?:\.\d+)+)/).flatten - end - def compute_requires dependencies.reduce({}) do |requires, dep| next requires unless dep.should_include? diff --git a/lib/bundler/dsl.rb b/lib/bundler/dsl.rb index ac955894a7..3517a109ed 100644 --- a/lib/bundler/dsl.rb +++ b/lib/bundler/dsl.rb @@ -447,8 +447,21 @@ repo_name ||= user_name end def check_rubygems_source_safety - return unless @sources.aggregate_global_source? + if @sources.implicit_global_source? + implicit_global_source_warning + elsif @sources.aggregate_global_source? + multiple_global_source_warning + end + end + + def implicit_global_source_warning + Bundler::SharedHelpers.major_deprecation 2, "This Gemfile does not include an explicit global source. " \ + "Not using an explicit global source may result in a different lockfile being generated depending on " \ + "the gems you have installed locally before bundler is run." \ + "Instead, define a global source in your Gemfile like this: source \"https://rubygems.org\"." + end + def multiple_global_source_warning if Bundler.feature_flag.bundler_3_mode? msg = "This Gemfile contains multiple primary sources. " \ "Each source after the first must include a block to indicate which gems " \ diff --git a/lib/bundler/installer/gem_installer.rb b/lib/bundler/installer/gem_installer.rb index 507fd1802c..1df86ccfbc 100644 --- a/lib/bundler/installer/gem_installer.rb +++ b/lib/bundler/installer/gem_installer.rb @@ -1,7 +1,5 @@ # frozen_string_literal: true -require "shellwords" - module Bundler class GemInstaller attr_reader :spec, :standalone, :worker, :force, :installer @@ -31,34 +29,23 @@ module Bundler def specific_failure_message(e) message = "#{e.class}: #{e.message}\n" - message += " " + e.backtrace.join("\n ") + "\n\n" if Bundler.ui.debug? + message += " " + e.backtrace.join("\n ") + "\n\n" message = message.lines.first + Bundler.ui.add_color(message.lines.drop(1).join, :clear) message + Bundler.ui.add_color(failure_message, :red) end def failure_message - return install_error_message if spec.source.options["git"] - "#{install_error_message}\n#{gem_install_message}" + install_error_message end def install_error_message "An error occurred while installing #{spec.name} (#{spec.version}), and Bundler cannot continue." end - def gem_install_message - source = spec.source - return unless source.respond_to?(:remotes) - - if source.remotes.size == 1 - "Make sure that `gem install #{spec.name} -v '#{spec.version}' --source '#{source.remotes.first}'` succeeds before bundling." - else - "Make sure that `gem install #{spec.name} -v '#{spec.version}'` succeeds before bundling." - end - end - def spec_settings # Fetch the build settings, if there are any if settings = Bundler.settings["build.#{spec.name}"] + require "shellwords" Shellwords.shellsplit(settings) end end diff --git a/lib/bundler/lockfile_parser.rb b/lib/bundler/lockfile_parser.rb index afc21fd006..8d0e44d0ae 100644 --- a/lib/bundler/lockfile_parser.rb +++ b/lib/bundler/lockfile_parser.rb @@ -195,6 +195,7 @@ module Bundler platform = platform ? Gem::Platform.new(platform) : Gem::Platform::RUBY @current_spec = LazySpecification.new(name, version, platform) @current_spec.source = @current_source + @current_source.add_dependency_names(name) @specs[@current_spec.identifier] = @current_spec elsif spaces.size == 6 diff --git a/lib/bundler/rubygems_gem_installer.rb b/lib/bundler/rubygems_gem_installer.rb index f5f3c53309..8890582318 100644 --- a/lib/bundler/rubygems_gem_installer.rb +++ b/lib/bundler/rubygems_gem_installer.rb @@ -61,7 +61,10 @@ module Bundler def build_extensions extension_cache_path = options[:bundler_extension_cache_path] - return super unless extension_cache_path && extension_dir = spec.extension_dir + unless extension_cache_path && extension_dir = spec.extension_dir + require "shellwords" # compensate missing require in rubygems before version 3.2.25 + return super + end extension_dir = Pathname.new(extension_dir) build_complete = SharedHelpers.filesystem_access(extension_cache_path.join("gem.build_complete"), :read, &:file?) @@ -71,6 +74,7 @@ module Bundler FileUtils.cp_r extension_cache_path, spec.extension_dir end else + require "shellwords" # compensate missing require in rubygems before version 3.2.25 super if extension_dir.directory? # not made for gems without extensions SharedHelpers.filesystem_access(extension_cache_path.parent, &:mkpath) diff --git a/lib/bundler/runtime.rb b/lib/bundler/runtime.rb index 287fa1cfe9..fbb8833cfb 100644 --- a/lib/bundler/runtime.rb +++ b/lib/bundler/runtime.rb @@ -22,10 +22,6 @@ module Bundler # Activate the specs load_paths = specs.map do |spec| - unless spec.loaded_from - raise GemNotFound, "#{spec.full_name} is missing. Run `bundle install` to get it." - end - check_for_activated_spec!(spec) Bundler.rubygems.mark_loaded(spec) @@ -104,7 +100,7 @@ module Bundler alias_method :gems, :specs - def cache(custom_path = nil) + def cache(custom_path = nil, local = false) cache_path = Bundler.app_cache(custom_path) SharedHelpers.filesystem_access(cache_path) do |p| FileUtils.mkdir_p(p) @@ -112,7 +108,20 @@ module Bundler Bundler.ui.info "Updating files in #{Bundler.settings.app_cache_path}" - specs_to_cache = Bundler.settings[:cache_all_platforms] ? @definition.resolve.materialized_for_all_platforms : specs + specs_to_cache = if Bundler.settings[:cache_all_platforms] + @definition.resolve.materialized_for_all_platforms + else + begin + specs + rescue GemNotFound + if local + Bundler.ui.warn "Some gems seem to be missing from your #{Bundler.settings.app_cache_path} directory." + end + + raise + end + end + specs_to_cache.each do |spec| next if spec.name == "bundler" next if spec.source.is_a?(Source::Gemspec) diff --git a/lib/bundler/settings.rb b/lib/bundler/settings.rb index de42cc16af..03126f616c 100644 --- a/lib/bundler/settings.rb +++ b/lib/bundler/settings.rb @@ -428,6 +428,8 @@ module Bundler def global_config_file if ENV["BUNDLE_CONFIG"] && !ENV["BUNDLE_CONFIG"].empty? Pathname.new(ENV["BUNDLE_CONFIG"]) + elsif ENV["BUNDLE_USER_CONFIG"] && !ENV["BUNDLE_USER_CONFIG"].empty? + Pathname.new(ENV["BUNDLE_USER_CONFIG"]) elsif Bundler.rubygems.user_home && !Bundler.rubygems.user_home.empty? Pathname.new(Bundler.rubygems.user_home).join(".bundle/config") end diff --git a/lib/bundler/setup.rb b/lib/bundler/setup.rb index 27911dc1ad..32e9b2d7c0 100644 --- a/lib/bundler/setup.rb +++ b/lib/bundler/setup.rb @@ -9,10 +9,10 @@ if Bundler::SharedHelpers.in_bundle? begin Bundler.ui.silence { Bundler.setup } rescue Bundler::BundlerError => e - Bundler.ui.warn "\e[31m#{e.message}\e[0m" + Bundler.ui.error e.message Bundler.ui.warn e.backtrace.join("\n") if ENV["DEBUG"] if e.is_a?(Bundler::GemNotFound) - Bundler.ui.warn "\e[33mRun `bundle install` to install missing gems.\e[0m" + Bundler.ui.warn "Run `bundle install` to install missing gems." end exit e.status_code end diff --git a/lib/bundler/shared_helpers.rb b/lib/bundler/shared_helpers.rb index 09b79acbf9..187dfe87a1 100644 --- a/lib/bundler/shared_helpers.rb +++ b/lib/bundler/shared_helpers.rb @@ -152,13 +152,6 @@ module Bundler Bundler.ui.warn message end - def trap(signal, override = false, &block) - prior = Signal.trap(signal) do - block.call - prior.call unless override - end - end - def ensure_same_dependencies(spec, old_deps, new_deps) new_deps = new_deps.reject {|d| d.type == :development } old_deps = old_deps.reject {|d| d.type == :development } diff --git a/lib/bundler/source/git/git_proxy.rb b/lib/bundler/source/git/git_proxy.rb index ae21770306..7555561edd 100644 --- a/lib/bundler/source/git/git_proxy.rb +++ b/lib/bundler/source/git/git_proxy.rb @@ -1,7 +1,5 @@ # frozen_string_literal: true -require "shellwords" - module Bundler class Source class Git @@ -224,6 +222,7 @@ module Bundler end def check_allowed(command) + require "shellwords" command_with_no_credentials = URICredentialsFilter.credential_filtered_string("git #{command.shelljoin}", uri) raise GitNotAllowedError.new(command_with_no_credentials) unless allow? command_with_no_credentials diff --git a/lib/bundler/source/rubygems.rb b/lib/bundler/source/rubygems.rb index 43b193cf1c..858a69a48b 100644 --- a/lib/bundler/source/rubygems.rb +++ b/lib/bundler/source/rubygems.rb @@ -71,6 +71,10 @@ module Bundler @remotes.size > 1 end + def no_remotes? + @remotes.size == 0 + end + def can_lock?(spec) return super unless multiple_remotes? include?(spec.source) diff --git a/lib/bundler/source_list.rb b/lib/bundler/source_list.rb index 113d49ba72..d6310b78c0 100644 --- a/lib/bundler/source_list.rb +++ b/lib/bundler/source_list.rb @@ -37,6 +37,10 @@ module Bundler global_rubygems_source.multiple_remotes? end + def implicit_global_source? + global_rubygems_source.no_remotes? + end + def add_path_source(options = {}) if options["gemspec"] add_source_to_list Source::Gemspec.new(options), path_sources @@ -117,7 +121,8 @@ module Bundler def replace_sources!(replacement_sources) return false if replacement_sources.empty? - @path_sources, @git_sources, @plugin_sources = map_sources(replacement_sources) + @rubygems_sources, @path_sources, @git_sources, @plugin_sources = map_sources(replacement_sources) + @global_rubygems_source = global_replacement_source(replacement_sources) different_sources?(lock_sources, replacement_sources) end @@ -152,13 +157,21 @@ module Bundler end def map_sources(replacement_sources) - [path_sources, git_sources, plugin_sources].map do |sources| + [@rubygems_sources, @path_sources, @git_sources, @plugin_sources].map do |sources| sources.map do |source| replacement_sources.find {|s| s == source } || source end end end + def global_replacement_source(replacement_sources) + replacement_source = replacement_sources.find {|s| s == global_rubygems_source } + return global_rubygems_source unless replacement_source + + replacement_source.local! + replacement_source + end + def different_sources?(lock_sources, replacement_sources) !equal_sources?(lock_sources, replacement_sources) && !equivalent_sources?(lock_sources, replacement_sources) end @@ -202,7 +215,7 @@ module Bundler end def equal_source?(source, other_source) - return source.include?(other_source) if source.is_a?(Source::Rubygems) && other_source.is_a?(Source::Rubygems) && !merged_gem_lockfile_sections? + return source.include?(other_source) if source.is_a?(Source::Rubygems) && other_source.is_a?(Source::Rubygems) source == other_source end diff --git a/lib/bundler/spec_set.rb b/lib/bundler/spec_set.rb index 1a8906c47e..7be4fcca87 100644 --- a/lib/bundler/spec_set.rb +++ b/lib/bundler/spec_set.rb @@ -11,7 +11,7 @@ module Bundler @specs = specs end - def for(dependencies, check = false, match_current_platform = false, raise_on_missing = true) + def for(dependencies, check = false, match_current_platform = false) handled = [] deps = dependencies.dup specs = [] @@ -33,11 +33,6 @@ module Bundler end elsif check return false - elsif raise_on_missing - others = lookup[dep.name] if match_current_platform - message = "Unable to find a spec satisfying #{dep} in the set. Perhaps the lockfile is corrupted?" - message += " Found #{others.join(", ")} that did not match the current platform." if others && !others.empty? - raise GemNotFound, message end end @@ -71,52 +66,35 @@ module Bundler lookup.dup end - def materialize(deps, missing_specs = nil) - materialized = self.for(deps, false, true, !missing_specs) - - materialized.group_by(&:source).each do |source, specs| - next unless specs.any?{|s| s.is_a?(LazySpecification) } - - source.local! - names = -> { specs.map(&:name).uniq } - source.double_check_for(names) - end + def materialize(deps) + materialized = self.for(deps, false, true) materialized.map! do |s| next s unless s.is_a?(LazySpecification) - spec = s.__materialize__ - unless spec - unless missing_specs - raise GemNotFound, "Could not find #{s.full_name} in any of the sources" - end - missing_specs << s - end - spec + s.source.local! + s.__materialize__ || s end - SpecSet.new(missing_specs ? materialized.compact : materialized) + SpecSet.new(materialized) end # Materialize for all the specs in the spec set, regardless of what platform they're for # This is in contrast to how for does platform filtering (and specifically different from how `materialize` calls `for` only for the current platform) # @return [Array<Gem::Specification>] def materialized_for_all_platforms - @specs.group_by(&:source).each do |source, specs| - next unless specs.any?{|s| s.is_a?(LazySpecification) } - - source.local! - source.remote! - names = -> { specs.map(&:name).uniq } - source.double_check_for(names) - end - @specs.map do |s| next s unless s.is_a?(LazySpecification) + s.source.local! + s.source.remote! spec = s.__materialize__ raise GemNotFound, "Could not find #{s.full_name} in any of the sources" unless spec spec end end + def missing_specs + @specs.select {|s| s.is_a?(LazySpecification) } + end + def merge(set) arr = sorted.dup set.each do |set_spec| diff --git a/lib/bundler/templates/Executable.bundler b/lib/bundler/templates/Executable.bundler index 69f26bb9c0..8009412ea2 100644 --- a/lib/bundler/templates/Executable.bundler +++ b/lib/bundler/templates/Executable.bundler @@ -60,16 +60,16 @@ m = Module.new do Regexp.last_match(1) end - def bundler_version - @bundler_version ||= + def bundler_requirement + @bundler_requirement ||= env_var_version || cli_arg_version || - lockfile_version + bundler_requirement_for(lockfile_version) end - def bundler_requirement - return "#{Gem::Requirement.default}.a" unless bundler_version + def bundler_requirement_for(version) + return "#{Gem::Requirement.default}.a" unless version - bundler_gem_version = Gem::Version.new(bundler_version) + bundler_gem_version = Gem::Version.new(version) requirement = bundler_gem_version.approximate_recommendation diff --git a/lib/bundler/version.rb b/lib/bundler/version.rb index c4f92994ff..4447aa401e 100644 --- a/lib/bundler/version.rb +++ b/lib/bundler/version.rb @@ -1,7 +1,7 @@ # frozen_string_literal: false module Bundler - VERSION = "2.2.24".freeze + VERSION = "2.2.25".freeze def self.bundler_major_version @bundler_major_version ||= VERSION.split(".").first.to_i diff --git a/lib/bundler/worker.rb b/lib/bundler/worker.rb index 10139ed25b..ffa095b228 100644 --- a/lib/bundler/worker.rb +++ b/lib/bundler/worker.rb @@ -26,7 +26,7 @@ module Bundler @func = func @size = size @threads = nil - SharedHelpers.trap("INT") { abort_threads } + @previous_interrupt_handler = nil end # Enqueue a request to be executed in the worker pool @@ -68,13 +68,16 @@ module Bundler # so as worker threads after retrieving it, shut themselves down def stop_threads return unless @threads + @threads.each { @request_queue.enq POISON } @threads.each(&:join) + + remove_interrupt_handler + @threads = nil end def abort_threads - return unless @threads Bundler.ui.debug("\n#{caller.join("\n")}") @threads.each(&:exit) exit 1 @@ -94,11 +97,23 @@ module Bundler end end.compact + add_interrupt_handler unless @threads.empty? + return if creation_errors.empty? message = "Failed to create threads for the #{name} worker: #{creation_errors.map(&:to_s).uniq.join(", ")}" raise ThreadCreationError, message if @threads.empty? Bundler.ui.info message end + + def add_interrupt_handler + @previous_interrupt_handler = trap("INT") { abort_threads } + end + + def remove_interrupt_handler + return unless @previous_interrupt_handler + + trap "INT", @previous_interrupt_handler + end end end |