lib/bundler/definition.rb in bundler-2.4.20 vs lib/bundler/definition.rb in bundler-2.4.21
- old
+ new
@@ -147,11 +147,11 @@
end
@dependency_changes = converge_dependencies
@local_changes = converge_locals
- @missing_lockfile_dep = check_missing_lockfile_dep
+ check_lockfile
end
def gem_version_promoter
@gem_version_promoter ||= GemVersionPromoter.new
end
@@ -403,17 +403,17 @@
msg = String.new
msg << "#{reason.capitalize.strip}, but the lockfile can't be updated because frozen mode is set"
msg << "\n\nYou have added to the Gemfile:\n" << added.join("\n") if added.any?
msg << "\n\nYou have deleted from the Gemfile:\n" << deleted.join("\n") if deleted.any?
msg << "\n\nYou have changed in the Gemfile:\n" << changed.join("\n") if changed.any?
- msg << "\n\nRun `bundle install` elsewhere and add the updated #{Bundler.default_lockfile.relative_path_from(SharedHelpers.pwd)} to version control.\n"
+ msg << "\n\nRun `bundle install` elsewhere and add the updated #{SharedHelpers.relative_gemfile_path} to version control.\n"
unless explicit_flag
suggested_command = unless Bundler.settings.locations("frozen").keys.include?(:env)
"bundle config set frozen false"
end
- msg << "If this is a development machine, remove the #{Bundler.default_gemfile.relative_path_from(SharedHelpers.pwd)} " \
+ msg << "If this is a development machine, remove the #{SharedHelpers.relative_lockfile_path} " \
"freeze by running `#{suggested_command}`." if suggested_command
end
raise ProductionError, msg if added.any? || deleted.any? || changed.any? || !nothing_changed?
end
@@ -450,12 +450,12 @@
def validate_platforms!
return if current_platform_locked?
raise ProductionError, "Your bundle only supports platforms #{@platforms.map(&:to_s)} " \
- "but your local platform is #{Bundler.local_platform}. " \
- "Add the current platform to the lockfile with\n`bundle lock --add-platform #{Bundler.local_platform}` and try again."
+ "but your local platform is #{local_platform}. " \
+ "Add the current platform to the lockfile with\n`bundle lock --add-platform #{local_platform}` and try again."
end
def add_platform(platform)
@new_platform ||= !@platforms.include?(platform)
@platforms |= [platform]
@@ -476,11 +476,11 @@
attr_reader :sources
private :sources
def nothing_changed?
- !@source_changes && !@dependency_changes && !@new_platform && !@path_changes && !@local_changes && !@missing_lockfile_dep && !@unlocking_bundler
+ !@source_changes && !@dependency_changes && !@new_platform && !@path_changes && !@local_changes && !@missing_lockfile_dep && !@unlocking_bundler && !@invalid_lockfile_dep
end
def no_resolve_needed?
!unlocking? && nothing_changed?
end
@@ -507,11 +507,11 @@
end
def resolution_packages
@resolution_packages ||= begin
last_resolve = converge_locked_specs
- remove_ruby_from_platforms_if_necessary!(current_dependencies)
+ remove_invalid_platforms!(current_dependencies)
packages = Resolver::Base.new(source_requirements, expanded_dependencies, last_resolve, @platforms, :locked_specs => @originally_locked_specs, :unlock => @unlock[:gems], :prerelease => gem_version_promoter.pre?)
additional_base_requirements_for_resolve(packages, last_resolve)
end
end
@@ -598,11 +598,11 @@
current_platform_locked?
end
def current_platform_locked?
@platforms.any? do |bundle_platform|
- MatchPlatform.platforms_match?(bundle_platform, Bundler.local_platform)
+ MatchPlatform.platforms_match?(bundle_platform, local_platform)
end
end
def add_current_platform
return if current_ruby_platform_locked?
@@ -628,10 +628,11 @@
[@new_platform, "you added a new platform to your gemfile"],
[@path_changes, "the gemspecs for path gems changed"],
[@local_changes, "the gemspecs for git local gems changed"],
[@missing_lockfile_dep, "your lock file is missing \"#{@missing_lockfile_dep}\""],
[@unlocking_bundler, "an update to the version of Bundler itself was requested"],
+ [@invalid_lockfile_dep, "your lock file has an invalid dependency \"#{@invalid_lockfile_dep}\""],
].select(&:first).map(&:last).join(", ")
end
def pretty_dep(dep)
SharedHelpers.pretty_dependency(dep)
@@ -682,28 +683,42 @@
changed || specs_changed?(source)
end.map(&:first)
!sources_with_changes.each {|source| @unlock[:sources] << source.name }.empty?
end
- def check_missing_lockfile_dep
- all_locked_specs = @locked_specs.map(&:name) << "bundler"
+ def check_lockfile
+ @invalid_lockfile_dep = nil
+ @missing_lockfile_dep = nil
- missing = @locked_specs.select do |s|
- s.dependencies.any? {|dep| !all_locked_specs.include?(dep.name) }
+ locked_names = @locked_specs.map(&:name)
+ missing = []
+ invalid = []
+
+ @locked_specs.each do |s|
+ s.dependencies.each do |dep|
+ next if dep.name == "bundler"
+
+ missing << s unless locked_names.include?(dep.name)
+ invalid << s if @locked_specs.none? {|spec| dep.matches_spec?(spec) }
+ end
end
if missing.any?
@locked_specs.delete(missing)
- return missing.first.name
+ @missing_lockfile_dep = missing.first.name
+ elsif !@dependency_changes
+ @missing_lockfile_dep = current_dependencies.find do |d|
+ @locked_specs[d.name].empty? && d.name != "bundler"
+ end&.name
end
- return if @dependency_changes
+ if invalid.any?
+ @locked_specs.delete(invalid)
- current_dependencies.find do |d|
- @locked_specs[d.name].empty? && d.name != "bundler"
- end&.name
+ @invalid_lockfile_dep = invalid.first.name
+ end
end
def converge_paths
sources.path_sources.any? do |source|
specs_changed?(source)
@@ -939,20 +954,22 @@
resolution_packages.base_requirements[locked_spec.name] = Gem::Requirement.new(">= #{locked_spec.version}")
end
resolution_packages
end
- def remove_ruby_from_platforms_if_necessary!(dependencies)
- return if Bundler.frozen_bundle? ||
- Bundler.local_platform == Gem::Platform::RUBY ||
- !platforms.include?(Gem::Platform::RUBY) ||
- (@new_platform && platforms.last == Gem::Platform::RUBY) ||
+ def remove_invalid_platforms!(dependencies)
+ return if Bundler.frozen_bundle?
+
+ platforms.each do |platform|
+ next if local_platform == platform ||
+ (@new_platform && platforms.last == platform) ||
@path_changes ||
@dependency_changes ||
- !@originally_locked_specs.incomplete_ruby_specs?(dependencies)
+ !@originally_locked_specs.incomplete_for_platform?(dependencies, platform)
- remove_platform(Gem::Platform::RUBY)
- add_current_platform
+ remove_platform(platform)
+ add_current_platform if platform == Gem::Platform::RUBY
+ end
end
def source_map
@source_map ||= SourceMap.new(sources, dependencies, @locked_specs)
end