diff options
author | Samuel Giddins <segiddins@segiddins.me> | 2017-07-06 09:21:27 +0200 |
---|---|---|
committer | Samuel Giddins <segiddins@segiddins.me> | 2017-07-12 15:09:55 -0500 |
commit | 6b2d04b892dfa9ac9b93d4cba80d59195d71449f (patch) | |
tree | fc99fb5c6659ca428fa0cea10d7ae96ead41bffb | |
parent | 0d84c9c5156df8f722e91e961a63849b51a4ed11 (diff) | |
download | bundler-6b2d04b892dfa9ac9b93d4cba80d59195d71449f.tar.gz |
Use deployment instead of frozen as a setting on Bundler 2
-rw-r--r-- | lib/bundler.rb | 6 | ||||
-rw-r--r-- | lib/bundler/cli/check.rb | 2 | ||||
-rw-r--r-- | lib/bundler/cli/install.rb | 14 | ||||
-rw-r--r-- | lib/bundler/cli/outdated.rb | 2 | ||||
-rw-r--r-- | lib/bundler/definition.rb | 13 | ||||
-rw-r--r-- | lib/bundler/feature_flag.rb | 1 | ||||
-rw-r--r-- | lib/bundler/injector.rb | 46 | ||||
-rw-r--r-- | lib/bundler/installer.rb | 4 | ||||
-rw-r--r-- | lib/bundler/runtime.rb | 2 | ||||
-rw-r--r-- | lib/bundler/settings.rb | 2 | ||||
-rw-r--r-- | man/bundle-config.ronn | 2 | ||||
-rw-r--r-- | spec/bundler/settings_spec.rb | 16 | ||||
-rw-r--r-- | spec/commands/add_spec.rb | 2 | ||||
-rw-r--r-- | spec/quality_spec.rb | 1 |
14 files changed, 74 insertions, 39 deletions
diff --git a/lib/bundler.rb b/lib/bundler.rb index b0f6869423..068970fbc6 100644 --- a/lib/bundler.rb +++ b/lib/bundler.rb @@ -130,6 +130,12 @@ module Bundler end end + def frozen? + frozen = settings[:deployment] + frozen ||= settings[:frozen] unless feature_flag.deployment_means_frozen? + frozen + end + def locked_gems @locked_gems ||= if defined?(@definition) && @definition diff --git a/lib/bundler/cli/check.rb b/lib/bundler/cli/check.rb index 057a7e5695..96781b6c3a 100644 --- a/lib/bundler/cli/check.rb +++ b/lib/bundler/cli/check.rb @@ -28,7 +28,7 @@ module Bundler not_installed.each {|s| Bundler.ui.error " * #{s.name} (#{s.version})" } Bundler.ui.warn "Install missing gems with `bundle install`" exit 1 - elsif !Bundler.default_lockfile.file? && Bundler.settings[:frozen] + elsif !Bundler.default_lockfile.file? && Bundler.frozen? Bundler.ui.error "This bundle has been frozen, but there is no #{Bundler.default_lockfile.relative_path_from(SharedHelpers.pwd)} present" exit 1 else diff --git a/lib/bundler/cli/install.rb b/lib/bundler/cli/install.rb index 0592385e23..3ff3438baf 100644 --- a/lib/bundler/cli/install.rb +++ b/lib/bundler/cli/install.rb @@ -32,17 +32,19 @@ module Bundler check_trust_policy - if options[:deployment] || options[:frozen] + if options[:deployment] || options[:frozen] || Bundler.frozen? unless Bundler.default_lockfile.exist? - flag = options[:deployment] ? "--deployment" : "--frozen" - raise ProductionError, "The #{flag} flag requires a #{Bundler.default_lockfile.relative_path_from(SharedHelpers.pwd)}. Please make " \ + flag = "--deployment flag" if options[:deployment] + flag ||= "--frozen flag" if options[:frozen] + flag ||= "deployment setting" + raise ProductionError, "The #{flag} requires a #{Bundler.default_lockfile.relative_path_from(SharedHelpers.pwd)}. Please make " \ "sure you have checked your #{Bundler.default_lockfile.relative_path_from(SharedHelpers.pwd)} into version control " \ "before deploying." end options[:local] = true if Bundler.app_cache.exist? - Bundler.settings[:frozen] = "1" + Bundler.settings[:frozen] = true unless Bundler.feature_flag.deployment_means_frozen? end # When install is called with --no-deployment, disable deployment mode @@ -66,7 +68,7 @@ module Bundler definition.validate_runtime! installer = Installer.install(Bundler.root, definition, options) - Bundler.load.cache if Bundler.app_cache.exist? && !options["no-cache"] && !Bundler.settings[:frozen] + Bundler.load.cache if Bundler.app_cache.exist? && !options["no-cache"] && !Bundler.frozen? Bundler.ui.confirm "Bundle complete! #{dependencies_count_for(definition)}, #{gems_installed_for(definition)}." Bundler::CLI::Common.output_without_groups_message @@ -175,7 +177,7 @@ module Bundler def normalize_settings Bundler.settings[:path] = nil if options[:system] - Bundler.settings[:path] = "vendor/bundle" if options[:deployment] + Bundler.settings[:path] = "vendor/bundle" if options[:deployment] && !Bundler.feature_flag.deployment_means_frozen? Bundler.settings[:path] = options["path"] if options["path"] Bundler.settings[:path] ||= "bundle" if options["standalone"] diff --git a/lib/bundler/cli/outdated.rb b/lib/bundler/cli/outdated.rb index 62cfc3d28c..20d6ed01fa 100644 --- a/lib/bundler/cli/outdated.rb +++ b/lib/bundler/cli/outdated.rb @@ -214,7 +214,7 @@ module Bundler end def check_for_deployment_mode - if Bundler.settings[:frozen] + if Bundler.frozen? raise ProductionError, "You are trying to check outdated gems in " \ "deployment mode. Run `bundle outdated` elsewhere.\n" \ "\nIf this is a development machine, remove the " \ diff --git a/lib/bundler/definition.rb b/lib/bundler/definition.rb index bf0316b8d8..074291414b 100644 --- a/lib/bundler/definition.rb +++ b/lib/bundler/definition.rb @@ -102,7 +102,7 @@ module Bundler end @unlocking ||= @unlock[:ruby] ||= (!@locked_ruby_version ^ !@ruby_version) - add_current_platform unless Bundler.settings[:frozen] + add_current_platform unless Bundler.frozen? converge_path_sources_to_gemspec_sources @path_changes = converge_paths @@ -234,7 +234,10 @@ module Bundler def resolve @resolve ||= begin last_resolve = converge_locked_specs - if Bundler.settings[:frozen] || (!unlocking? && nothing_changed?) + if Bundler.frozen? + Bundler.ui.debug "Frozen, using resolution from the lockfile" + last_resolve + elsif !unlocking? && nothing_changed? Bundler.ui.debug("Found no changes, using resolution from the lockfile") last_resolve else @@ -319,10 +322,10 @@ module Bundler end end - preserve_unknown_sections ||= !updating_major && (Bundler.settings[:frozen] || !unlocking?) + preserve_unknown_sections ||= !updating_major && (Bundler.frozen? || !unlocking?) return if lockfiles_equal?(@lockfile_contents, contents, preserve_unknown_sections) - if Bundler.settings[:frozen] + if Bundler.frozen? Bundler.ui.error "Cannot write a changed lockfile while frozen." return end @@ -660,7 +663,7 @@ module Bundler end def converge_dependencies - frozen = Bundler.settings[:frozen] + frozen = Bundler.frozen? (@dependencies + @locked_deps.values).each do |dep| locked_source = @locked_deps[dep.name] # This is to make sure that if bundler is installing in deployment mode and diff --git a/lib/bundler/feature_flag.rb b/lib/bundler/feature_flag.rb index c8c5894c96..2d054c2856 100644 --- a/lib/bundler/feature_flag.rb +++ b/lib/bundler/feature_flag.rb @@ -30,6 +30,7 @@ module Bundler settings_flag(:allow_offline_install) { bundler_2_mode? } settings_flag(:cache_command_is_package) { bundler_2_mode? } settings_flag(:console_command) { !bundler_2_mode? } + settings_flag(:deployment_means_frozen) { bundler_2_mode? } settings_flag(:disable_multisource) { bundler_2_mode? } settings_flag(:error_on_stderr) { bundler_2_mode? } settings_flag(:global_gem_cache) { bundler_2_mode? } diff --git a/lib/bundler/injector.rb b/lib/bundler/injector.rb index cba1b3d5e5..d0cece2869 100644 --- a/lib/bundler/injector.rb +++ b/lib/bundler/injector.rb @@ -12,38 +12,40 @@ module Bundler end def inject(gemfile_path, lockfile_path) - if Bundler.settings[:frozen] + if Bundler.frozen? # ensure the lock and Gemfile are synced Bundler.definition.ensure_equivalent_gemfile_and_lockfile(true) - # temporarily remove frozen while we inject - frozen = Bundler.settings.delete(:frozen) end - # evaluate the Gemfile we have now - builder = Dsl.new - builder.eval_gemfile(gemfile_path) + # temporarily unfreeze + Bundler.settings.temporary(:deployment => false, :frozen => false) do + # evaluate the Gemfile we have now + builder = Dsl.new + builder.eval_gemfile(gemfile_path) - # don't inject any gems that are already in the Gemfile - @new_deps -= builder.dependencies + # don't inject any gems that are already in the Gemfile + @new_deps -= builder.dependencies - # add new deps to the end of the in-memory Gemfile - # Set conservative versioining to false because we want to let the resolver resolve the version first - builder.eval_gemfile("injected gems", build_gem_lines(false)) if @new_deps.any? + # add new deps to the end of the in-memory Gemfile + # Set conservative versioning to false because we want to let the resolver resolve the version first + builder.eval_gemfile("injected gems", build_gem_lines(false)) if @new_deps.any? - # resolve to see if the new deps broke anything - @definition = builder.to_definition(lockfile_path, {}) - @definition.resolve_remotely! + # resolve to see if the new deps broke anything + @definition = builder.to_definition(lockfile_path, {}) + @definition.resolve_remotely! - # since nothing broke, we can add those gems to the gemfile - append_to(gemfile_path, build_gem_lines(@options[:conservative_versioning])) if @new_deps.any? + # since nothing broke, we can add those gems to the gemfile + append_to(gemfile_path, build_gem_lines(@options[:conservative_versioning])) if @new_deps.any? - # since we resolved successfully, write out the lockfile - @definition.lock(Bundler.default_lockfile) + # since we resolved successfully, write out the lockfile + @definition.lock(Bundler.default_lockfile) - # return an array of the deps that we added - return @new_deps - ensure - Bundler.settings[:frozen] = "1" if frozen + # invalidate the cached Bundler.definition + Bundler.reset_paths! + + # return an array of the deps that we added + @new_deps + end end private diff --git a/lib/bundler/installer.rb b/lib/bundler/installer.rb index 78a73eeedd..084c49cb47 100644 --- a/lib/bundler/installer.rb +++ b/lib/bundler/installer.rb @@ -68,7 +68,7 @@ module Bundler def run(options) create_bundle_path - if Bundler.settings[:frozen] + if Bundler.frozen? @definition.ensure_equivalent_gemfile_and_lockfile(options[:deployment]) end @@ -83,7 +83,7 @@ module Bundler warn_on_incompatible_bundler_deps install(options) - lock unless Bundler.settings[:frozen] + lock unless Bundler.frozen? Standalone.new(options[:standalone], @definition).generate if options[:standalone] end diff --git a/lib/bundler/runtime.rb b/lib/bundler/runtime.rb index 152471db85..c8f5b8496d 100644 --- a/lib/bundler/runtime.rb +++ b/lib/bundler/runtime.rb @@ -11,7 +11,7 @@ module Bundler end def setup(*groups) - @definition.ensure_equivalent_gemfile_and_lockfile if Bundler.settings[:frozen] + @definition.ensure_equivalent_gemfile_and_lockfile if Bundler.frozen? groups.map!(&:to_sym) diff --git a/lib/bundler/settings.rb b/lib/bundler/settings.rb index 9bce931734..45934f2944 100644 --- a/lib/bundler/settings.rb +++ b/lib/bundler/settings.rb @@ -14,6 +14,8 @@ module Bundler cache_all_platforms cache_command_is_package console_command + deployment + deployment_means_frozen disable_checksum_validation disable_exec_load disable_local_branch_check diff --git a/man/bundle-config.ronn b/man/bundle-config.ronn index 1260e9692b..c1e9f8e997 100644 --- a/man/bundle-config.ronn +++ b/man/bundle-config.ronn @@ -138,6 +138,8 @@ learn more about their operation in [bundle install(1)][bundle-install]. `bundle install`. * `console` (`BUNDLE_CONSOLE`): The console that `bundle console` starts. Defaults to `irb`. +* `deployment` (`BUNDLE_DEPLOYMENT`): + Disallow changes to the `Gemfile`. * `disable_checksum_validation` (`BUNDLE_DISABLE_CHECKSUM_VALIDATION`): Allow installing gems even if they do not match the checksum provided by RubyGems. diff --git a/spec/bundler/settings_spec.rb b/spec/bundler/settings_spec.rb index d680ab3f3e..cdc6745d39 100644 --- a/spec/bundler/settings_spec.rb +++ b/spec/bundler/settings_spec.rb @@ -137,6 +137,22 @@ that would suck --ehhh=oh geez it looks like i might have broken bundler somehow expect(Bundler.settings[:no_install]).to eq true end + + it "returns the return value of the block" do + ret = Bundler.settings.temporary({}) { :ret } + expect(ret).to eq :ret + end + + context "when called without a block" do + it "leaves the setting changed" do + Bundler.settings.temporary(:foo => :random) + expect(Bundler.settings[:foo]).to eq :random + end + + it "returns nil" do + expect(Bundler.settings.temporary(:foo => :bar)).to be_nil + end + end end describe "#set_global" do diff --git a/spec/commands/add_spec.rb b/spec/commands/add_spec.rb index aebe8442d1..7916db960a 100644 --- a/spec/commands/add_spec.rb +++ b/spec/commands/add_spec.rb @@ -81,7 +81,7 @@ RSpec.describe "bundle add" do it "using combination of short form options works like long form" do bundle "add 'foo' -s='file://#{gem_repo2}' -g='development' -v='~>1.0'" - expect(bundled_app("Gemfile").read).to match(%r{gem "foo", "~> 1.0", :group => \[:development\], :source => "file:\/\/#{gem_repo2}"}) + expect(bundled_app("Gemfile").read).to include %(gem "foo", "~> 1.0", :group => [:development], :source => "file://#{gem_repo2}") expect(the_bundle).to include_gems "foo 1.1" end diff --git a/spec/quality_spec.rb b/spec/quality_spec.rb index 247063b3cf..8c90b33158 100644 --- a/spec/quality_spec.rb +++ b/spec/quality_spec.rb @@ -172,6 +172,7 @@ RSpec.describe "The library itself" do cache_command_is_package console_command default_cli_command + deployment_means_frozen gem.coc gem.mit inline |