diff --git a/lib/bundler.rb b/lib/bundler.rb index 6c942baf59d..f492ede4e13 100644 --- a/lib/bundler.rb +++ b/lib/bundler.rb @@ -148,7 +148,7 @@ def locked_gems definition.locked_gems elsif Bundler.default_lockfile.file? lock = Bundler.read_file(Bundler.default_lockfile) - LockfileParser.new(lock) + LockfileParser.new(lock, Bundler.default_lockfile.dirname) end end diff --git a/lib/bundler/definition.rb b/lib/bundler/definition.rb index 4b9a781c826..ddb669d1320 100644 --- a/lib/bundler/definition.rb +++ b/lib/bundler/definition.rb @@ -80,7 +80,7 @@ def initialize(lockfile, dependencies, sources, unlock, ruby_version = nil, opti if lockfile && File.exist?(lockfile) @lockfile_contents = Bundler.read_file(lockfile) - @locked_gems = LockfileParser.new(@lockfile_contents) + @locked_gems = LockfileParser.new(@lockfile_contents, lockfile.dirname) @locked_platforms = @locked_gems.platforms @platforms = @locked_platforms.dup @locked_bundler_version = @locked_gems.bundler_version diff --git a/lib/bundler/lockfile_parser.rb b/lib/bundler/lockfile_parser.rb index ff706fca1d5..0a590dcf01a 100644 --- a/lib/bundler/lockfile_parser.rb +++ b/lib/bundler/lockfile_parser.rb @@ -58,7 +58,8 @@ def self.sections_to_ignore(base_version = nil) attributes end - def initialize(lockfile) + def initialize(lockfile, root_path) + @root_path = root_path @platforms = [] @sources = [] @dependencies = {} @@ -170,7 +171,7 @@ def parse_source(line) end when *SOURCE @current_source = nil - @opts = {} + @opts = { "root_path" => @root_path } @type = line else parse_spec(line) diff --git a/spec/bundler/lockfile_parser_spec.rb b/spec/bundler/lockfile_parser_spec.rb index 3a6d61336ff..19ec8706c0b 100644 --- a/spec/bundler/lockfile_parser_spec.rb +++ b/spec/bundler/lockfile_parser_spec.rb @@ -94,7 +94,7 @@ describe "#initialize" do before { allow(Bundler::SharedHelpers).to receive(:find_gemfile).and_return(bundled_app("gems.rb")) } - subject { described_class.new(lockfile_contents) } + subject { described_class.new(lockfile_contents, nil) } let(:sources) do [Bundler::Source::Git.new("uri" => "https://github.com/alloy/peiji-san.git", "revision" => "eca485d8dc95f12aaec1a434b49d295c7e91844b"), diff --git a/spec/commands/install_spec.rb b/spec/commands/install_spec.rb index 4cb8584633c..0e076c1ded8 100644 --- a/spec/commands/install_spec.rb +++ b/spec/commands/install_spec.rb @@ -534,4 +534,25 @@ "setting them for authentication.") end end + + describe "when sharing gemfile with path sources across different directories" do + it do + build_lib("foo", :path => "foo") + create_file("app/.bundle/config", <<-YAML) + --- + BUNDLE_GEMFILE: "../Gemfile" + YAML + gemfile <<-RUBY + gem 'foo', :path => 'foo' + RUBY + + bundle "install" + expect(out).to include("Bundle complete!") + in_app_root_custom "app" do + bundle "install" + expect(out).to include("Bundle complete!") + expect(the_bundle).to include_gem("foo 1.0") + end + end + end end diff --git a/spec/commands/lock_spec.rb b/spec/commands/lock_spec.rb index 8edbb95b0f2..4e1be46209b 100644 --- a/spec/commands/lock_spec.rb +++ b/spec/commands/lock_spec.rb @@ -165,13 +165,13 @@ def read_lockfile(file = "Gemfile.lock") it "supports adding new platforms" do bundle! "lock --add-platform java x86-mingw32" - lockfile = Bundler::LockfileParser.new(read_lockfile) + lockfile = Bundler::LockfileParser.new(read_lockfile, nil) expect(lockfile.platforms).to match_array(local_platforms.unshift(java, mingw).uniq) end it "supports adding the `ruby` platform" do bundle! "lock --add-platform ruby" - lockfile = Bundler::LockfileParser.new(read_lockfile) + lockfile = Bundler::LockfileParser.new(read_lockfile, nil) expect(lockfile.platforms).to match_array(local_platforms.unshift("ruby").uniq) end @@ -183,12 +183,12 @@ def read_lockfile(file = "Gemfile.lock") it "allows removing platforms" do bundle! "lock --add-platform java x86-mingw32" - lockfile = Bundler::LockfileParser.new(read_lockfile) + lockfile = Bundler::LockfileParser.new(read_lockfile, nil) expect(lockfile.platforms).to match_array(local_platforms.unshift(java, mingw).uniq) bundle! "lock --remove-platform java" - lockfile = Bundler::LockfileParser.new(read_lockfile) + lockfile = Bundler::LockfileParser.new(read_lockfile, nil) expect(lockfile.platforms).to match_array(local_platforms.unshift(mingw).uniq) end diff --git a/spec/install/gemfile/ruby_spec.rb b/spec/install/gemfile/ruby_spec.rb index 24fe021fa35..3c3d2e47976 100644 --- a/spec/install/gemfile/ruby_spec.rb +++ b/spec/install/gemfile/ruby_spec.rb @@ -2,7 +2,7 @@ RSpec.describe "ruby requirement" do def locked_ruby_version - Bundler::RubyVersion.from_string(Bundler::LockfileParser.new(lockfile).ruby_version) + Bundler::RubyVersion.from_string(Bundler::LockfileParser.new(lockfile, nil).ruby_version) end # As discovered by https://github.com/bundler/bundler/issues/4147, there is diff --git a/spec/support/sometimes.rb b/spec/support/sometimes.rb index 65a95ed59c9..ebacfcbc4c6 100644 --- a/spec/support/sometimes.rb +++ b/spec/support/sometimes.rb @@ -20,6 +20,8 @@ def run_with_retries(example_to_run, retries) end end +RSpec::Support.require_rspec_core "formatters/console_codes" + RSpec.configure do |config| config.include Sometimes config.alias_example_to :sometimes, :sometimes => true diff --git a/spec/support/the_bundle.rb b/spec/support/the_bundle.rb index c994eaae788..06a0b43a324 100644 --- a/spec/support/the_bundle.rb +++ b/spec/support/the_bundle.rb @@ -31,7 +31,7 @@ def lockfile def locked_gems raise "Cannot read lockfile if it doesn't exist" unless locked? - Bundler::LockfileParser.new(lockfile.read) + Bundler::LockfileParser.new(lockfile.read, lockfile.dirname) end end end