Skip to content
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
1 change: 1 addition & 0 deletions bundler/lib/bundler/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ def remove(*gems)
method_option "local", type: :boolean, banner: "Do not attempt to fetch gems remotely and use the gem cache instead"
method_option "prefer-local", type: :boolean, banner: "Only attempt to fetch gems remotely if not present locally, even if newer versions are available remotely"
method_option "no-cache", type: :boolean, banner: "Don't update the existing gem cache."
method_option "no-lock", type: :boolean, banner: "Don't create a lockfile."

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm curious, would people have a desire to see a CLI option to expose a --lockfile option? Similar to how we expose a --gemfile option. This might be a good "nice to have" for a follow-up PR rather than blocking this one.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That could be useful. But I agree it may be better to do in a follow-up PR.

method_option "force", type: :boolean, aliases: "--redownload", banner: "Force reinstalling every gem, even if already installed"
method_option "no-prune", type: :boolean, banner: "Don't remove stale gems from the cache (removed)."
method_option "path", type: :string, banner: "Specify a different path than the system default, namely, $BUNDLE_PATH or $GEM_HOME (removed)."
Expand Down
1 change: 1 addition & 0 deletions bundler/lib/bundler/cli/install.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ def run
# (rather than some optimizations we perform at app runtime).
definition = Bundler.definition(strict: true)
definition.validate_runtime!
definition.lockfile = false if options["no-lock"]

installer = Installer.install(Bundler.root, definition, options)

Expand Down
4 changes: 3 additions & 1 deletion bundler/lib/bundler/definition.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ class << self
attr_accessor :no_lock
end

attr_writer :lockfile

attr_reader(
:dependencies,
:locked_checksums,
Expand Down Expand Up @@ -379,7 +381,7 @@ def lock(file_or_preserve_unknown_sections = false, preserve_unknown_sections_or
end

def write_lock(file, preserve_unknown_sections)
return if Definition.no_lock || file.nil?
return if Definition.no_lock || !lockfile || file.nil?

contents = to_lock

Expand Down
14 changes: 13 additions & 1 deletion bundler/lib/bundler/dsl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ class Dsl

def self.evaluate(gemfile, lockfile, unlock)
builder = new
builder.lockfile(lockfile)
builder.eval_gemfile(gemfile)
builder.to_definition(lockfile, unlock)
builder.to_definition(builder.lockfile_path, unlock)
end

VALID_PLATFORMS = Bundler::CurrentRuby::PLATFORM_MAP.keys.freeze
Expand Down Expand Up @@ -38,6 +39,7 @@ def initialize
@gemspecs = []
@gemfile = nil
@gemfiles = []
@lockfile = nil
add_git_sources
end

Expand Down Expand Up @@ -101,6 +103,15 @@ def gem(name, *args)
add_dependency(name, version, options)
end

# For usage in Dsl.evaluate, since lockfile is used as part of the Gemfile.
def lockfile_path
@lockfile
end

def lockfile(file)
@lockfile = file
end

def source(source, *args, &blk)
options = args.last.is_a?(Hash) ? args.pop.dup : {}
options = normalize_hash(options)
Expand Down Expand Up @@ -175,6 +186,7 @@ def github(repo, options = {})

def to_definition(lockfile, unlock)
check_primary_source_safety
lockfile = @lockfile unless @lockfile.nil?
Definition.new(lockfile, @dependencies, @sources, unlock, @ruby_version, @optional_groups, @gemfiles)
end

Expand Down
1 change: 1 addition & 0 deletions bundler/lib/bundler/environment_preserver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ class EnvironmentPreserver
BUNDLER_KEYS = %w[
BUNDLE_BIN_PATH
BUNDLE_GEMFILE
BUNDLE_LOCKFILE
BUNDLER_VERSION
BUNDLER_SETUP
GEM_HOME
Expand Down
8 changes: 8 additions & 0 deletions bundler/lib/bundler/inline.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,14 @@ def gemfile(force_latest_compatible = false, options = {}, &gemfile)
raise ArgumentError, "Unknown options: #{opts.keys.join(", ")}" unless opts.empty?

old_gemfile = ENV["BUNDLE_GEMFILE"]
old_lockfile = ENV["BUNDLE_LOCKFILE"]

Bundler.unbundle_env!

begin
Bundler.instance_variable_set(:@bundle_path, Pathname.new(Gem.dir))
Bundler::SharedHelpers.set_env "BUNDLE_GEMFILE", "Gemfile"
Bundler::SharedHelpers.set_env "BUNDLE_LOCKFILE", "Gemfile.lock"

Bundler::Plugin.gemfile_install(&gemfile) if Bundler.settings[:plugins]
builder = Bundler::Dsl.new
Expand Down Expand Up @@ -94,5 +96,11 @@ def gemfile(force_latest_compatible = false, options = {}, &gemfile)
else
ENV["BUNDLE_GEMFILE"] = ""
end

if old_lockfile
ENV["BUNDLE_LOCKFILE"] = old_lockfile
else
ENV["BUNDLE_LOCKFILE"] = ""
end
end
end
3 changes: 3 additions & 0 deletions bundler/lib/bundler/man/bundle-config.1
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@ Generate a \fBgems\.rb\fR instead of a \fBGemfile\fR when running \fBbundle init
\fBjobs\fR (\fBBUNDLE_JOBS\fR)
The number of gems Bundler can install in parallel\. Defaults to the number of available processors\.
.TP
\fBlockfile\fR (\fBBUNDLE_LOCKFILE\fR)
The path to the lockfile that bundler should use\. By default, Bundler adds \fB\.lock\fR to the end of the \fBgemfile\fR entry\. Can be set to \fBfalse\fR in the Gemfile to disable lockfile creation entirely (see gemfile(5))\.
.TP
\fBlockfile_checksums\fR (\fBBUNDLE_LOCKFILE_CHECKSUMS\fR)
Whether Bundler should include a checksums section in new lockfiles, to protect from compromised gem sources\. Defaults to true\.
.TP
Expand Down
4 changes: 4 additions & 0 deletions bundler/lib/bundler/man/bundle-config.1.ronn
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,10 @@ learn more about their operation in [bundle install(1)](bundle-install.1.html).
* `jobs` (`BUNDLE_JOBS`):
The number of gems Bundler can install in parallel. Defaults to the number of
available processors.
* `lockfile` (`BUNDLE_LOCKFILE`):
The path to the lockfile that bundler should use. By default, Bundler adds
`.lock` to the end of the `gemfile` entry. Can be set to `false` in the
Gemfile to disable lockfile creation entirely (see gemfile(5)).
* `lockfile_checksums` (`BUNDLE_LOCKFILE_CHECKSUMS`):
Whether Bundler should include a checksums section in new lockfiles, to protect from compromised gem sources. Defaults to true.
* `no_install` (`BUNDLE_NO_INSTALL`):
Expand Down
7 changes: 6 additions & 1 deletion bundler/lib/bundler/man/bundle-install.1
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
.SH "NAME"
\fBbundle\-install\fR \- Install the dependencies specified in your Gemfile
.SH "SYNOPSIS"
\fBbundle install\fR [\-\-force] [\-\-full\-index] [\-\-gemfile=GEMFILE] [\-\-jobs=NUMBER] [\-\-local] [\-\-no\-cache] [\-\-prefer\-local] [\-\-quiet] [\-\-retry=NUMBER] [\-\-standalone[=GROUP[ GROUP\|\.\|\.\|\.]]] [\-\-trust\-policy=TRUST\-POLICY] [\-\-target\-rbconfig=TARGET\-RBCONFIG]
\fBbundle install\fR [\-\-force] [\-\-full\-index] [\-\-gemfile=GEMFILE] [\-\-jobs=NUMBER] [\-\-local] [\-\-no\-cache] [\-\-no\-lock] [\-\-prefer\-local] [\-\-quiet] [\-\-retry=NUMBER] [\-\-standalone[=GROUP[ GROUP\|\.\|\.\|\.]]] [\-\-trust\-policy=TRUST\-POLICY] [\-\-target\-rbconfig=TARGET\-RBCONFIG]
.SH "DESCRIPTION"
Install the gems specified in your Gemfile(5)\. If this is the first time you run bundle install (and a \fBGemfile\.lock\fR does not exist), Bundler will fetch all remote sources, resolve dependencies and install all needed gems\.
.P
Expand Down Expand Up @@ -34,6 +34,11 @@ Force using locally installed gems, or gems already present in Rubygems' cache o
\fB\-\-no\-cache\fR
Do not update the cache in \fBvendor/cache\fR with the newly bundled gems\. This does not remove any gems in the cache but keeps the newly bundled gems from being cached during the install\.
.TP
\fB\-\-no\-lock\fR
Do not create a lockfile\. Useful if you want to install dependencies but not lock versions of gems\. Recommended for library development, and other situations where the code is expected to work with a range of dependency versions\.
.IP
This has the same effect as using \fBlockfile false\fR in the Gemfile\. See gemfile(5) for more information\.
.TP
\fB\-\-quiet\fR
Do not print progress information to the standard output\.
.TP
Expand Down
10 changes: 10 additions & 0 deletions bundler/lib/bundler/man/bundle-install.1.ronn
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ bundle-install(1) -- Install the dependencies specified in your Gemfile
[--jobs=NUMBER]
[--local]
[--no-cache]
[--no-lock]
[--prefer-local]
[--quiet]
[--retry=NUMBER]
Expand Down Expand Up @@ -71,6 +72,15 @@ update process below under [CONSERVATIVE UPDATING][].
does not remove any gems in the cache but keeps the newly bundled gems from
being cached during the install.

* `--no-lock`:
Do not create a lockfile. Useful if you want to install dependencies but not
lock versions of gems. Recommended for library development, and other
situations where the code is expected to work with a range of dependency
versions.

Comment thread
jeremyevans marked this conversation as resolved.
This has the same effect as using `lockfile false` in the Gemfile.
See gemfile(5) for more information.

* `--quiet`:
Do not print progress information to the standard output.

Expand Down
29 changes: 29 additions & 0 deletions bundler/lib/bundler/man/gemfile.5
Original file line number Diff line number Diff line change
Expand Up @@ -469,4 +469,33 @@ For implicit gems (dependencies of explicit gems), any source, git, or path repo
.IP "3." 4
If neither of the above conditions are met, the global source will be used\. If multiple global sources are specified, they will be prioritized from last to first, but this is deprecated since Bundler 1\.13, so Bundler prints a warning and will abort with an error in the future\.
.IP "" 0
.SH "LOCKFILE"
By default, Bundler will create a lockfile by adding \fB\.lock\fR to the end of the Gemfile name\. To change this, use the \fBlockfile\fR method:
.IP "" 4
.nf
lockfile "/path/to/lockfile\.lock"
.fi
.IP "" 0
.P
This is useful when you want to use different lockfiles per ruby version or platform\.
.P
To avoid writing a lock file, use \fBfalse\fR as the argument:
.IP "" 4
.nf
lockfile false
.fi
.IP "" 0
.P
This is useful for library development and other situations where the code is expected to work with a range of dependency versions\.
.SS "LOCKFILE PRECEDENCE"
When determining path to the lockfile or whether to create a lockfile, the following precedence is used:
.IP "1." 4
The \fBbundle install\fR \fB\-\-no\-lock\fR option (which disables lockfile creation)\.
.IP "2." 4
The \fBlockfile\fR method in the Gemfile\.
.IP "3." 4
The \fBBUNDLE_LOCKFILE\fR environment variable\.
.IP "4." 4
The default behavior of adding \fB\.lock\fR to the end of the Gemfile name\.
.IP "" 0

27 changes: 27 additions & 0 deletions bundler/lib/bundler/man/gemfile.5.ronn
Original file line number Diff line number Diff line change
Expand Up @@ -556,3 +556,30 @@ bundler uses the following priority order:
If multiple global sources are specified, they will be prioritized from
last to first, but this is deprecated since Bundler 1.13, so Bundler prints
a warning and will abort with an error in the future.

## LOCKFILE

By default, Bundler will create a lockfile by adding `.lock` to the end of the
Gemfile name. To change this, use the `lockfile` method:

lockfile "/path/to/lockfile.lock"

This is useful when you want to use different lockfiles per ruby version or
platform.

To avoid writing a lock file, use `false` as the argument:

lockfile false

This is useful for library development and other situations where the code is

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you shed a light on what these other situations/use cases are? Are they also related to gem maintainership?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any case where you are developing libraries that are designed to work with multiple versions of dependencies (that is, almost every library). Otherwise, as @byroot alluded to above:

  • Unless you add Gemfile.lock to .gitignore, it will show up as an untracked file, which is generally undesirable in terms of development.
  • Unless you rm Gemfile.lock, you are likely stuck testing the library with the dependencies that were present when the libraries were initally installed.

Other issues:

  • If you want to test your library with multiple Ruby versions, Gemfile.lock gets in the way as it restricts the Ruby version.
  • Creating the Gemfile.lock does not work in cases where the process doesn't have write access to the directory containing Gemfile.

In general, Gemfile.lock is only useful for applications. There is rarely a good reason to have it for a library, and it generally just gets in the way.

This is only related to gem maintainership in that the vast majority of gems are libraries and would benefit from this.

Hopefully, these reasons make sense to you. If not, can you explain what benefit you see from creating a Gemfile.lock for a library Gemfile? Additionally, even if you believe some libraries may benefit from a Gemfile.lock, can you at least agree that not all libraries may want a Gemfile.lock? This isn't a default behavior, it's purely opt-in, so it causes no problems for users who want to continue having a Gemfile.lock created.

FWIW, the --no-lock option is already supported for gem (gem install -g Gemfile --no-lock).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is rarely a good reason to have it for a library, and it generally just gets in the way.

Well it depends. As @Earlopain mentioned, it's important for performance. e..g on ruby/json, the Gemfile.lock is git ignored, so every time I need to test with JRuby, I got to re-do the resolution:

real	0m16.573s
user	0m42.594s
sys	0m2.733s

And that's a project with basically no dependencies.

If you want to test your library with multiple Ruby versions, Gemfile.lock gets in the way as it restricts the Ruby version.

It shouldn't. The only issue is with ruby-head and precompiled binaries, I complained a lot about that, and it was somewhat improved lately.

If not, can you explain what benefit you see from creating a Gemfile.lock for a library Gemfile

I maintain projects with both approachs. E.g. ruby/json ignores the Gemfile.lock, but redis-client commits it and use dependabot to have regular PRs to bump dependencies. It is actually an OK workflow, as I'm notified when a dependency release a new version, and immediately get a CI run which proves or disprove compatibilty with it.

But it's OK because redis-client has few dependencies. With e.g. Rails, the Gemfile is much bigger and that workflow would be a PITA.

Overall, I think the more useful feature would be a way to set the path for Gemfile.lock in the Gemfile, e.g.

lock_file RUBY_PLATFORM =~ /java/ ? "Gemfile.jruby.lock" : "Gemfile.lock"

And it could allow lock_file false for your use case.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#9059 (comment)

You can test out how this will work by including this in the Gemfile

Ah, I didn't realize. Although, doing that still generates the lockfile for me, doesn't really want to work.

Personally, I don't really see the use case though. If you don't commit your lockfile, CI will test latest gem versions for you. If you do commit it, you get deterministic versions anyways. If you still have some old gem version in your lockfile, that shouldn't matter since your gem still has to work with it (since there are no constraints against it).

The only I can think of is ruby version bumps (which includes ruby-dev for me), I very rarely remove the lockfile to get rid of warnings that new ruby versions introduce. But to me that is fine for me, paying the cost to re-resolve with every command is just not worth it.

I would not take JRuby as a good counter-example for this, it is already consistently the slowest in CI (occasionally I use it locally where it is more of the same). But like I said earlier, even on CRuby it takes a few seconds (2.3s on the rubocop repo, subtracting the overhead of bundle lock when the lockfile already exists)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall, I think the more useful feature would be a way to set the path for Gemfile.lock in the Gemfile, e.g.

lock_file RUBY_PLATFORM =~ /java/ ? "Gemfile.jruby.lock" : "Gemfile.lock"

And it could allow lock_file false for your use case.

Since @kou also thought that would be a useful feature, and it allows support for a superset of my need, I'll work on support for that.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@byroot @kou I've updated this to use lock_file instead of no_lock! in the Gemfile, and added support for the BUNDLE_GEMFILE_LOCK environment variable.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! I’ll try to find some time tonight to play with it, to see how it does

expected to work with a range of dependency versions.
Comment thread
jeremyevans marked this conversation as resolved.

### LOCKFILE PRECEDENCE

When determining path to the lockfile or whether to create a lockfile, the
following precedence is used:

1. The `bundle install` `--no-lock` option (which disables lockfile creation).
2. The `lockfile` method in the Gemfile.
3. The `BUNDLE_LOCKFILE` environment variable.
4. The default behavior of adding `.lock` to the end of the Gemfile name.
1 change: 1 addition & 0 deletions bundler/lib/bundler/settings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ class Settings
gem.rubocop
gem.test
gemfile
lockfile
path
shebang
simulate_version
Expand Down
4 changes: 4 additions & 0 deletions bundler/lib/bundler/shared_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ def default_gemfile
end

def default_lockfile
given = ENV["BUNDLE_LOCKFILE"]
return Pathname.new(given) if given && !given.empty?

gemfile = default_gemfile

case gemfile.basename.to_s
Expand Down Expand Up @@ -297,6 +300,7 @@ def set_env(key, value)
def set_bundle_variables
Bundler::SharedHelpers.set_env "BUNDLE_BIN_PATH", bundle_bin_path
Bundler::SharedHelpers.set_env "BUNDLE_GEMFILE", find_gemfile.to_s
Bundler::SharedHelpers.set_env "BUNDLE_LOCKFILE", default_lockfile.to_s
Comment thread
colby-swandale marked this conversation as resolved.
Bundler::SharedHelpers.set_env "BUNDLER_VERSION", Bundler::VERSION
Bundler::SharedHelpers.set_env "BUNDLER_SETUP", File.expand_path("setup", __dir__)
end
Expand Down
17 changes: 17 additions & 0 deletions bundler/spec/commands/config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -592,3 +592,20 @@
end
end
end

RSpec.describe "setting lockfile via config" do
it "persists the lockfile location to .bundle/config" do
gemfile bundled_app("NotGemfile"), <<-G
source "https://gem.repo1"
gem 'myrack'
G

bundle "config set --local gemfile #{bundled_app("NotGemfile")}"
bundle "config set --local lockfile #{bundled_app("ReallyNotGemfile.lock")}"
expect(File.exist?(bundled_app(".bundle/config"))).to eq(true)

bundle "config list"
expect(out).to include("NotGemfile")
expect(out).to include("ReallyNotGemfile.lock")
end
end
33 changes: 33 additions & 0 deletions bundler/spec/commands/install_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,28 @@
expect(bundled_app_lock).to exist
end

it "creates lockfile based on the lockfile method in Gemfile" do

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we make a warning when the user has a Gemfile & Gemfile.lock, but runs bundle install with --no-lock ?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually I've also found that when you run --no-lock with an existing Gemfile & Gemfile.lock, Bundler will load the existing Gemfile.lock. I think this shouldn't be happening in this situation, but I'm keen to hear thoughts?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As designed and documented, --no-lock means Don't create a lockfile.. Maybe it should be changed to Don't write a lockfile., since it also prevents updating an existing lockfile? It doesn't affect whether an existing lockfile is read.

I think if we want to support ignoring an existing lockfile, we should have a separate option for that (e.g. --ignore-lockfile or --ignore-existing-lockfile). That option would prevent reading an existing lockfile, but wouldn't change whether a lock file is written. I think the two ideas are independent, one affects whether an existing lockfile is read, the other whether to write a lockfile.

install_gemfile <<-G
lockfile "OmgFile.lock"
source "https://gem.repo1"
gem "myrack", "1.0"
G

bundle "install"

expect(bundled_app("OmgFile.lock")).to exist
end

it "does not make a lockfile if lockfile false is used in Gemfile" do
install_gemfile <<-G
lockfile false
source "https://gem.repo1"
gem 'myrack'
G

expect(bundled_app_lock).not_to exist
end

it "does not create ./.bundle by default" do
install_gemfile <<-G
source "https://gem.repo1"
Expand Down Expand Up @@ -67,6 +89,17 @@
expect(bundled_app("OmgFile.lock")).to exist
end

it "doesn't create a lockfile if --no-lock option is given" do
gemfile bundled_app("OmgFile"), <<-G
source "https://gem.repo1"
gem "myrack", "1.0"
G

bundle "install --gemfile OmgFile --no-lock"

expect(bundled_app("OmgFile.lock")).not_to exist
end

it "doesn't delete the lockfile if one already exists" do
install_gemfile <<-G
source "https://gem.repo1"
Expand Down
29 changes: 29 additions & 0 deletions bundler/spec/install/gemfile_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,35 @@
ENV["BUNDLE_GEMFILE"] = "NotGemfile"
expect(the_bundle).to include_gems "myrack 1.0.0"
end

it "respects lockfile and BUNDLE_LOCKFILE" do
gemfile bundled_app("NotGemfile"), <<-G
lockfile "ReallyNotGemfile.lock"
source "https://gem.repo1"
gem 'myrack'
G

bundle :install, gemfile: bundled_app("NotGemfile")

ENV["BUNDLE_GEMFILE"] = "NotGemfile"
ENV["BUNDLE_LOCKFILE"] = "ReallyNotGemfile.lock"
expect(the_bundle).to include_gems "myrack 1.0.0"
end

it "respects BUNDLE_LOCKFILE during bundle install" do
ENV["BUNDLE_LOCKFILE"] = "ReallyNotGemfile.lock"

gemfile bundled_app("NotGemfile"), <<-G
source "https://gem.repo1"
gem 'myrack'
G

bundle :install, gemfile: bundled_app("NotGemfile")
expect(bundled_app("ReallyNotGemfile.lock")).to exist

ENV["BUNDLE_GEMFILE"] = "NotGemfile"
expect(the_bundle).to include_gems "myrack 1.0.0"
end
end

context "with gemfile set via config" do
Expand Down
9 changes: 6 additions & 3 deletions lib/rubygems/bundler_version_finder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,12 @@ def self.lockfile_contents

return unless gemfile

lockfile = case gemfile
when "gems.rb" then "gems.locked"
else "#{gemfile}.lock"
lockfile = ENV["BUNDLE_LOCKFILE"]
lockfile = nil if lockfile&.empty?

lockfile ||= case gemfile
when "gems.rb" then "gems.locked"
else "#{gemfile}.lock"
end

return unless File.file?(lockfile)
Expand Down