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

Bundler allows Incompatible Ruby versions in Gemfile and Gemfile.lock #4627

Closed
schneems opened this Issue May 31, 2016 · 15 comments

Comments

Projects
None yet
4 participants
@schneems
Contributor

schneems commented May 31, 2016

If you have ruby "2.3.0" in your Gemfile and bundle install then you'll get this in your Gemfile.lock:

RUBY VERSION
   ruby 2.3.0p0

Now if you want to update your project to the latest and you set ruby "2.3.1" in your Gemfile, and you run bundle install, nothing will change.

When you run bundle platform --ruby even though you have ruby "2.3.1" specified, you'll still get:

$ ruby -v
ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-darwin14]
$ bundle install
  # ... 
$ cat Gemfile | grep ruby
source 'https://rubygems.org'
ruby '2.3.1'
$ bundle _1.12.5_ platform --ruby
ruby 2.3.0p0

I'm thinking we should detect when the stored Ruby version does not satisfy the version specification and update the Gemfile.lock.

@segiddins

This comment has been minimized.

Show comment
Hide comment
@segiddins

segiddins May 31, 2016

Member

Please check if #4603 fixes things for you

Member

segiddins commented May 31, 2016

Please check if #4603 fixes things for you

@schneems

This comment has been minimized.

Show comment
Hide comment
@schneems

schneems May 31, 2016

Contributor

Did a bundle open bundler and added that line

@unlocking ||= @unlock[:ruby] || (!@locked_ruby_version ^ !@ruby_version)

To definition.rb and it didn't seem to have any effect.

Ran bundle install after that and still get the same result

$ bundle _1.12.5_ platform --ruby
ruby 2.3.0p0

Not actually sure what that code does. It looks like @locked_ruby_version is a string, and I don't know where the ^ is coming from.

Contributor

schneems commented May 31, 2016

Did a bundle open bundler and added that line

@unlocking ||= @unlock[:ruby] || (!@locked_ruby_version ^ !@ruby_version)

To definition.rb and it didn't seem to have any effect.

Ran bundle install after that and still get the same result

$ bundle _1.12.5_ platform --ruby
ruby 2.3.0p0

Not actually sure what that code does. It looks like @locked_ruby_version is a string, and I don't know where the ^ is coming from.

@schneems

This comment has been minimized.

Show comment
Hide comment
@schneems

schneems May 31, 2016

Contributor

missed the negation there, that makes sense http://ruby-doc.org/core-2.2.0/TrueClass.html#method-i-5E

Contributor

schneems commented May 31, 2016

missed the negation there, that makes sense http://ruby-doc.org/core-2.2.0/TrueClass.html#method-i-5E

@segiddins

This comment has been minimized.

Show comment
Hide comment
@segiddins

segiddins May 31, 2016

Member

So did using #4603 fix the issue?

Member

segiddins commented May 31, 2016

So did using #4603 fix the issue?

@schneems

This comment has been minimized.

Show comment
Hide comment
@schneems

schneems May 31, 2016

Contributor

I don't think it did.

Contributor

schneems commented May 31, 2016

I don't think it did.

@segiddins

This comment has been minimized.

Show comment
Hide comment
@segiddins

segiddins May 31, 2016

Member

and did you run bundle update --ruby before running bundle platform --ruby (or any sort of install / update command) because if not, bundle platform isn't supposed to update the lockfile

Member

segiddins commented May 31, 2016

and did you run bundle update --ruby before running bundle platform --ruby (or any sort of install / update command) because if not, bundle platform isn't supposed to update the lockfile

@segiddins

This comment has been minimized.

Show comment
Hide comment
@segiddins

segiddins May 31, 2016

Member

Ah, actually we can add an Definition#unlocking_ruby?, and if its true only use the gemfile req?
and it would just use the logic in #4603

Member

segiddins commented May 31, 2016

Ah, actually we can add an Definition#unlocking_ruby?, and if its true only use the gemfile req?
and it would just use the logic in #4603

@segiddins segiddins self-assigned this May 31, 2016

@schneems

This comment has been minimized.

Show comment
Hide comment
@schneems

schneems Jun 1, 2016

Contributor

Here's where I added your code:

$ sed -n '85,92p;' /Users/richardschneeman/.gem/ruby/2.3.1/gems/bundler-1.12.5/lib/bundler/definition.rb

      @unlock[:gems] ||= []
      @unlock[:sources] ||= []
      @unlocking ||= @unlock[:ruby] || (!@locked_ruby_version ^ !@ruby_version)

      current_platform = Bundler.rubygems.platforms.map {|p| generic(p) }.compact.last
      @new_platform = !@platforms.include?(current_platform)
      @platforms |= [current_platform]

Then in the same project I run bundle install:

$ bundle _1.12.5_ install
Resolving dependencies...
# ...
Bundle complete! 57 Gemfile dependencies, 138 gems now installed.
Use `bundle show [gemname]` to see where a bundled gem is installed.

I don't get an updated version:

$ bundle _1.12.5_ platform --ruby
ruby 2.3.0p0

If I try to update a gem

$ bundle _1.12.5_ update bourbon
# ...
Installing bourbon 4.2.7 (was 4.2.5)
Using neat 1.7.2
Bundle updated!

Then I still get the same output

$ bundle _1.12.5_ platform --ruby
ruby 2.3.0p0
Contributor

schneems commented Jun 1, 2016

Here's where I added your code:

$ sed -n '85,92p;' /Users/richardschneeman/.gem/ruby/2.3.1/gems/bundler-1.12.5/lib/bundler/definition.rb

      @unlock[:gems] ||= []
      @unlock[:sources] ||= []
      @unlocking ||= @unlock[:ruby] || (!@locked_ruby_version ^ !@ruby_version)

      current_platform = Bundler.rubygems.platforms.map {|p| generic(p) }.compact.last
      @new_platform = !@platforms.include?(current_platform)
      @platforms |= [current_platform]

Then in the same project I run bundle install:

$ bundle _1.12.5_ install
Resolving dependencies...
# ...
Bundle complete! 57 Gemfile dependencies, 138 gems now installed.
Use `bundle show [gemname]` to see where a bundled gem is installed.

I don't get an updated version:

$ bundle _1.12.5_ platform --ruby
ruby 2.3.0p0

If I try to update a gem

$ bundle _1.12.5_ update bourbon
# ...
Installing bourbon 4.2.7 (was 4.2.5)
Using neat 1.7.2
Bundle updated!

Then I still get the same output

$ bundle _1.12.5_ platform --ruby
ruby 2.3.0p0
@segiddins

This comment has been minimized.

Show comment
Hide comment
@segiddins

segiddins Jun 5, 2016

Member

The PR now should have this fixed, thanks for the issue!

Member

segiddins commented Jun 5, 2016

The PR now should have this fixed, thanks for the issue!

@schneems

This comment has been minimized.

Show comment
Hide comment
@schneems

schneems Jun 7, 2016

Contributor

I can confirm that your patch now gives an error stating that the Ruby version in the Gemfile does not match the current Ruby version

$ ruby -v
ruby 2.3.0p0 (2015-12-25 revision 53290) [x86_64-darwin14]
$ cat Gemfile | grep ruby
source "https://rubygems.org"
ruby "2.3.1"
$ cat Gemfile.lock | grep -A 1 "RUBY VERSION"
RUBY VERSION
   ruby 2.3.0p0
$ bundle _1.12.5_ install
Your Ruby version is 2.3.0, but your Gemfile specified 2.3.1

However the Gemfile.lock is still not correct when you try to bundle install if you've not changed any dependencies

$ ruby -v
ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-darwin14]
$ cat Gemfile | grep ruby
source "https://rubygems.org"
ruby "2.3.1"
$ cat Gemfile.lock | grep -A 1 "RUBY VERSION"
RUBY VERSION
   ruby 2.3.0p0
$  bundle _1.12.5_ install
The Gemfile specifies no dependencies
Bundle complete! 0 Gemfile dependencies, 1 gem now installed.
Use `bundle show [gemname]` to see where a bundled gem is installed.


# note that we have 2.3.1 in Gemfile and are using 2.3.1

$ bundle platform --ruby
ruby 2.3.0p0
$ cat Gemfile.lock | grep -A 1 "RUBY VERSION"
RUBY VERSION
   ruby 2.3.0p0
Contributor

schneems commented Jun 7, 2016

I can confirm that your patch now gives an error stating that the Ruby version in the Gemfile does not match the current Ruby version

$ ruby -v
ruby 2.3.0p0 (2015-12-25 revision 53290) [x86_64-darwin14]
$ cat Gemfile | grep ruby
source "https://rubygems.org"
ruby "2.3.1"
$ cat Gemfile.lock | grep -A 1 "RUBY VERSION"
RUBY VERSION
   ruby 2.3.0p0
$ bundle _1.12.5_ install
Your Ruby version is 2.3.0, but your Gemfile specified 2.3.1

However the Gemfile.lock is still not correct when you try to bundle install if you've not changed any dependencies

$ ruby -v
ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-darwin14]
$ cat Gemfile | grep ruby
source "https://rubygems.org"
ruby "2.3.1"
$ cat Gemfile.lock | grep -A 1 "RUBY VERSION"
RUBY VERSION
   ruby 2.3.0p0
$  bundle _1.12.5_ install
The Gemfile specifies no dependencies
Bundle complete! 0 Gemfile dependencies, 1 gem now installed.
Use `bundle show [gemname]` to see where a bundled gem is installed.


# note that we have 2.3.1 in Gemfile and are using 2.3.1

$ bundle platform --ruby
ruby 2.3.0p0
$ cat Gemfile.lock | grep -A 1 "RUBY VERSION"
RUBY VERSION
   ruby 2.3.0p0
@schneems

This comment has been minimized.

Show comment
Hide comment
@schneems

schneems Jun 7, 2016

Contributor

As a side note whats your recommend way to use a branch or commit of bundler for testing things locally? I've been using the time honored tradition of copy/pasta for testing this issue. Would love to eliminate any potential copy errors with a more automated method. Usually I would specify a dependency with github: "<username>/<name>", branch: "<name>", but that won't work for bundler.

Contributor

schneems commented Jun 7, 2016

As a side note whats your recommend way to use a branch or commit of bundler for testing things locally? I've been using the time honored tradition of copy/pasta for testing this issue. Would love to eliminate any potential copy errors with a more automated method. Usually I would specify a dependency with github: "<username>/<name>", branch: "<name>", but that won't work for bundler.

@segiddins

This comment has been minimized.

Show comment
Hide comment
@segiddins

segiddins Jun 7, 2016

Member

Just clone bundler, I believe we have instructions in either the contributing or development file

Member

segiddins commented Jun 7, 2016

Just clone bundler, I believe we have instructions in either the contributing or development file

@RochesterinNYC

This comment has been minimized.

Show comment
Hide comment
@RochesterinNYC

RochesterinNYC Jun 8, 2016

Member

I'm unable to reproduce the failed behavior that you're getting @schneems ? It seems to be working as expected for me.

$ ruby -v
ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-darwin14]
$ cat Gemfile
source 'https://rubygems.org'
ruby "2.3.1"
$ cat Gemfile.lock
GEM
  remote: https://rubygems.org/
  specs:

PLATFORMS
  ruby

DEPENDENCIES

RUBY VERSION
   ruby 2.3.0p0

BUNDLED WITH
   1.12.5
$ dbundle install
The Gemfile specifies no dependencies
Resolving dependencies...
Bundle complete! 0 Gemfile dependencies, 1 gem now installed.
Use `bundle show [gemname]` to see where a bundled gem is installed.
$ cat Gemfile.lock
GEM
  remote: https://rubygems.org/
  specs:

PLATFORMS
  ruby

DEPENDENCIES

RUBY VERSION
   ruby 2.3.1p112

BUNDLED WITH
   1.12.5
$ dbundle platform --ruby
ruby 2.3.1p112
Member

RochesterinNYC commented Jun 8, 2016

I'm unable to reproduce the failed behavior that you're getting @schneems ? It seems to be working as expected for me.

$ ruby -v
ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-darwin14]
$ cat Gemfile
source 'https://rubygems.org'
ruby "2.3.1"
$ cat Gemfile.lock
GEM
  remote: https://rubygems.org/
  specs:

PLATFORMS
  ruby

DEPENDENCIES

RUBY VERSION
   ruby 2.3.0p0

BUNDLED WITH
   1.12.5
$ dbundle install
The Gemfile specifies no dependencies
Resolving dependencies...
Bundle complete! 0 Gemfile dependencies, 1 gem now installed.
Use `bundle show [gemname]` to see where a bundled gem is installed.
$ cat Gemfile.lock
GEM
  remote: https://rubygems.org/
  specs:

PLATFORMS
  ruby

DEPENDENCIES

RUBY VERSION
   ruby 2.3.1p112

BUNDLED WITH
   1.12.5
$ dbundle platform --ruby
ruby 2.3.1p112
@RochesterinNYC

This comment has been minimized.

Show comment
Hide comment
@RochesterinNYC

RochesterinNYC Jun 8, 2016

Member

My setup (that uses this PR's branch for bundler):

$ alias dbundle
alias dbundle='ruby -I /Users/Rochester/Programming/OpenSource/bundler/lib /Users/Rochester/Programming/OpenSource/bundler/exe/bundle'
$ cd /Users/Rochester/Programming/OpenSource/bundler
$ git status
On branch seg-allow-unlocking-when-removing-ruby
Your branch is up-to-date with 'upstream/seg-allow-unlocking-when-removing-ruby'.
nothing to commit, working directory clean

The dbundle stuff is as per step 4 of https://github.com/bundler/bundler/blob/master/DEVELOPMENT.md#development-setup

Member

RochesterinNYC commented Jun 8, 2016

My setup (that uses this PR's branch for bundler):

$ alias dbundle
alias dbundle='ruby -I /Users/Rochester/Programming/OpenSource/bundler/lib /Users/Rochester/Programming/OpenSource/bundler/exe/bundle'
$ cd /Users/Rochester/Programming/OpenSource/bundler
$ git status
On branch seg-allow-unlocking-when-removing-ruby
Your branch is up-to-date with 'upstream/seg-allow-unlocking-when-removing-ruby'.
nothing to commit, working directory clean

The dbundle stuff is as per step 4 of https://github.com/bundler/bundler/blob/master/DEVELOPMENT.md#development-setup

@schneems

This comment has been minimized.

Show comment
Hide comment
@schneems

schneems Jun 8, 2016

Contributor

I can confirm it works now. Thanks!

$ ruby -v
ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-darwin14]
2.3.1  /tmp/bundler_issue
$ cat Gemfile
source "https://rubygems.org"

ruby "2.3.1"
2.3.1  /tmp/bundler_issue
$ cat Gemfile.lock
GEM
  remote: https://rubygems.org/
  specs:

PLATFORMS
  ruby

DEPENDENCIES

RUBY VERSION
   ruby 2.3.0p0

BUNDLED WITH
   1.12.5
2.3.1  /tmp/bundler_issue
$ dbundle install
The Gemfile specifies no dependencies
Resolving dependencies...
Bundle complete! 0 Gemfile dependencies, 1 gem now installed.
Use `bundle show [gemname]` to see where a bundled gem is installed.
2.3.1  /tmp/bundler_issue
$ cat Gemfile.lock
GEM
  remote: https://rubygems.org/
  specs:

PLATFORMS
  ruby

DEPENDENCIES

RUBY VERSION
   ruby 2.3.1p112

BUNDLED WITH
   1.12.5
Contributor

schneems commented Jun 8, 2016

I can confirm it works now. Thanks!

$ ruby -v
ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-darwin14]
2.3.1  /tmp/bundler_issue
$ cat Gemfile
source "https://rubygems.org"

ruby "2.3.1"
2.3.1  /tmp/bundler_issue
$ cat Gemfile.lock
GEM
  remote: https://rubygems.org/
  specs:

PLATFORMS
  ruby

DEPENDENCIES

RUBY VERSION
   ruby 2.3.0p0

BUNDLED WITH
   1.12.5
2.3.1  /tmp/bundler_issue
$ dbundle install
The Gemfile specifies no dependencies
Resolving dependencies...
Bundle complete! 0 Gemfile dependencies, 1 gem now installed.
Use `bundle show [gemname]` to see where a bundled gem is installed.
2.3.1  /tmp/bundler_issue
$ cat Gemfile.lock
GEM
  remote: https://rubygems.org/
  specs:

PLATFORMS
  ruby

DEPENDENCIES

RUBY VERSION
   ruby 2.3.1p112

BUNDLED WITH
   1.12.5

homu added a commit that referenced this issue Jun 10, 2016

Auto merge of #4603 - bundler:seg-allow-unlocking-when-removing-ruby,…
… r=indirect

[Definition] Allow unlocking when removing the ruby version requirement

Closes #4595. Closes #4627.

\c @RochesterinNYC

@homu homu closed this in #4603 Jun 10, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment