-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Add support for lockfile in Gemfile and bundle install --no-lock #9059
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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:
Other issues:
In general, 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 FWIW, the
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Well it depends. As @Earlopain mentioned, it's important for performance. e..g on And that's a project with basically no dependencies.
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.
I maintain projects with both approachs. E.g. But it's OK because Overall, I think the more useful feature would be a way to set the path for lock_file RUBY_PLATFORM =~ /java/ ? "Gemfile.jruby.lock" : "Gemfile.lock"And it could allow
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
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
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
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.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks!
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. | ||
|
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. | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -65,6 +65,7 @@ class Settings | |
| gem.rubocop | ||
| gem.test | ||
| gemfile | ||
| lockfile | ||
| path | ||
| shebang | ||
| simulate_version | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -29,6 +29,28 @@ | |
| expect(bundled_app_lock).to exist | ||
| end | ||
|
|
||
| it "creates lockfile based on the lockfile method in Gemfile" do | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we make a warning when the user has a
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually I've also found that when you run
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As designed and documented, I think if we want to support ignoring an existing lockfile, we should have a separate option for that (e.g. |
||
| 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" | ||
|
|
@@ -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" | ||
|
|
||
There was a problem hiding this comment.
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
--lockfileoption? Similar to how we expose a--gemfileoption. This might be a good "nice to have" for a follow-up PR rather than blocking this one.There was a problem hiding this comment.
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.