diff --git a/lib/bundler/definition.rb b/lib/bundler/definition.rb index 4b75b390654..d7faff53e7d 100644 --- a/lib/bundler/definition.rb +++ b/lib/bundler/definition.rb @@ -194,10 +194,19 @@ def missing_specs missing end - def missing_dependencies + def missing_dependencies? missing = [] resolve.materialize(current_dependencies, missing) - missing + return false if missing.empty? + Bundler.ui.debug "The definition is missing #{missing.map(&:full_name)}" + true + rescue BundlerError => e + Bundler.ui.debug "The definition is missing dependencies, failed to resolve & materialize locally (#{e})" + true + ensure + @index = nil + @resolve = nil + @specs = nil end def requested_specs diff --git a/lib/bundler/installer.rb b/lib/bundler/installer.rb index ae8055408fc..7c13c0c8a93 100644 --- a/lib/bundler/installer.rb +++ b/lib/bundler/installer.rb @@ -78,7 +78,7 @@ def run(options) return end - resolve_if_need(options) + resolve_if_needed(options) ensure_specs_are_compatible! install(options) @@ -229,18 +229,11 @@ def create_bundle_path "because a file already exists at that path. Either remove or rename the file so the directory can be created." end - def resolve_if_need(options) + def resolve_if_needed(options) if !options["update"] && !options[:inline] && !options["force"] && Bundler.default_lockfile.file? - local = Bundler.ui.silence do - begin - tmpdef = Definition.build(Bundler.default_gemfile, Bundler.default_lockfile, nil) - true unless tmpdef.new_platform? || tmpdef.missing_dependencies.any? - rescue BundlerError - end - end + return if @definition.nothing_changed? && !@definition.missing_dependencies? end - return if local options["local"] ? @definition.resolve_with_cache! : @definition.resolve_remotely! end diff --git a/lib/bundler/source/path.rb b/lib/bundler/source/path.rb index 82f987fdd8f..99808d2ef26 100644 --- a/lib/bundler/source/path.rb +++ b/lib/bundler/source/path.rb @@ -35,10 +35,12 @@ def initialize(options) end def remote! + @local_specs = nil @allow_remote = true end def cached! + @local_specs = nil @allow_cached = true end diff --git a/lib/bundler/source/rubygems.rb b/lib/bundler/source/rubygems.rb index 353194f53f8..a1d42669608 100644 --- a/lib/bundler/source/rubygems.rb +++ b/lib/bundler/source/rubygems.rb @@ -31,6 +31,7 @@ def remote! end def cached! + @specs = nil @allow_cached = true end diff --git a/spec/install/gemfile/lockfile_spec.rb b/spec/install/gemfile/lockfile_spec.rb new file mode 100644 index 00000000000..dc1baca6ea5 --- /dev/null +++ b/spec/install/gemfile/lockfile_spec.rb @@ -0,0 +1,48 @@ +# frozen_string_literal: true + +RSpec.describe "bundle install with a lockfile present" do + let(:gf) { <<-G } + source "file://#{gem_repo1}" + + gem "rack", "1.0.0" + G + + subject do + install_gemfile(gf) + end + + context "gemfile evaluation" do + let(:gf) { super() + "\n\n File.open('evals', 'a') {|f| f << %(1\n) } unless ENV['BUNDLER_SPEC_NO_APPEND']" } + + context "with plugins disabled" do + before do + bundle! "config plugins false" + subject + end + + it "does not evaluate the gemfile twice" do + bundle! :install + + with_env_vars("BUNDLER_SPEC_NO_APPEND" => "1") { expect(the_bundle).to include_gem "rack 1.0.0" } + + # The first eval is from the initial install, we're testing that the + # second install doesn't double-eval + expect(bundled_app("evals").read.lines.to_a.size).to eq(2) + end + + context "when the gem is not installed" do + before { FileUtils.rm_rf ".bundle" } + + it "does not evaluate the gemfile twice" do + bundle! :install + + with_env_vars("BUNDLER_SPEC_NO_APPEND" => "1") { expect(the_bundle).to include_gem "rack 1.0.0" } + + # The first eval is from the initial install, we're testing that the + # second install doesn't double-eval + expect(bundled_app("evals").read.lines.to_a.size).to eq(2) + end + end + end + end +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index f6700ca315b..782cffc1d19 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -46,7 +46,6 @@ FileUtils.rm_rf(Spec::Path.gem_repo1) ENV["RUBYOPT"] = "#{ENV["RUBYOPT"]} -r#{Spec::Path.root}/spec/support/hax.rb" ENV["BUNDLE_SPEC_RUN"] = "true" -ENV["BUNDLE_PLUGINS"] = "true" # Don't wrap output in tests ENV["THOR_COLUMNS"] = "10000"