diff options
author | Samuel Giddins <segiddins@segiddins.me> | 2017-07-18 17:46:34 -0500 |
---|---|---|
committer | Colby Swandale <colby@taplaboratories.com> | 2017-08-20 11:18:13 +1000 |
commit | fd78b296323e4656c2df800cc6100418d0ad9aa7 (patch) | |
tree | c90e5a89101a1d87f679ecfb08174ded9a80c923 | |
parent | aea4046b5b91b83b27f117822e1bd6c614da3e6e (diff) | |
download | bundler-fd78b296323e4656c2df800cc6100418d0ad9aa7.tar.gz |
Ensure deprecations become a hard error in Bundler 2
-rwxr-xr-x | exe/bundle_ruby | 7 | ||||
-rw-r--r-- | lib/bundler.rb | 5 | ||||
-rw-r--r-- | lib/bundler/cli.rb | 4 | ||||
-rw-r--r-- | lib/bundler/cli/console.rb | 2 | ||||
-rw-r--r-- | lib/bundler/cli/install.rb | 2 | ||||
-rw-r--r-- | lib/bundler/cli/update.rb | 2 | ||||
-rw-r--r-- | lib/bundler/deployment.rb | 2 | ||||
-rw-r--r-- | lib/bundler/dsl.rb | 10 | ||||
-rw-r--r-- | lib/bundler/rubygems_integration.rb | 2 | ||||
-rw-r--r-- | lib/bundler/settings.rb | 2 | ||||
-rw-r--r-- | lib/bundler/shared_helpers.rb | 31 | ||||
-rw-r--r-- | lib/bundler/version.rb | 4 | ||||
-rw-r--r-- | spec/other/major_deprecation_spec.rb | 14 |
13 files changed, 51 insertions, 36 deletions
diff --git a/exe/bundle_ruby b/exe/bundle_ruby index 847708c3ea..df6f8cc8a1 100755 --- a/exe/bundle_ruby +++ b/exe/bundle_ruby @@ -1,12 +1,15 @@ #!/usr/bin/env ruby # frozen_string_literal: true +require "bundler/shared_helpers" + +Bundler::SharedHelpers.major_deprecation(2, "the bundle_ruby executable has been removed in favor of `bundle platform --ruby`") + Signal.trap("INT") { exit 1 } require "bundler/errors" require "bundler/ruby_version" require "bundler/ruby_dsl" -require "bundler/shared_helpers" module Bundler class Dsl @@ -42,8 +45,6 @@ module Bundler end end -Bundler::SharedHelpers.major_deprecation("the bundle_ruby executable has been removed in favor of `bundle platform --ruby`") - dsl = Bundler::Dsl.new begin dsl.eval_gemfile(Bundler::SharedHelpers.default_gemfile) diff --git a/lib/bundler.rb b/lib/bundler.rb index e4b9313401..d1be40c2b5 100644 --- a/lib/bundler.rb +++ b/lib/bundler.rb @@ -119,7 +119,7 @@ module Bundler end def environment - SharedHelpers.major_deprecation "Bundler.environment has been removed in favor of Bundler.load" + SharedHelpers.major_deprecation 2, "Bundler.environment has been removed in favor of Bundler.load" load end @@ -267,7 +267,7 @@ EOF # @deprecated Use `original_env` instead # @return [Hash] Environment with all bundler-related variables removed def clean_env - Bundler::SharedHelpers.major_deprecation("`Bundler.clean_env` has weird edge cases, use `.original_env` instead") + Bundler::SharedHelpers.major_deprecation(2, "`Bundler.clean_env` has weird edge cases, use `.original_env` instead") env = original_env if env.key?("BUNDLER_ORIG_MANPATH") @@ -464,6 +464,7 @@ EOF def reset_paths! @bin_path = nil + @bundler_major_version = nil @bundle_path = nil @configured = nil @configured_bundle_path = nil diff --git a/lib/bundler/cli.rb b/lib/bundler/cli.rb index 70d210b9e9..12fe7adf01 100644 --- a/lib/bundler/cli.rb +++ b/lib/bundler/cli.rb @@ -253,7 +253,7 @@ module Bundler method_option "outdated", :type => :boolean, :banner => "Show verbose output including whether gems are outdated." def show(gem_name = nil) - Bundler::SharedHelpers.major_deprecation("use `bundle list` instead of `bundle show`") if ARGV[0] == "show" + Bundler::SharedHelpers.major_deprecation(2, "use `bundle list` instead of `bundle show`") if ARGV[0] == "show" require "bundler/cli/show" Show.new(options, gem_name).run end @@ -536,7 +536,7 @@ module Bundler method_option "group", :type => :string, :banner => "Install gem into a bundler group" def inject(name, version) - SharedHelpers.major_deprecation "The `inject` command has been replaced by the `add` command" + SharedHelpers.major_deprecation 2, "The `inject` command has been replaced by the `add` command" require "bundler/cli/inject" Inject.new(options.dup, name, version).run end diff --git a/lib/bundler/cli/console.rb b/lib/bundler/cli/console.rb index 70a2c90f74..853eca8358 100644 --- a/lib/bundler/cli/console.rb +++ b/lib/bundler/cli/console.rb @@ -9,7 +9,7 @@ module Bundler end def run - Bundler::SharedHelpers.major_deprecation "bundle console will be replaced " \ + Bundler::SharedHelpers.major_deprecation 2, "bundle console will be replaced " \ "by `bin/console` generated by `bundle gem <name>`" group ? Bundler.require(:default, *(group.split.map!(&:to_sym))) : Bundler.require diff --git a/lib/bundler/cli/install.rb b/lib/bundler/cli/install.rb index 771ff6f5dc..5b852dd88c 100644 --- a/lib/bundler/cli/install.rb +++ b/lib/bundler/cli/install.rb @@ -55,7 +55,7 @@ module Bundler Bundler::Fetcher.disable_endpoint = options["full-index"] if options["binstubs"] - Bundler::SharedHelpers.major_deprecation \ + Bundler::SharedHelpers.major_deprecation 2, "The --binstubs option will be removed in favor of `bundle binstubs`" end diff --git a/lib/bundler/cli/update.rb b/lib/bundler/cli/update.rb index 73caae387f..26ee192aa9 100644 --- a/lib/bundler/cli/update.rb +++ b/lib/bundler/cli/update.rb @@ -24,7 +24,7 @@ module Bundler if Bundler.feature_flag.update_requires_all_flag? raise InvalidOption, "To update everything, pass the `--all` flag." end - SharedHelpers.major_deprecation "Pass --all to `bundle update` to update everything" + SharedHelpers.major_deprecation 2, "Pass --all to `bundle update` to update everything" elsif !full_update && options[:all] raise InvalidOption, "Cannot specify --all along with specific options." end diff --git a/lib/bundler/deployment.rb b/lib/bundler/deployment.rb index 94f2fac620..291e158ca0 100644 --- a/lib/bundler/deployment.rb +++ b/lib/bundler/deployment.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true require "bundler/shared_helpers" -Bundler::SharedHelpers.major_deprecation "Bundler no longer integrates with " \ +Bundler::SharedHelpers.major_deprecation 2, "Bundler no longer integrates with " \ "Capistrano, but Capistrano provides its own integration with " \ "Bundler via the capistrano-bundler gem. Use it instead." diff --git a/lib/bundler/dsl.rb b/lib/bundler/dsl.rb index 679c66e711..8681163277 100644 --- a/lib/bundler/dsl.rb +++ b/lib/bundler/dsl.rb @@ -178,7 +178,7 @@ module Bundler " end\n\n" raise DeprecatedError, msg if Bundler.feature_flag.disable_multisource? - SharedHelpers.major_deprecation(msg.strip) + SharedHelpers.major_deprecation(2, msg.strip) end source_options = normalize_hash(options).merge( @@ -290,7 +290,7 @@ module Bundler repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?("/") # TODO: 2.0 upgrade this setting to the default if Bundler.settings["github.https"] - Bundler::SharedHelpers.major_deprecation "The `github.https` setting will be removed" + Bundler::SharedHelpers.major_deprecation 2, "The `github.https` setting will be removed" "https://github.com/#{repo_name}.git" else "git://github.com/#{repo_name}.git" @@ -440,7 +440,7 @@ repo_name ||= user_name def normalize_source(source) case source when :gemcutter, :rubygems, :rubyforge - Bundler::SharedHelpers.major_deprecation "The source :#{source} is deprecated because HTTP " \ + Bundler::SharedHelpers.major_deprecation 2, "The source :#{source} is deprecated because HTTP " \ "requests are insecure.\nPlease change your source to 'https://" \ "rubygems.org' if possible, or 'http://rubygems.org' if not." "http://rubygems.org" @@ -464,7 +464,7 @@ repo_name ||= user_name end raise GemfileEvalError, msg else - Bundler::SharedHelpers.major_deprecation "Your Gemfile contains multiple primary sources. " \ + Bundler::SharedHelpers.major_deprecation 2, "Your Gemfile contains multiple primary sources. " \ "Using `source` more than once without a block is a security risk, and " \ "may result in installing unexpected gems. To resolve this warning, use " \ "a block to indicate which gems should come from the secondary source. " \ @@ -482,7 +482,7 @@ repo_name ||= user_name "do |repo_name|\n#{replacement.to_s.gsub(/^/, " ")}\n end" end - Bundler::SharedHelpers.major_deprecation <<-EOS + Bundler::SharedHelpers.major_deprecation 2, <<-EOS The :#{name} git source is deprecated, and will be removed in Bundler 2.0.#{additional_message} Add this code to the top of your Gemfile to ensure it continues to work: git_source(:#{name}) #{replacement} diff --git a/lib/bundler/rubygems_integration.rb b/lib/bundler/rubygems_integration.rb index 202903d981..3016a19e03 100644 --- a/lib/bundler/rubygems_integration.rb +++ b/lib/bundler/rubygems_integration.rb @@ -456,7 +456,7 @@ module Bundler raise Gem::Exception, "no default executable for #{spec.full_name}" unless exec_name ||= spec.default_executable unless spec.name == exec_name - Bundler::SharedHelpers.major_deprecation \ + Bundler::SharedHelpers.major_deprecation 2, "Bundler is using a binstub that was created for a different gem (#{spec.name}).\n" \ "You should run `bundle binstub #{gem_name}` " \ "to work around a system/bundle conflict." diff --git a/lib/bundler/settings.rb b/lib/bundler/settings.rb index d19cc18dd6..8d4276159b 100644 --- a/lib/bundler/settings.rb +++ b/lib/bundler/settings.rb @@ -103,7 +103,7 @@ module Bundler "bundle config #{key} #{Array(value).join(":")}" end - Bundler::SharedHelpers.major_deprecation \ + Bundler::SharedHelpers.major_deprecation 2,\ "flags passed to commands " \ "will no longer be automatically remembered. Instead please set flags " \ "you want remembered between commands using `bundle config " \ diff --git a/lib/bundler/shared_helpers.rb b/lib/bundler/shared_helpers.rb index ce3286cc28..bef9cc6139 100644 --- a/lib/bundler/shared_helpers.rb +++ b/lib/bundler/shared_helpers.rb @@ -5,6 +5,7 @@ require "bundler/compatibility_guard" require "pathname" require "rubygems" +require "bundler/version" require "bundler/constants" require "bundler/rubygems_integration" require "bundler/current_ruby" @@ -138,20 +139,34 @@ module Bundler namespace.const_get(constant_name) end - def major_deprecation(message) + def major_deprecation(major_version, message) + if Bundler.bundler_major_version >= major_version + require "bundler/errors" + raise DeprecatedError, "[REMOVED FROM #{major_version}.0] #{message}" + end + return unless prints_major_deprecations? @major_deprecation_ui ||= Bundler::UI::Shell.new("no-color" => true) ui = Bundler.ui.is_a?(@major_deprecation_ui.class) ? Bundler.ui : @major_deprecation_ui - ui.warn("[DEPRECATED FOR #{Bundler::VERSION.split(".").first.to_i + 1}.0] #{message}") + ui.warn("[DEPRECATED FOR #{major_version}.0] #{message}") end def print_major_deprecations! - deprecate_gemfile(find_gemfile) if find_gemfile(:order_matters) == find_file("Gemfile") + multiple_gemfiles = search_up(".") do |dir| + gemfiles = gemfile_names.select {|gf| File.file? File.expand_path(gf, dir) } + next if gemfiles.empty? + break false if gemfiles.size == 1 + end + if multiple_gemfiles && Bundler.bundler_major_version == 1 + Bundler::SharedHelpers.major_deprecation 2, \ + "gems.rb and gems.locked will be preferred to Gemfile and Gemfile.lock." + end + if RUBY_VERSION < "2" - major_deprecation("Bundler will only support ruby >= 2.0, you are running #{RUBY_VERSION}") + major_deprecation(2, "Bundler will only support ruby >= 2.0, you are running #{RUBY_VERSION}") end return if Bundler.rubygems.provides?(">= 2") - major_deprecation("Bundler will only support rubygems >= 2.0, you are running #{Bundler.rubygems.version}") + major_deprecation(2, "Bundler will only support rubygems >= 2.0, you are running #{Bundler.rubygems.version}") end def trap(signal, override = false, &block) @@ -330,12 +345,6 @@ module Bundler true end - def deprecate_gemfile(gemfile) - return unless gemfile && File.basename(gemfile) == "Gemfile" - Bundler::SharedHelpers.major_deprecation \ - "gems.rb and gems.locked will be preferred to Gemfile and Gemfile.lock." - end - extend self end end diff --git a/lib/bundler/version.rb b/lib/bundler/version.rb index fe36d4e45b..424965771a 100644 --- a/lib/bundler/version.rb +++ b/lib/bundler/version.rb @@ -21,4 +21,8 @@ module Bundler end private_class_method :overwrite_loaded_gem_version overwrite_loaded_gem_version + + def self.bundler_major_version + @bundler_major_version ||= VERSION.split(".").first.to_i + end end diff --git a/spec/other/major_deprecation_spec.rb b/spec/other/major_deprecation_spec.rb index dada1db317..1f5d16e516 100644 --- a/spec/other/major_deprecation_spec.rb +++ b/spec/other/major_deprecation_spec.rb @@ -137,7 +137,7 @@ RSpec.describe "major deprecations", :bundler => "< 2" do gem "rack" G - expect(warnings).to have_major_deprecation("gems.rb and gems.locked will be preferred to Gemfile and Gemfile.lock.") + expect(warnings).to have_major_deprecation a_string_including("gems.rb and gems.locked will be preferred to Gemfile and Gemfile.lock.") end context "with flags" do @@ -202,7 +202,7 @@ The :github git source is deprecated, and will be removed in Bundler 2.0. Change git_source(:github) {|repo_name| "https://github.com/\#{repo_name}.git" } EOS - expect(Bundler::SharedHelpers).to receive(:major_deprecation).with(msg) + expect(Bundler::SharedHelpers).to receive(:major_deprecation).with(2, msg) subject.gem("sparks", :github => "indirect/sparks") end @@ -214,8 +214,8 @@ The :github git source is deprecated, and will be removed in Bundler 2.0. Change git_source(:github) {|repo_name| "https://github.com/\#{repo_name}.git" } EOS - expect(Bundler::SharedHelpers).to receive(:major_deprecation).with(msg) - expect(Bundler::SharedHelpers).to receive(:major_deprecation).with("The `github.https` setting will be removed") + expect(Bundler::SharedHelpers).to receive(:major_deprecation).with(2, msg) + expect(Bundler::SharedHelpers).to receive(:major_deprecation).with(2, "The `github.https` setting will be removed") subject.gem("sparks", :github => "indirect/sparks") github_uri = "https://github.com/indirect/sparks.git" expect(subject.dependencies.first.source.uri).to eq(github_uri) @@ -235,7 +235,7 @@ The :bitbucket git source is deprecated, and will be removed in Bundler 2.0. Add end EOS - expect(Bundler::SharedHelpers).to receive(:major_deprecation).with(msg) + expect(Bundler::SharedHelpers).to receive(:major_deprecation).with(2, msg) subject.gem("not-really-a-gem", :bitbucket => "mcorp/flatlab-rails") end end @@ -247,7 +247,7 @@ The :bitbucket git source is deprecated, and will be removed in Bundler 2.0. Add "in Bundler 2.0. Add this code to the top of your Gemfile to ensure it " \ "continues to work:\n\n git_source(:gist) {|repo_name| " \ "\"https://gist.github.com/\#{repo_name}.git\" }\n\n" - expect(Bundler::SharedHelpers).to receive(:major_deprecation).with(msg) + expect(Bundler::SharedHelpers).to receive(:major_deprecation).with(2, msg) subject.gem("not-really-a-gem", :gist => "1234") end end @@ -264,7 +264,7 @@ The :bitbucket git source is deprecated, and will be removed in Bundler 2.0. Add warnings.gsub!(/gems included.*?\[DEPRECATED/im, "[DEPRECATED") - expect(warnings).to have_major_deprecation("use `bundle list` instead of `bundle show`") + expect(warnings).to have_major_deprecation a_string_including("use `bundle list` instead of `bundle show`") end end |