lib/bundler/definition.rb in bundler-2.0.2 vs lib/bundler/definition.rb in bundler-2.1.0.pre.1
- old
+ new
@@ -1,8 +1,8 @@
# frozen_string_literal: true
-require "bundler/lockfile_parser"
+require_relative "lockfile_parser"
require "set"
module Bundler
class Definition
include GemHelpers
@@ -165,11 +165,11 @@
#
# @return [Bundler::SpecSet]
def specs
@specs ||= begin
begin
- specs = resolve.materialize(Bundler.settings[:cache_all_platforms] ? dependencies : requested_dependencies)
+ specs = 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}, but that version could not " \
@@ -315,11 +315,11 @@
def has_local_dependencies?
!sources.path_sources.empty? || !sources.git_sources.empty?
end
def spec_git_paths
- sources.git_sources.map {|s| s.path.to_s }
+ sources.git_sources.map {|s| File.realpath(s.path) }
end
def groups
dependencies.map(&:groups).flatten.uniq
end
@@ -329,11 +329,11 @@
# Convert to \r\n if the existing lock has them
# i.e., Windows with `git config core.autocrlf=true`
contents.gsub!(/\n/, "\r\n") if @lockfile_contents.match("\r\n")
- if @locked_bundler_version && Bundler.feature_flag.lockfile_upgrade_warning?
+ if @locked_bundler_version
locked_major = @locked_bundler_version.segments.first
current_major = Gem::Version.create(Bundler::VERSION).segments.first
if updating_major = locked_major < current_major
Bundler.ui.warn "Warning: the lockfile is being updated to Bundler #{current_major}, " \
@@ -383,11 +383,11 @@
version
end
end
def to_lock
- require "bundler/lockfile_generator"
+ require_relative "lockfile_generator"
LockfileGenerator.generate(self)
end
def ensure_equivalent_gemfile_and_lockfile(explicit_flag = false)
msg = String.new
@@ -395,13 +395,13 @@
"your Gemfile. Run `bundle install` elsewhere and add the\n" \
"updated #{Bundler.default_lockfile.relative_path_from(SharedHelpers.pwd)} to version control."
unless explicit_flag
suggested_command = if Bundler.settings.locations("frozen")[:global]
- "bundle config --delete frozen"
+ "bundle config unset frozen"
elsif Bundler.settings.locations("deployment").keys.&([:global, :local]).any?
- "bundle config --delete deployment"
+ "bundle config unset deployment"
else
"bundle install --no-deployment"
end
msg << "\n\nIf this is a development machine, remove the #{Bundler.default_gemfile} " \
"freeze \nby running `#{suggested_command}`."
@@ -517,13 +517,11 @@
return if @platforms.delete(Gem::Platform.new(platform))
raise InvalidOption, "Unable to remove the platform `#{platform}` since the only platforms are #{@platforms.join ", "}"
end
def add_current_platform
- current_platform = Bundler.local_platform
- add_platform(current_platform) if Bundler.feature_flag.specific_platform?
- add_platform(generic(current_platform))
+ current_platforms.each {|platform| add_platform(platform) }
end
def find_resolved_spec(current_spec)
specs.find_by_name_and_platform(current_spec.name, current_spec.platform)
end
@@ -543,10 +541,18 @@
@unlocking
end
private
+ def current_platforms
+ current_platform = Bundler.local_platform
+ [].tap do |platforms|
+ platforms << current_platform if Bundler.feature_flag.specific_platform?
+ platforms << generic(current_platform)
+ end
+ end
+
def change_reason
if unlocking?
unlock_reason = @unlock.reject {|_k, v| Array(v).empty? }.map do |k, v|
if v == true
k.to_s
@@ -641,11 +647,11 @@
dep.source &&= converge_path_source_to_gemspec_source(dep.source)
end
end
def converge_rubygems_sources
- return false if Bundler.feature_flag.lockfile_uses_separate_rubygems_sources?
+ return false if Bundler.feature_flag.disable_multisource?
changes = false
# Get the RubyGems sources from the Gemfile.lock
locked_gem_sources = @locked_sources.select {|s| s.is_a?(Source::Rubygems) }
@@ -780,11 +786,11 @@
# If the spec is from a path source and it doesn't exist anymore
# then we unlock it.
# Path sources have special logic
if s.source.instance_of?(Source::Path) || s.source.instance_of?(Source::Gemspec)
- other_sources_specs = begin
+ new_specs = begin
s.source.specs
rescue PathError, GitError
# 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.
@@ -792,29 +798,30 @@
none? {|locked_spec| locked_spec.source == s.source }
raise
end
- other = other_sources_specs[s].first
+ new_spec = new_specs[s].first
# If the spec is no longer in the path source, unlock it. This
# commonly happens if the version changed in the gemspec
- next unless other
+ next unless new_spec
- deps2 = other.dependencies.select {|d| d.type != :development }
- runtime_dependencies = s.dependencies.select {|d| d.type != :development }
- # If the dependencies of the path source have changed, unlock it
- next unless runtime_dependencies.sort == deps2.sort
+ new_runtime_deps = new_spec.dependencies.select {|d| d.type != :development }
+ old_runtime_deps = s.dependencies.select {|d| d.type != :development }
+ # If the dependencies of the path source have changed and locked spec can't satisfy new dependencies, unlock it
+ next unless new_runtime_deps.sort == old_runtime_deps.sort || new_runtime_deps.all? {|d| satisfies_locked_spec?(d) }
+
+ s.dependencies.replace(new_spec.dependencies)
end
converged << s
end
resolve = SpecSet.new(converged)
- expanded_deps = expand_dependencies(deps, true)
- @locked_specs_incomplete_for_platform = !resolve.for(expanded_deps, @unlock[:gems], true, true)
- resolve = resolve.for(expanded_deps, @unlock[:gems], false, false, false)
+ @locked_specs_incomplete_for_platform = !resolve.for(expand_dependencies(deps), @unlock[:gems], true, true)
+ resolve = resolve.for(expand_dependencies(deps, true), @unlock[:gems], false, false, false)
diff = nil
# Now, we unlock any sources that do not have anymore gems pinned to it
sources.all_sources.each do |source|
next unless source.respond_to?(:unlock!)
@@ -853,12 +860,12 @@
if ruby_versions.empty? || !@ruby_version.exact?
concat_ruby_version_requirements(RubyVersion.system)
concat_ruby_version_requirements(locked_ruby_version_object) unless @unlock[:ruby]
end
[
- Dependency.new("ruby\0", ruby_versions),
- Dependency.new("rubygems\0", Gem::VERSION),
+ Dependency.new("Ruby\0", ruby_versions),
+ Dependency.new("RubyGems\0", Gem::VERSION),
]
end
end
def concat_ruby_version_requirements(ruby_version, ruby_versions = [])
@@ -883,11 +890,11 @@
dependencies.each do |dep|
dep = Dependency.new(dep, ">= 0") unless dep.respond_to?(:name)
next if !remote && !dep.current_platform?
platforms = dep.gem_platforms(sorted_platforms)
if platforms.empty? && !Bundler.settings[:disable_platform_warnings]
- mapped_platforms = dep.platforms.map {|p| Dependency::PLATFORM_MAP[p] }
+ mapped_platforms = dep.expanded_platforms
Bundler.ui.warn \
"The dependency #{dep} will be unused by any of the platforms Bundler is installing for. " \
"Bundler is installing for #{@platforms.join ", "} but the dependency " \
"is only for #{mapped_platforms.join ", "}. " \
"To add those platforms to the bundle, " \
@@ -913,11 +920,11 @@
# Record the specs available in each gem's source, so that those
# specs will be available later when the resolver knows where to
# look for that gemspec (or its dependencies)
default = sources.default_source
source_requirements = { :default => default }
- default = nil unless Bundler.feature_flag.lockfile_uses_separate_rubygems_sources?
+ default = nil unless Bundler.feature_flag.disable_multisource?
dependencies.each do |dep|
next unless source = dep.source || default
source_requirements[dep.name] = source
end
metadata_dependencies.each do |dep|
@@ -927,10 +934,10 @@
source_requirements
end
def pinned_spec_names(skip = nil)
pinned_names = []
- default = Bundler.feature_flag.lockfile_uses_separate_rubygems_sources? && sources.default_source
+ default = Bundler.feature_flag.disable_multisource? && sources.default_source
@dependencies.each do |dep|
next unless dep_source = dep.source || default
next if dep_source == skip
pinned_names << dep.name
end