bottle.rb: add workaround to make gcc have cellar :any#11899
bottle.rb: add workaround to make gcc have cellar :any#11899MikeMcQuaid merged 1 commit intoHomebrew:masterfrom
Conversation
|
Review period will end on 2021-08-24 at 00:00:00 UTC. |
|
|
|
Okay, what's the best place to add this exception? Perhaps in the I was able to change that to and it also made the gcc bottles relocatable. |
|
Something like that, yes. Can you clarify here what the references are? We don't have the issue on macOS so I'm interested what might be different. |
|
Oh sorry, we do have the issue on macOS. Someone must have manually changed the macOS line in the PR you linked. |
|
Yeah, let me post the strings below. I'm happy to explore other solutions even outside of |
Interesting. Anyway, GCC is designed to be portable so these strings should be ignored regardless of OS. |
e272e04 to
54a84ae
Compare
|
I pushed a change to add something to the |
Everyone says so, but is this officially documented upstream? Looking at the long list of |
|
The documentation of That doesn't cover everything but that's about as far as I know regarding the matter.
Maybe we should actually limit this to the GCC formulae so that a potential dependent that includes GCC prefixes is still flagged. |
MikeMcQuaid
left a comment
There was a problem hiding this comment.
This is far too broad for me for now. I'd like to see this scoped to specific i.e. gcc formulae, comments added and, ideally, we long-term fix this in a way that makes sense for other formulae.
|
Review period ended. |
|
Thanks for the additional feedback. A few more thoughts:
|
Cool, this is exactly what I'd like to see as a comment in the source.
I'd still like to see some sort of "ignores" just in case we accidentally add a hardcoded path through our formula changes and don't notice.
I agree that could be a good long-term solution. I'm more optimistic it will be for these sorts of cases where we know they are already working on Anaconda than globally. |
Library/Homebrew/dev-cmd/bottle.rb
Outdated
| # Ignore matches to source code, which is not required at run time. | ||
| # These matches may be caused by debugging symbols. | ||
| ignores = [%r{/include/|\.(c|cc|cpp|h|hpp)$}] | ||
| ignores = [%r{/include/|\.(c|cc|cpp|h|hpp)$|#{cellar}/gcc}] |
There was a problem hiding this comment.
| ignores = [%r{/include/|\.(c|cc|cpp|h|hpp)$|#{cellar}/gcc}] | |
| ignores = [%r{/include/|\.(c|cc|cpp|h|hpp)$}] | |
| # GCC installation can be moved so long as the whole directory tree is moved together (which we are doing here): | |
| # https://gcc-help.gcc.gnu.narkive.com/GnwuCA7l/moving-gcc-from-the-installation-path-is-it-allowed. | |
| if Formula["gcc"].versioned_formulae.map(&:name).include?(name) | |
| ignores << %r{#{Regexp.escape(cellar)}/gcc/} | |
| end | |
There was a problem hiding this comment.
Thanks, this is super helpful! One quick question, will Formula["gcc"].versioned_formulae.map also include the current version of GCC (GCC 11)? Because we'd want to include that as well.
There was a problem hiding this comment.
I made this change but I hit a weird problem when testing with gcc@5 - it's not returned by Formula["gcc"].versioned_formulae.map! This is the list of formulae that are loaded by that map:
/home/linuxbrew/.linuxbrew/Homebrew/Library/Homebrew/brew.rb (Formulary::FormulaLoader): loading /home/linuxbrew/.linuxbrew/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/gcc.rb
/home/linuxbrew/.linuxbrew/Homebrew/Library/Homebrew/brew.rb (Formulary::FormulaLoader): loading /home/linuxbrew/.linuxbrew/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/gcc@8.rb
/home/linuxbrew/.linuxbrew/Homebrew/Library/Homebrew/brew.rb (Formulary::FormulaLoader): loading /home/linuxbrew/.linuxbrew/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/gcc@6.rb
/home/linuxbrew/.linuxbrew/Homebrew/Library/Homebrew/brew.rb (Formulary::FormulaLoader): loading /home/linuxbrew/.linuxbrew/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/gcc@9.rb
/home/linuxbrew/.linuxbrew/Homebrew/Library/Homebrew/brew.rb (Formulary::FormulaLoader): loading /home/linuxbrew/.linuxbrew/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/gcc@4.9.rb
/home/linuxbrew/.linuxbrew/Homebrew/Library/Homebrew/brew.rb (Formulary::FormulaLoader): loading /home/linuxbrew/.linuxbrew/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/gcc@10.rb
/home/linuxbrew/.linuxbrew/Homebrew/Library/Homebrew/brew.rb (Formulary::FormulaLoader): loading /home/linuxbrew/.linuxbrew/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/gcc@7.rb
gcc@5 might be excluded from that list because of its special status as the CI version of gcc.
There was a problem hiding this comment.
Separately from that, I had to add a begin/rescue block to catch FormulaUnavailableError, but now I'm getting a brew style failure I don't really understand:
Metrics/AbcSize: Assignment Branch Condition size for bottle_formula is too high. [<83, 255, 81> 280.1/280]
There was a problem hiding this comment.
I made this change but I hit a weird problem when testing with
gcc@5- it's not returned byFormula["gcc"].versioned_formulae.map! This is the list of formulae that are loaded by that map:
I think it'd be worth trying to fix that. Sorry for the yak shave.
Separately from that, I had to add a
begin/rescueblock to catchFormulaUnavailableError, but now I'm getting abrew stylefailure I don't really understand:
Basically that's saying "move some logic into a new method".
There was a problem hiding this comment.
I think it'd be worth trying to fix that. Sorry for the yak shave.
Definitely agreed that we should fix that. It's not clear to me how gcc@5 is even being excluded from that list in the first place, as Formula.versioned_formulae just seems to find the formulae based on filenames. I dig around to found out how this happening.
Basically that's saying "move some logic into a new method".
Okay I will make a new method that returns an additional array of regexes to be appended to ignores.
There was a problem hiding this comment.
I made some progress in figuring out why gcc@5 was missing from the list of versioned formulae produced by Formula.versioned_formulae. It is not specific to gcc@5. When I tried to use brew bottle with gcc@9, for example, it skipped gcc@9 but did load the other versions, including gcc@5. I am puzzled as to how the version of gcc I'm bottling with brew bottle could have any influence on the output of versioned_formulae, given that we are calling the method for Formula["gcc"], and not the specific version of gcc being bottled.
I am wondering if this is somehow related to next if versioned_path == path in
def versioned_formulae
Pathname.glob(path.to_s.gsub(/(@[\d.]+)?\.rb$/, "@*.rb")).map do |versioned_path|
next if versioned_path == path
Formula[versioned_path.basename(".rb").to_s]
rescue FormulaUnavailableError
nil
end.compact.sort_by(&:version).reverse
end
but when I comment that line out, the result is the same.
There was a problem hiding this comment.
@danielnachun Thanks for digging in. Think it's fine to just hack around this for now.
a8ea1b4 to
3e2fc14
Compare
Your understanding is correct. Also true for |
I'll take a look at the binary strings in |
I'm fine with us adding more and more of these formula-specific tweaks to bottling logic and then reverting them on user complaints. We may want to move them to a dedicated file i.e. |
Library/Homebrew/dev-cmd/bottle.rb
Outdated
| ignores = [%r{/include/|\.(c|cc|cpp|h|hpp)$}] | ||
|
|
||
| # GCC installation can be moved so long as the whole directory tree is moved together: | ||
| # https://gcc-help.gcc.gnu.narkive.com/GnwuCA7l/moving-gcc-from-the-installation-path-is-it-allowed. |
There was a problem hiding this comment.
Unfortunately this advice is only true on Linux, so this exception needs to be Linux-only.
|
This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. |
3e2fc14 to
f775b5d
Compare
|
I made a few changes here to pass |
Library/Homebrew/dev-cmd/bottle.rb
Outdated
| ignores = %r{#{Regexp.escape(cellar)}/gcc} if | ||
| Version.formula_optionally_versioned_regex(:gcc).match(f.name) | ||
| ignores = %r{#{Regexp.escape(cellar)}/binutils} if | ||
| Version.formula_optionally_versioned_regex(:binutils).match(f.name) |
There was a problem hiding this comment.
Don't use postfix if if it can't fit on one line. This can either be an if/elsif or case given that these are exclusive cases.
f775b5d to
1a0d01f
Compare
8be080d to
39174d8
Compare
Library/Homebrew/dev-cmd/bottle.rb
Outdated
| %r{#{Regexp.escape(cellar)}/binutils} | ||
| end | ||
| end | ||
| ignores ||= [] |
There was a problem hiding this comment.
Wait, do we really want to add an empty array to the ignores array (ignores in bottle_formula, not ignores in add_additional_ignores) when we're not bottling gcc or binutils on Linux?
There was a problem hiding this comment.
We probably don't need to add an empty array. Can it just be nil instead?
There was a problem hiding this comment.
It can. My recent suggestion, before the edit, returned nils with OS.mac? or when the formula isn't gcc or binutils. You can return an empty array if you make sure this method always returns an array, and you change the << to += below, though.
Library/Homebrew/dev-cmd/bottle.rb
Outdated
| def add_additional_ignores(f, cellar) | ||
| # On Linux, GCC installation can be moved so long as the whole directory tree is moved together: | ||
| # https://gcc-help.gcc.gnu.narkive.com/GnwuCA7l/moving-gcc-from-the-installation-path-is-it-allowed. | ||
| # binutils is relocatable for the same reason: https://github.com/Homebrew/brew/pull/11899#issuecomment-906804451. | ||
| ignores = if OS.linux? | ||
| case f.name | ||
| when Version.formula_optionally_versioned_regex(:gcc) | ||
| %r{#{Regexp.escape(cellar)}/gcc} | ||
| when Version.formula_optionally_versioned_regex(:binutils) | ||
| %r{#{Regexp.escape(cellar)}/binutils} | ||
| end | ||
| end | ||
| ignores ||= [] |
There was a problem hiding this comment.
| def add_additional_ignores(f, cellar) | |
| # On Linux, GCC installation can be moved so long as the whole directory tree is moved together: | |
| # https://gcc-help.gcc.gnu.narkive.com/GnwuCA7l/moving-gcc-from-the-installation-path-is-it-allowed. | |
| # binutils is relocatable for the same reason: https://github.com/Homebrew/brew/pull/11899#issuecomment-906804451. | |
| ignores = if OS.linux? | |
| case f.name | |
| when Version.formula_optionally_versioned_regex(:gcc) | |
| %r{#{Regexp.escape(cellar)}/gcc} | |
| when Version.formula_optionally_versioned_regex(:binutils) | |
| %r{#{Regexp.escape(cellar)}/binutils} | |
| end | |
| end | |
| ignores ||= [] | |
| def formula_ignores(f, cellar) | |
| ignores = if OS.linux? | |
| case f.name | |
| # On Linux, GCC installation can be moved so long as the whole directory tree is moved together: | |
| # https://gcc-help.gcc.gnu.narkive.com/GnwuCA7l/moving-gcc-from-the-installation-path-is-it-allowed. | |
| when Version.formula_optionally_versioned_regex(:gcc) | |
| [%r{#{Regexp.escape(cellar)}/gcc/}] | |
| # binutils is relocatable for the same reason: https://github.com/Homebrew/brew/pull/11899#issuecomment-906804451. | |
| when Version.formula_optionally_versioned_regex(:binutils) | |
| [%r{#{Regexp.escape(cellar)}/binutils/}] | |
| else | |
| [] | |
| end | |
| end.freeze |
Library/Homebrew/dev-cmd/bottle.rb
Outdated
| # Add additional workarounds to ignore | ||
| ignores << add_additional_ignores(f, cellar) |
There was a problem hiding this comment.
| # Add additional workarounds to ignore | |
| ignores << add_additional_ignores(f, cellar) | |
| # Add any formula-specific workarounds | |
| ignores += add_additional_ignores(f, cellar) |
Library/Homebrew/dev-cmd/bottle.rb
Outdated
| # Add additional workarounds to ignore | ||
| ignores << add_additional_ignores(f, cellar) | ||
|
|
||
| any_go_deps = f.deps.any? do |dep| |
There was a problem hiding this comment.
I think it might be nice to figure out how to put this into the function above, too.
There was a problem hiding this comment.
Yes, I was thinking that would make sense. I'll make the change.
carlocab
left a comment
There was a problem hiding this comment.
Sorry for flip-flopping on the comments. I think this should work.
Library/Homebrew/dev-cmd/bottle.rb
Outdated
| def add_additional_ignores(f, cellar) | ||
| # On Linux, GCC installation can be moved so long as the whole directory tree is moved together: | ||
| # https://gcc-help.gcc.gnu.narkive.com/GnwuCA7l/moving-gcc-from-the-installation-path-is-it-allowed. | ||
| # binutils is relocatable for the same reason: https://github.com/Homebrew/brew/pull/11899#issuecomment-906804451. | ||
| ignores = if OS.linux? | ||
| case f.name | ||
| when Version.formula_optionally_versioned_regex(:gcc) | ||
| %r{#{Regexp.escape(cellar)}/gcc} | ||
| when Version.formula_optionally_versioned_regex(:binutils) | ||
| %r{#{Regexp.escape(cellar)}/binutils} | ||
| end | ||
| end | ||
| ignores ||= [] | ||
| ignores | ||
| end |
There was a problem hiding this comment.
| def add_additional_ignores(f, cellar) | |
| # On Linux, GCC installation can be moved so long as the whole directory tree is moved together: | |
| # https://gcc-help.gcc.gnu.narkive.com/GnwuCA7l/moving-gcc-from-the-installation-path-is-it-allowed. | |
| # binutils is relocatable for the same reason: https://github.com/Homebrew/brew/pull/11899#issuecomment-906804451. | |
| ignores = if OS.linux? | |
| case f.name | |
| when Version.formula_optionally_versioned_regex(:gcc) | |
| %r{#{Regexp.escape(cellar)}/gcc} | |
| when Version.formula_optionally_versioned_regex(:binutils) | |
| %r{#{Regexp.escape(cellar)}/binutils} | |
| end | |
| end | |
| ignores ||= [] | |
| ignores | |
| end | |
| # On Linux, GCC installation can be moved so long as the whole directory tree is moved together: | |
| # https://gcc-help.gcc.gnu.narkive.com/GnwuCA7l/moving-gcc-from-the-installation-path-is-it-allowed. | |
| # binutils is relocatable for the same reason: https://github.com/Homebrew/brew/pull/11899#issuecomment-906804451. | |
| def gcc_or_binutils_regex_if_applicable(f, cellar) | |
| return [] unless OS.linux? | |
| case f.name | |
| when Version.formula_optionally_versioned_regex(:gcc) | |
| [%r{#{Regexp.escape(cellar)}/gcc}] | |
| when Version.formula_optionally_versioned_regex(:binutils) | |
| [%r{#{Regexp.escape(cellar)}/binutils}] | |
| end | |
| end |
Library/Homebrew/dev-cmd/bottle.rb
Outdated
| ignores = [%r{/include/|\.(c|cc|cpp|h|hpp)$}] | ||
|
|
||
| # Add additional workarounds to ignore | ||
| ignores << add_additional_ignores(f, cellar) |
There was a problem hiding this comment.
| ignores << add_additional_ignores(f, cellar) | |
| ignores += gcc_or_binutils_regex_if_applicable(f, cellar) |
There was a problem hiding this comment.
Yea, returning an Array instead of a NilClass or Regexp is cleaner. Amended my suggestion.
39174d8 to
ff7f81d
Compare
Library/Homebrew/dev-cmd/bottle.rb
Outdated
| %r{#{Regexp.escape(cellar)}/gcc} | ||
| when Version.formula_optionally_versioned_regex(:binutils) | ||
| %r{#{Regexp.escape(cellar)}/binutils} |
There was a problem hiding this comment.
These need to be Arrays and not Regexps (wrap them in [,]) for += to work.
a5b3a2a to
8bff652
Compare
Library/Homebrew/dev-cmd/bottle.rb
Outdated
| def add_regex_if_applicable(f, cellar, ignores) | ||
| # Ignore matches to go keg | ||
| any_go_deps = f.deps.any? do |dep| | ||
| dep.name =~ Version.formula_optionally_versioned_regex(:go) | ||
| end | ||
| if any_go_deps | ||
| go_regex = | ||
| Version.formula_optionally_versioned_regex(:go, full: false) | ||
| ignores += [%r{#{Regexp.escape(HOMEBREW_CELLAR)}/#{go_regex}/[\d.]+/libexec]}] | ||
| end | ||
|
|
||
| # On Linux, GCC installation can be moved so long as the whole directory tree is moved together: | ||
| # https://gcc-help.gcc.gnu.narkive.com/GnwuCA7l/moving-gcc-from-the-installation-path-is-it-allowed. | ||
| # binutils is relocatable for the same reason: https://github.com/Homebrew/brew/pull/11899#issuecomment-906804451. | ||
| ignores += if OS.linux? | ||
| case f.name | ||
| when Version.formula_optionally_versioned_regex(:gcc) | ||
| [%r{#{Regexp.escape(cellar)}/gcc}] | ||
| when Version.formula_optionally_versioned_regex(:binutils) | ||
| [%r{#{Regexp.escape(cellar)}/binutils}] | ||
| end | ||
| end | ||
| ignores | ||
| end |
There was a problem hiding this comment.
| def add_regex_if_applicable(f, cellar, ignores) | |
| # Ignore matches to go keg | |
| any_go_deps = f.deps.any? do |dep| | |
| dep.name =~ Version.formula_optionally_versioned_regex(:go) | |
| end | |
| if any_go_deps | |
| go_regex = | |
| Version.formula_optionally_versioned_regex(:go, full: false) | |
| ignores += [%r{#{Regexp.escape(HOMEBREW_CELLAR)}/#{go_regex}/[\d.]+/libexec]}] | |
| end | |
| # On Linux, GCC installation can be moved so long as the whole directory tree is moved together: | |
| # https://gcc-help.gcc.gnu.narkive.com/GnwuCA7l/moving-gcc-from-the-installation-path-is-it-allowed. | |
| # binutils is relocatable for the same reason: https://github.com/Homebrew/brew/pull/11899#issuecomment-906804451. | |
| ignores += if OS.linux? | |
| case f.name | |
| when Version.formula_optionally_versioned_regex(:gcc) | |
| [%r{#{Regexp.escape(cellar)}/gcc}] | |
| when Version.formula_optionally_versioned_regex(:binutils) | |
| [%r{#{Regexp.escape(cellar)}/binutils}] | |
| end | |
| end | |
| ignores | |
| end | |
| def formula_ignores(f, cellar) | |
| ignores = [] | |
| # Ignore matches to go keg | |
| # TODO: explain why | |
| any_go_deps = f.deps.any? do |dep| | |
| dep.name =~ Version.formula_optionally_versioned_regex(:go) | |
| end | |
| if any_go_deps | |
| go_regex = Version.formula_optionally_versioned_regex(:go, full: false) | |
| ignores << %r{#{Regexp.escape(HOMEBREW_CELLAR)}/#{go_regex}/[\d.]+/libexec]} | |
| end | |
| ignores << if OS.linux? | |
| case f.name | |
| # On Linux, GCC installation can be moved so long as the whole directory tree is moved together: | |
| # https://gcc-help.gcc.gnu.narkive.com/GnwuCA7l/moving-gcc-from-the-installation-path-is-it-allowed. | |
| when Version.formula_optionally_versioned_regex(:gcc) | |
| %r{#{Regexp.escape(cellar)}/gcc} | |
| # binutils is relocatable for the same reason: https://github.com/Homebrew/brew/pull/11899#issuecomment-906804451. | |
| when Version.formula_optionally_versioned_regex(:binutils) | |
| %r{#{Regexp.escape(cellar)}/binutils} | |
| end | |
| end | |
| ignores | |
| end |
Library/Homebrew/dev-cmd/bottle.rb
Outdated
| # Add additional workarounds to ignore | ||
| ignores += add_regex_if_applicable(f, cellar, ignores) |
There was a problem hiding this comment.
| # Add additional workarounds to ignore | |
| ignores += add_regex_if_applicable(f, cellar, ignores) | |
| # Add formula-specific workarounds | |
| ignores += formula_ignores(f, cellar) |
8bff652 to
9c7bce0
Compare
Library/Homebrew/dev-cmd/bottle.rb
Outdated
| go_regex = | ||
| Version.formula_optionally_versioned_regex(:go, full: false) |
There was a problem hiding this comment.
| go_regex = | |
| Version.formula_optionally_versioned_regex(:go, full: false) | |
| go_regex = Version.formula_optionally_versioned_regex(:go, full: false) |
| # On Linux, GCC installation can be moved so long as the whole directory tree is moved together: | ||
| # https://gcc-help.gcc.gnu.narkive.com/GnwuCA7l/moving-gcc-from-the-installation-path-is-it-allowed. | ||
| # binutils is relocatable for the same reason: https://github.com/Homebrew/brew/pull/11899#issuecomment-906804451. |
There was a problem hiding this comment.
Please move down these comments so it's easier to see what parts specifically refer to gcc/binutils and so adding more formulae in future won't look like they are referred to by these comments. Ideally I'd consider duplicating the if OS.linux? on each regex line and doing ignores.compact so it doesn't require as much reorganisation when other formulae are added here
There was a problem hiding this comment.
I moved things around as per your suggestions and now it should be easier to add new formulae as needed. I think it makes sense to keep the go exception separate because it is related to the dependencies of the formula rather than the formula name. But for future additions which rely on the formula name, they should be added to the case block with if OS.linux? or if OS.mac? added as needed.
9c7bce0 to
0323c3a
Compare
|
Looks great, thanks @danielnachun and sorry for all the back and forth! |
|
Thanks @MikeMcQuaid! |
|
Related? Homebrew/homebrew-core@56dd835 |
…LINKS
brew stylewith your changes locally?brew typecheckwith your changes locally?brew testswith your changes locally?This is a followup to https://github.com/Homebrew/linuxbrew-core/pull/23361. I followed the suggestion from @iMichka to add a regex to exclude the nonrelocatable strings inside the GCC formulae. For many years
:anywas manually added to the GCC cellar block on Linux so we know it works. This should guarantee this happens from now on.