Skip to content

bottle: prioritize HOMEBREW_CELLAR over :any over :any_skip_relocation#6969

Merged
MikeMcQuaid merged 1 commit intoHomebrew:masterfrom
dawidd6:bottle-cellar-priority
Feb 11, 2020
Merged

bottle: prioritize HOMEBREW_CELLAR over :any over :any_skip_relocation#6969
MikeMcQuaid merged 1 commit intoHomebrew:masterfrom
dawidd6:bottle-cellar-priority

Conversation

@dawidd6
Copy link
Copy Markdown
Contributor

@dawidd6 dawidd6 commented Jan 27, 2020

  • Have you followed the guidelines in our Contributing document?
  • Have you checked to ensure there aren't other open Pull Requests for the same change?
  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your changes? Here's an example.
  • Have you successfully run brew style with your changes locally?
  • Have you successfully run brew tests with your changes locally?

This is an example from @sjackman on what is the issue:

❯❯❯ jq '."brewsci/bio/ntcard".bottle.cellar' ntcard--1.2.0.catalina.bottle.json ntcard--1.2.0.x86_64_linux.bottle.json
"any"
"any_skip_relocation"
❯❯❯ brew bottle --merge --write *.json
==> brewsci/bio/ntcard
  bottle do
    root_url "https://linuxbrew.bintray.com/bottles-bio"
    cellar :any_skip_relocation
    sha256 "3687ad1e69cfc8849b4d9d6c2aaaf96f426125509658ace1ec4febe7c3dadcf3" => :catalina
    sha256 "a4c224a29010985c7956a6ef37e6b08f3370975512031f16ed5f1370b55866a3" => :x86_64_linux
  end

As one can see, there are two different cellars and the less proper one is chosen.
After applying the patch from this PR:

➜  ~/Downloads  brew bottle --merge ntcard--1.2.0.catalina.bottle.json ntcard--1.2.0.x86_64_linux.bottle.json 
==> brewsci/bio/ntcard
  bottle do
    root_url "https://linuxbrew.bintray.com/bottles-bio"
    cellar :any
    sha256 "3687ad1e69cfc8849b4d9d6c2aaaf96f426125509658ace1ec4febe7c3dadcf3" => :catalina
    sha256 "a4c224a29010985c7956a6ef37e6b08f3370975512031f16ed5f1370b55866a3" => :x86_64_linux
  end
➜  ~/Downloads  brew bottle --merge ntcard--1.2.0.x86_64_linux.bottle.json ntcard--1.2.0.catalina.bottle.json 
==> brewsci/bio/ntcard
  bottle do
    root_url "https://linuxbrew.bintray.com/bottles-bio"
    cellar :any
    sha256 "3687ad1e69cfc8849b4d9d6c2aaaf96f426125509658ace1ec4febe7c3dadcf3" => :catalina
    sha256 "a4c224a29010985c7956a6ef37e6b08f3370975512031f16ed5f1370b55866a3" => :x86_64_linux
  end

@dawidd6 dawidd6 changed the title bottle: priority :any over :any_skip_relocation bottle: prioritize :any over :any_skip_relocation Jan 27, 2020
@dawidd6 dawidd6 force-pushed the bottle-cellar-priority branch 2 times, most recently from dd80948 to 1afe4af Compare January 27, 2020 18:56
@dawidd6 dawidd6 changed the title bottle: prioritize :any over :any_skip_relocation bottle: prioritize HOMEBREW_CELLAR over :any over :any_skip_relocation Jan 27, 2020
@dawidd6 dawidd6 force-pushed the bottle-cellar-priority branch 2 times, most recently from 6028791 to c2f923b Compare January 27, 2020 19:15
Copy link
Copy Markdown
Contributor

@sjackman sjackman left a comment

Choose a reason for hiding this comment

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

Thanks, Dawidd!

Comment thread Library/Homebrew/dev-cmd/bottle.rb Outdated
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.

Not sure I understand the .min here. Can you explain?

Copy link
Copy Markdown
Contributor Author

@dawidd6 dawidd6 Jan 27, 2020

Choose a reason for hiding this comment

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

It will return the minimum value from those 2 cellars.
HOMEBREW_CELLAR < :any < :any_skip_relocation.

That was @sjackman idea and it works well.

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.

Is that just based on a string comparison? If so it's a bit confusing and I think an if/else or a case statement might be a bit more obvious with intent.

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.

Yep, just based on string comparison. /… sorts before any sorts before any_skip_relocation. I'm personally okay with this style, so long as the comment precedes the code. The code to manually sort it could be a bit tedious. If we go that route, I'd suggesting creating a comparison function for this member and call [first, second].min { |a, b| … }

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.

@MikeMcQuaid Your call. What do you think?

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.

Please 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.

If I've understood correctly: how about:

Suggested change
[first, second].min
cellars = [first, second]
if cellars.include?(HOMEBREW_CELLAR)
HOMEBREW_CELLAR
elsif cellars.include?(:any)
:any
elsif cellars.include?(:any_skip_relocation)
:any_skip_relocation
else
second
end

Copy link
Copy Markdown
Contributor

@sjackman sjackman Feb 6, 2020

Choose a reason for hiding this comment

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

This code doesn't handle the case when the cellar is the default path from the other OS or a non default path. How about:

if cellars.include?(HOMEBREW_CELLAR)
  HOMEBREW_CELLAR
elsif first.start_with?("/")
  first
elsif second.start_with?("/")
  second
elsif cellars.include?(:any)
  :any
else
  :any_skip_relocation
end

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.

Would probably want to see an elsif cellars.include?(:any_skip_relocation) partly just to ensure this code survives being changed in future (as an else it makes me a bit uneasy).

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.

Updated.

@dawidd6 dawidd6 force-pushed the bottle-cellar-priority branch from 8469d9f to 8ace72e Compare February 10, 2020 12:27
Comment thread Library/Homebrew/dev-cmd/bottle.rb Outdated
@dawidd6 dawidd6 force-pushed the bottle-cellar-priority branch from 8ace72e to c80107c Compare February 10, 2020 20:39
Copy link
Copy Markdown
Member

@MikeMcQuaid MikeMcQuaid left a comment

Choose a reason for hiding this comment

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

Nice work, thanks @dawidd6!

@MikeMcQuaid MikeMcQuaid merged commit dca717e into Homebrew:master Feb 11, 2020
@sjackman
Copy link
Copy Markdown
Contributor

Thank you, Dawid!

@dawidd6 dawidd6 deleted the bottle-cellar-priority branch February 12, 2020 10:07
@lock lock bot added the outdated PR was locked due to age label Mar 17, 2020
@lock lock bot locked as resolved and limited conversation to collaborators Mar 17, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

outdated PR was locked due to age

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants