Skip to content
This repository was archived by the owner on Apr 14, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/bundler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ def user_cache

def root
@root ||= begin
default_gemfile.dirname.expand_path
SharedHelpers.root
rescue GemfileNotFound
bundle_dir = default_bundle_dir
raise GemfileNotFound, "Could not locate Gemfile or .bundle/ directory" unless bundle_dir
Expand Down
1 change: 1 addition & 0 deletions lib/bundler/feature_flag.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def self.settings_flag(flag, &default)
settings_flag(:init_gems_rb) { bundler_2_mode? }
settings_flag(:only_update_to_newer_versions) { bundler_2_mode? }
settings_flag(:plugins) { @bundler_version >= Gem::Version.new("1.14") }
settings_flag(:prefer_gems_rb) { bundler_2_mode? }
settings_flag(:update_requires_all_flag) { bundler_2_mode? }

def initialize(bundler_version)
Expand Down
1 change: 1 addition & 0 deletions lib/bundler/settings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class Settings
no_prune
only_update_to_newer_versions
plugins
prefer_gems_rb
silence_root_warning
update_requires_all_flag
].freeze
Expand Down
22 changes: 17 additions & 5 deletions lib/bundler/shared_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,15 @@ def requirement

module Bundler
module SharedHelpers
def default_gemfile
def root
gemfile = find_gemfile
raise GemfileNotFound, "Could not locate Gemfile" unless gemfile
Pathname.new(gemfile).untaint.expand_path.parent
end

def default_gemfile
gemfile = find_gemfile(:order_matters)
raise GemfileNotFound, "Could not locate Gemfile" unless gemfile
Pathname.new(gemfile).untaint
end

Expand Down Expand Up @@ -137,7 +143,7 @@ def major_deprecation(message)
end

def print_major_deprecations!
deprecate_gemfile(find_gemfile) if find_gemfile == find_file("Gemfile")
deprecate_gemfile(find_gemfile) if find_gemfile(:order_matters) == find_file("Gemfile")
if RUBY_VERSION < "2"
major_deprecation("Bundler will only support ruby >= 2.0, you are running #{RUBY_VERSION}")
end
Expand Down Expand Up @@ -172,10 +178,16 @@ def ensure_same_dependencies(spec, old_deps, new_deps)

private

def find_gemfile
def find_gemfile(order_matters = false)
given = ENV["BUNDLE_GEMFILE"]
return given if given && !given.empty?
find_file("Gemfile", "gems.rb")
names = gemfile_names
names.reverse! if order_matters && Bundler.feature_flag.prefer_gems_rb?
find_file(*names)
end

def gemfile_names
["Gemfile", "gems.rb"]
end

def find_file(*names)
Expand Down Expand Up @@ -228,7 +240,7 @@ def set_bundle_variables
end

# Set BUNDLE_GEMFILE
Bundler::SharedHelpers.set_env "BUNDLE_GEMFILE", find_gemfile.to_s
Bundler::SharedHelpers.set_env "BUNDLE_GEMFILE", find_gemfile(:order_matters).to_s
Bundler::SharedHelpers.set_env "BUNDLER_VERSION", Bundler::VERSION
end

Expand Down
6 changes: 4 additions & 2 deletions man/bundle-config.ronn
Original file line number Diff line number Diff line change
Expand Up @@ -223,9 +223,11 @@ learn more about their operation in [bundle install(1)][bundle-install].
Sets the `--key` parameter for `gem push` when using the `rake release`
command with a private gemstash server.
* `error_on_stderr` (`BUNDLE_ERROR_ON_STDERR`)
Print Bundler errors to stderr
Print Bundler errors to stderr.
* `init_gems_rb` (`BUNDLE_NEW_GEMFILE_NAME`)
generate a new gems.rb on `bundle init` instead of the `Gemfile`
Generate a `gems.rb` instead of a `Gemfile` when running `bundle init`.
* `prefer_gems_rb` (`BUNDLE_PREFER_GEMS_RB`)
Prefer `gems.rb` to `Gemfile` when Bundler is searching for a Gemfile.
* `update_requires_all_flag` (`BUNDLE_UPDATE_REQUIRES_ALL_FLAG`)
Require passing `--all` to `bundle update` when everything should be updated,
and disallow passing no options to `bundle update`.
Expand Down
2 changes: 1 addition & 1 deletion spec/bundler/definition_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
describe "#lock" do
before do
allow(Bundler).to receive(:settings) { Bundler::Settings.new(".") }
allow(Bundler).to receive(:default_gemfile) { Pathname.new("Gemfile") }
allow(Bundler::SharedHelpers).to receive(:find_gemfile) { Pathname.new("Gemfile") }
allow(Bundler).to receive(:ui) { double("UI", :info => "", :debug => "") }
end
context "when it's not possible to write to the file" do
Expand Down
16 changes: 16 additions & 0 deletions spec/install/gemfile_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,22 @@
end
end

context "with prefer_gems_rb set" do
before { bundle! "config prefer_gems_rb true" }

it "prefers gems.rb to Gemfile" do
create_file("gems.rb", "gem 'bundler'")
create_file("Gemfile", "raise 'wrong Gemfile!'")

bundle! :install

expect(bundled_app("gems.rb")).to be_file
expect(bundled_app("Gemfile.lock")).not_to be_file

expect(the_bundle).to include_gem "bundler #{Bundler::VERSION}"
end
end

context "with engine specified in symbol" do
it "does not raise any error parsing Gemfile" do
simulate_ruby_version "2.3.0" do
Expand Down