summaryrefslogtreecommitdiff
path: root/lib/bundler/lockfile_parser.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/bundler/lockfile_parser.rb')
-rw-r--r--lib/bundler/lockfile_parser.rb55
1 files changed, 43 insertions, 12 deletions
diff --git a/lib/bundler/lockfile_parser.rb b/lib/bundler/lockfile_parser.rb
index a0f75bae1f..852fc631f3 100644
--- a/lib/bundler/lockfile_parser.rb
+++ b/lib/bundler/lockfile_parser.rb
@@ -1,9 +1,9 @@
# frozen_string_literal: true
+require_relative "shared_helpers"
+
module Bundler
class LockfileParser
- include GemHelpers
-
class Position
attr_reader :line, :column
def initialize(line, column)
@@ -28,6 +28,7 @@ module Bundler
attr_reader(
:sources,
+ :metadata_source,
:dependencies,
:specs,
:platforms,
@@ -94,24 +95,37 @@ module Bundler
lockfile_contents.split(BUNDLED).last.strip
end
- def initialize(lockfile)
+ def initialize(lockfile, strict: false, lockfile_path: nil)
@platforms = []
@sources = []
+ @metadata_source = Source::Metadata.new
@dependencies = {}
@parse_method = nil
@specs = {}
- @lockfile_path = begin
+ @lockfile_path = lockfile_path || begin
SharedHelpers.relative_lockfile_path
rescue GemfileNotFound
"Gemfile.lock"
end
@pos = Position.new(1, 1)
+ @strict = strict
if lockfile.match?(/<<<<<<<|=======|>>>>>>>|\|\|\|\|\|\|\|/)
raise LockfileError, "Your #{@lockfile_path} contains merge conflicts.\n" \
"Run `git checkout HEAD -- #{@lockfile_path}` first to get a clean lock."
end
+ @valid = lockfile.strip.empty? ||
+ lockfile.split(/(?:\r?\n)+/).any? {|l| KNOWN_SECTIONS.include?(l) }
+
+ unless @valid
+ SharedHelpers.feature_deprecated!(
+ "Your #{@lockfile_path} does not appear to be a valid lockfile. " \
+ "Run `rm #{@lockfile_path}` and then `bundle install` to generate a new lockfile. " \
+ "This will raise a LockfileError in a future version of Bundler."
+ )
+ end
+
lockfile.split(/((?:\r?\n)+)/) do |line|
# split alternates between the line and the following whitespace
next @pos.advance!(line) if line.match?(/^\s*$/)
@@ -139,8 +153,13 @@ module Bundler
end
@pos.advance!(line)
end
+
+ if @platforms.include?(Gem::Platform::X64_MINGW_LEGACY)
+ SharedHelpers.feature_deprecated!("Found x64-mingw32 in lockfile, which is deprecated and will be removed in the future.")
+ end
+
@most_specific_locked_platform = @platforms.min_by do |bundle_platform|
- platform_specificity_match(bundle_platform, local_platform)
+ Gem::Platform.platform_specificity_match(bundle_platform, Bundler.local_platform)
end
@specs = @specs.values.sort_by!(&:full_name).each do |spec|
spec.most_specific_locked_platform = @most_specific_locked_platform
@@ -156,6 +175,10 @@ module Bundler
bundler_version.nil? || bundler_version < Gem::Version.new("1.16.2")
end
+ def valid?
+ @valid
+ end
+
private
TYPES = {
@@ -239,7 +262,6 @@ module Bundler
spaces = $1
return unless spaces.size == 2
checksums = $6
- return unless checksums
name = $2
version = $3
platform = $4
@@ -247,12 +269,21 @@ module Bundler
version = Gem::Version.new(version)
platform = platform ? Gem::Platform.new(platform) : Gem::Platform::RUBY
full_name = Gem::NameTuple.new(name, version, platform).full_name
- return unless spec = @specs[full_name]
+ spec = @specs[full_name]
- checksums.split(",") do |lock_checksum|
- column = line.index(lock_checksum) + 1
- checksum = Checksum.from_lock(lock_checksum, "#{@lockfile_path}:#{@pos.line}:#{column}")
- spec.source.checksum_store.register(spec, checksum)
+ if name == "bundler"
+ spec ||= LazySpecification.new(name, version, platform, @metadata_source)
+ end
+ return unless spec
+
+ if checksums
+ checksums.split(",") do |lock_checksum|
+ column = line.index(lock_checksum) + 1
+ checksum = Checksum.from_lock(lock_checksum, "#{@lockfile_path}:#{@pos.line}:#{column}")
+ spec.source.checksum_store.register(spec, checksum)
+ end
+ else
+ spec.source.checksum_store.register(spec, nil)
end
end
@@ -268,7 +299,7 @@ module Bundler
version = Gem::Version.new(version)
platform = platform ? Gem::Platform.new(platform) : Gem::Platform::RUBY
- @current_spec = LazySpecification.new(name, version, platform, @current_source)
+ @current_spec = LazySpecification.new(name, version, platform, @current_source, strict: @strict)
@current_source.add_dependency_names(name)
@specs[@current_spec.full_name] = @current_spec