summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHomu <homu@barosl.com>2016-06-24 11:15:17 +0900
committerSamuel Giddins <segiddins@segiddins.me>2016-06-27 16:17:38 -0500
commit0f441e83fe4988d86c928aad0fe6f6cb908c6aab (patch)
tree0e39d063166eca73d1f5d8274ff266485edcb831
parent63622905967db5766305df374d19eda9d4045776 (diff)
downloadbundler-0f441e83fe4988d86c928aad0fe6f6cb908c6aab.tar.gz
Auto merge of #4702 - bundler:seg-major-deprecations, r=indirect
Add machinery for printing major deprecations First step towards handling all of #4695 \c @RochesterinNYC @indirect (cherry picked from commit dca6d26833ddd9d9de658bef7274c8fa21014c44)
-rwxr-xr-xexe/bundle_ruby6
-rw-r--r--lib/bundler.rb3
-rw-r--r--lib/bundler/cli.rb2
-rw-r--r--lib/bundler/deprecate.rb16
-rw-r--r--lib/bundler/dsl.rb2
-rw-r--r--lib/bundler/settings.rb30
-rw-r--r--lib/bundler/shared_helpers.rb23
-rw-r--r--lib/bundler/ui/shell.rb16
-rw-r--r--lib/bundler/ui/silent.rb3
-rw-r--r--spec/other/bundle_ruby_spec.rb16
-rw-r--r--spec/other/major_deprecation_spec.rb78
11 files changed, 165 insertions, 30 deletions
diff --git a/exe/bundle_ruby b/exe/bundle_ruby
index 49767304e2..847708c3ea 100755
--- a/exe/bundle_ruby
+++ b/exe/bundle_ruby
@@ -3,14 +3,12 @@
Signal.trap("INT") { exit 1 }
+require "bundler/errors"
require "bundler/ruby_version"
require "bundler/ruby_dsl"
require "bundler/shared_helpers"
module Bundler
- class GemfileError < RuntimeError; end
- class GemfileEvalError < GemfileError; end
-
class Dsl
include RubyDsl
@@ -44,7 +42,7 @@ module Bundler
end
end
-STDERR.puts "Warning: bundle_ruby will be deprecated in Bundler 2.0.0."
+Bundler::SharedHelpers.major_deprecation("the bundle_ruby executable has been removed in favor of `bundle platform --ruby`")
dsl = Bundler::Dsl.new
begin
diff --git a/lib/bundler.rb b/lib/bundler.rb
index 9cfc7157b5..4aa0abe26f 100644
--- a/lib/bundler.rb
+++ b/lib/bundler.rb
@@ -92,6 +92,8 @@ module Bundler
definition.validate_ruby!
+ SharedHelpers.print_major_deprecations!
+
if groups.empty?
# Load all groups, but only once
@setup = load.setup
@@ -209,6 +211,7 @@ module Bundler
# @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")
env = original_env
if env.key?("BUNDLE_ORIG_MANPATH")
diff --git a/lib/bundler/cli.rb b/lib/bundler/cli.rb
index c3a9a01e2b..1fb4b1bd41 100644
--- a/lib/bundler/cli.rb
+++ b/lib/bundler/cli.rb
@@ -12,6 +12,8 @@ module Bundler
rescue Exception => e
Bundler.ui = UI::Shell.new
raise e
+ ensure
+ Bundler::SharedHelpers.print_major_deprecations!
end
def initialize(*args)
diff --git a/lib/bundler/deprecate.rb b/lib/bundler/deprecate.rb
index 1ab4de1a28..b978c0df6c 100644
--- a/lib/bundler/deprecate.rb
+++ b/lib/bundler/deprecate.rb
@@ -10,7 +10,23 @@ module Bundler
unless Deprecate.respond_to?(:skip_during)
def Deprecate.skip_during
+ original = skip
+ self.skip = true
yield
+ ensure
+ self.skip = original
+ end
+ end
+
+ unless Deprecate.respond_to?(:skip)
+ def Deprecate.skip
+ @skip
+ end
+ end
+
+ unless Deprecate.respond_to?(:skip=)
+ def Deprecate.skip=(skip)
+ @skip = skip
end
end
end
diff --git a/lib/bundler/dsl.rb b/lib/bundler/dsl.rb
index 4208f9b575..358784a9de 100644
--- a/lib/bundler/dsl.rb
+++ b/lib/bundler/dsl.rb
@@ -374,7 +374,7 @@ module Bundler
def normalize_source(source)
case source
when :gemcutter, :rubygems, :rubyforge
- Bundler.ui.warn "The source :#{source} is deprecated because HTTP " \
+ Bundler::SharedHelpers.major_deprecation "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"
diff --git a/lib/bundler/settings.rb b/lib/bundler/settings.rb
index 0dd1d762e6..46333c8986 100644
--- a/lib/bundler/settings.rb
+++ b/lib/bundler/settings.rb
@@ -3,9 +3,33 @@ require "uri"
module Bundler
class Settings
- BOOL_KEYS = %w(frozen cache_all no_prune disable_local_branch_check disable_shared_gems ignore_messages gem.mit gem.coc silence_root_warning no_install plugins).freeze
- NUMBER_KEYS = %w(retry timeout redirect ssl_verify_mode).freeze
- DEFAULT_CONFIG = { :retry => 3, :timeout => 10, :redirect => 5 }.freeze
+ BOOL_KEYS = %w(
+ cache_all
+ disable_local_branch_check
+ disable_shared_gems
+ frozen
+ gem.coc
+ gem.mit
+ ignore_messages
+ major_deprecations
+ no_install
+ no_prune
+ plugins
+ silence_root_warning
+ ).freeze
+
+ NUMBER_KEYS = %w(
+ redirect
+ retry
+ ssl_verify_mode
+ timeout
+ ).freeze
+
+ DEFAULT_CONFIG = {
+ :redirect => 5,
+ :retry => 3,
+ :timeout => 10,
+ }.freeze
def initialize(root = nil)
@root = root
diff --git a/lib/bundler/shared_helpers.rb b/lib/bundler/shared_helpers.rb
index 01f1118d7b..df0fffbaed 100644
--- a/lib/bundler/shared_helpers.rb
+++ b/lib/bundler/shared_helpers.rb
@@ -120,6 +120,21 @@ module Bundler
namespace.const_get(constant_name)
end
+ def major_deprecation(message)
+ 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}")
+ end
+
+ def print_major_deprecations!
+ if RUBY_VERSION < "2"
+ major_deprecation("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}")
+ end
+
private
def find_gemfile
@@ -207,6 +222,14 @@ module Bundler
end
end
+ def prints_major_deprecations?
+ require "bundler"
+ return false unless Bundler.settings[:major_deprecations]
+ require "bundler/deprecate"
+ return false if Bundler::Deprecate.skip
+ true
+ end
+
extend self
end
end
diff --git a/lib/bundler/ui/shell.rb b/lib/bundler/ui/shell.rb
index 1317b1838a..df41d72768 100644
--- a/lib/bundler/ui/shell.rb
+++ b/lib/bundler/ui/shell.rb
@@ -79,12 +79,8 @@ module Bundler
tell_me(msg, nil, newline)
end
- def silence
- old_level = @level
- @level = "silent"
- yield
- ensure
- @level = old_level
+ def silence(&blk)
+ with_level("silent", &blk)
end
private
@@ -109,6 +105,14 @@ module Bundler
line.length > line_width ? line.gsub(/(.{1,#{line_width}})(\s+|$)/, "\\1\n").strip : line
end * "\n"
end
+
+ def with_level(level)
+ original = @level
+ @level = level
+ yield
+ ensure
+ @level = original
+ end
end
end
end
diff --git a/lib/bundler/ui/silent.rb b/lib/bundler/ui/silent.rb
index af512eced3..02978fc686 100644
--- a/lib/bundler/ui/silent.rb
+++ b/lib/bundler/ui/silent.rb
@@ -40,6 +40,9 @@ module Bundler
def trace(message, newline = nil)
end
+ def major_deprecation(message)
+ end
+
def silence
yield
end
diff --git a/spec/other/bundle_ruby_spec.rb b/spec/other/bundle_ruby_spec.rb
index 88cd8a7e03..9847aded62 100644
--- a/spec/other/bundle_ruby_spec.rb
+++ b/spec/other/bundle_ruby_spec.rb
@@ -2,22 +2,6 @@
require "spec_helper"
describe "bundle_ruby" do
- context "when run" do
- it "displays a deprecation warning" do
- gemfile <<-G
- source "file://#{gem_repo1}"
- ruby "1.9.3", :engine => 'ruby', :engine_version => '1.9.3'
-
- gem "foo"
- G
-
- bundle_ruby :expect_err => true
-
- expect(err).to eq("Warning: bundle_ruby will be deprecated in " \
- "Bundler 2.0.0.")
- end
- end
-
context "without patchlevel" do
it "returns the ruby version" do
gemfile <<-G
diff --git a/spec/other/major_deprecation_spec.rb b/spec/other/major_deprecation_spec.rb
new file mode 100644
index 0000000000..a3d8fd12f4
--- /dev/null
+++ b/spec/other/major_deprecation_spec.rb
@@ -0,0 +1,78 @@
+# frozen_string_literal: true
+require "spec_helper"
+
+describe "major deprecations" do
+ matcher :have_major_deprecation do |expected|
+ diffable
+ match do |actual|
+ actual.split(/^\[DEPRECATED FOR 2\.0\]\s*/).any? do |d|
+ !d.empty? && values_match?(expected, d.strip)
+ end
+ end
+ end
+
+ let(:warnings) { out } # change to err in 2.0
+
+ before do
+ bundle "config major_deprecations true"
+
+ install_gemfile <<-G
+ source "file:#{gem_repo1}"
+ ruby #{RUBY_VERSION.dump}
+ gem "rack"
+ G
+ end
+
+ describe "bundle_ruby" do
+ it "prints a deprecation" do
+ bundle_ruby :expect_err => true
+ out.gsub! "\nruby #{RUBY_VERSION}", ""
+ expect(warnings).to have_major_deprecation "the bundle_ruby executable has been removed in favor of `bundle platform --ruby`"
+ end
+ end
+
+ describe "Bundler" do
+ describe ".clean_env" do
+ it "is deprecated in favor of .original_env" do
+ source = "Bundler.clean_env"
+ bundle "exec ruby -e #{source.dump}"
+ expect(warnings).to have_major_deprecation "`Bundler.clean_env` has weird edge cases, use `.original_env` instead"
+ end
+ end
+
+ shared_examples_for "environmental deprecations" do |trigger|
+ describe "ruby version", :ruby => "< 2.0" do
+ it "requires a newer ruby version" do
+ instance_eval(&trigger)
+ expect(warnings).to have_major_deprecation "Bundler will only support ruby >= 2.0, you are running #{RUBY_VERSION}"
+ end
+ end
+
+ describe "rubygems version", :rubygems => "< 2.0" do
+ it "requires a newer rubygems version" do
+ instance_eval(&trigger)
+ expect(warnings).to have_major_deprecation "Bundler will only support rubygems >= 2.0, you are running #{Gem::VERSION}"
+ end
+ end
+ end
+
+ describe "-rbundler/setup" do
+ it_behaves_like "environmental deprecations", proc { ruby "require 'bundler/setup'" }
+ end
+
+ describe "Bundler.setup" do
+ it_behaves_like "environmental deprecations", proc { ruby "require 'bundler'; Bundler.setup" }
+ end
+
+ describe "bundle check" do
+ it_behaves_like "environmental deprecations", proc { bundle :check }
+ end
+
+ describe "bundle update --quiet" do
+ it "does not print any deprecations" do
+ bundle :update, :quiet => true
+ expect(warnings).not_to have_major_deprecation
+ end
+ end
+ end
+end