lib/bundler/definition.rb in bundler-1.11.2 vs lib/bundler/definition.rb in bundler-1.12.0.pre.1
- old
+ new
@@ -1,5 +1,6 @@
+# frozen_string_literal: true
require "bundler/lockfile_parser"
require "digest/sha1"
require "set"
module Bundler
@@ -51,18 +52,20 @@
@optional_groups = optional_groups
@remote = false
@specs = nil
@ruby_version = ruby_version
- @lockfile_contents = ""
+ @lockfile_contents = String.new
@locked_bundler_version = nil
+ @locked_ruby_version = nil
if lockfile && File.exist?(lockfile)
@lockfile_contents = Bundler.read_file(lockfile)
locked = LockfileParser.new(@lockfile_contents)
@platforms = locked.platforms
@locked_bundler_version = locked.bundler_version
+ @locked_ruby_version = locked.ruby_version
if unlock != true
@locked_deps = locked.dependencies
@locked_specs = SpecSet.new(locked.specs)
@locked_sources = locked.sources
@@ -192,12 +195,11 @@
last_resolve = converge_locked_specs
if Bundler.settings[:frozen] || (!@unlocking && nothing_changed?)
last_resolve
else
# Run a resolve against the locally available gems
- requested_ruby_version = ruby_version.version if ruby_version
- last_resolve.merge Resolver.resolve(expanded_dependencies, index, source_requirements, last_resolve, requested_ruby_version)
+ last_resolve.merge Resolver.resolve(expanded_dependencies, index, source_requirements, last_resolve, ruby_version)
end
end
end
def index
@@ -267,22 +269,40 @@
SharedHelpers.filesystem_access(file) do |p|
File.open(p, "wb") {|f| f.puts(contents) }
end
end
- # Returns the version of Bundler that is creating or has created
- # Gemfile.lock. Used in #to_lock.
- def lock_version
+ def locked_bundler_version
if @locked_bundler_version && @locked_bundler_version < Gem::Version.new(Bundler::VERSION)
new_version = Bundler::VERSION
end
new_version || @locked_bundler_version || Bundler::VERSION
end
+ def locked_ruby_version
+ if @unlock[:ruby]
+ if ruby_version && !@locked_ruby_version
+ return Bundler::RubyVersion.system
+ elsif ruby_version && @locked_ruby_version
+ return Bundler::RubyVersion.system
+ elsif !ruby_version && @locked_ruby_version
+ return nil
+ end
+ else
+ if ruby_version && !@locked_ruby_version
+ return Bundler::RubyVersion.system
+ elsif ruby_version && @locked_ruby_version
+ return @locked_ruby_version
+ elsif !ruby_version && @locked_ruby_version
+ return @locked_ruby_version
+ end
+ end
+ end
+
def to_lock
- out = ""
+ out = String.new
sources.lock_sources.each do |source|
# Add the source header
out << source.to_lock
# Find all specs for this source
@@ -313,24 +333,30 @@
next if handled.include?(dep.name)
out << dep.to_lock
handled << dep.name
end
+ if locked_ruby_version
+ out << "\nRUBY VERSION\n"
+ out << " #{locked_ruby_version}\n"
+ end
+
# Record the version of Bundler that was used to create the lockfile
out << "\nBUNDLED WITH\n"
- out << " #{lock_version}\n"
+ out << " #{locked_bundler_version}\n"
out
end
def ensure_equivalent_gemfile_and_lockfile(explicit_flag = false)
- msg = "You are trying to install in deployment mode after changing\n" \
- "your Gemfile. Run `bundle install` elsewhere and add the\n" \
- "updated #{Bundler.default_lockfile.relative_path_from(SharedHelpers.pwd)} to version control."
+ msg = String.new
+ msg << "You are trying to install in deployment mode after changing\n" \
+ "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
- msg += "\n\nIf this is a development machine, remove the #{Bundler.default_gemfile} " \
+ msg << "\n\nIf this is a development machine, remove the #{Bundler.default_gemfile} " \
"freeze \nby running `bundle install --no-deployment`."
end
added = []
deleted = []
@@ -379,20 +405,20 @@
end
def validate_ruby!
return unless ruby_version
- if diff = ruby_version.diff(Bundler.ruby_version)
+ if diff = ruby_version.diff(Bundler::RubyVersion.system)
problem, expected, actual = diff
msg = case problem
when :engine
"Your Ruby engine is #{actual}, but your Gemfile specified #{expected}"
when :version
"Your Ruby version is #{actual}, but your Gemfile specified #{expected}"
when :engine_version
- "Your #{Bundler.ruby_version.engine} version is #{actual}, but your Gemfile specified #{ruby_version.engine} #{expected}"
+ "Your #{Bundler::RubyVersion.system.engine} version is #{actual}, but your Gemfile specified #{ruby_version.engine} #{expected}"
when :patchlevel
if !expected.is_a?(String)
"The Ruby patchlevel in your Gemfile must be a string"
else
"Your Ruby patchlevel is #{actual}, but your Gemfile specified #{expected}"
@@ -610,10 +636,10 @@
deps = []
dependencies.each do |dep|
dep = Dependency.new(dep, ">= 0") unless dep.respond_to?(:name)
next unless remote || dep.current_platform?
dep.gem_platforms(@platforms).each do |p|
- deps << DepProxy.new(dep, p) if remote || p == generic(Gem::Platform.local)
+ deps << DepProxy.new(dep, p) if remote || p == generic_local_platform
end
end
deps
end