Skip to content
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

gcc@11: add missing version_suffix method #119162

Closed
wants to merge 1 commit into from
Closed

gcc@11: add missing version_suffix method #119162

wants to merge 1 commit into from

Conversation

curoky
Copy link
Contributor

@curoky curoky commented Dec 26, 2022

  • Have you followed the guidelines for contributing?
  • Have you ensured that your commits follow the commit style guide?
  • Have you checked that there aren't other open pull requests for the same formula update/change?
  • Have you built your formula locally with brew install --build-from-source <formula>, where <formula> is the name of the formula you're submitting?
  • Is your test running fine brew test <formula>, where <formula> is the name of the formula you're submitting?
  • Does your build pass brew audit --strict <formula> (after doing brew install --build-from-source <formula>)? If this is a new formula, does it pass brew audit --new <formula>?

When I install custom tap's formula with HOMEBREW_INSTALL_FROM_API=1 enabled, I got follow errors.

==> Installing zsh-bundle from curoky/tap
/home/linuxbrew/.linuxbrew/Homebrew/Library/Homebrew/shims/shared/curl --disable --cookie /dev/null --globoff --show-error --user-agent Linuxbrew/3.6.16\ \(Linux\;\ x86_64\ 4.14.81.bm.30-amd64\)\ curl/7.81.0 --header Accept-Language:\ en --fail --max-time 5 --retry 3 --location --remote-time --output /root/.cache/Homebrew/api/formula.json --time-cond /root/.cache/Homebrew/api/formula.json --compressed --silent https://formulae.brew.sh/api/formula.json
/home/linuxbrew/.linuxbrew/Homebrew/Library/Homebrew/build.rb (Formulary::FormulaAPILoader): loading gcc@11 from API
/home/linuxbrew/.linuxbrew/Homebrew/Library/Homebrew/build.rb (Formulary::FormulaAPILoader): loading binutils from API
/home/linuxbrew/.linuxbrew/Homebrew/Library/Homebrew/build.rb (Formulary::FormulaAPILoader): loading make from API
/home/linuxbrew/.linuxbrew/Homebrew/Library/Homebrew/build.rb (Formulary::FormulaAPILoader): loading gcc from API
Error: An exception occurred within a child process:
  NoMethodError: undefined method `version_suffix' for #<Formulary::FormulaNamespaceAPIe0d511356bd44120af49cc96c9dcf3b3::Gcc:0x0000000005b7fa70>
Did you mean?  version_scheme
/home/linuxbrew/.linuxbrew/Homebrew/Library/Homebrew/extend/ENV/shared.rb:292:in `gcc_version_formula'
/home/linuxbrew/.linuxbrew/Homebrew/Library/Homebrew/extend/ENV/super.rb:151:in `determine_path'
/home/linuxbrew/.linuxbrew/Homebrew/Library/Homebrew/extend/ENV/super.rb:68:in `setup_build_environment'
/home/linuxbrew/.linuxbrew/Homebrew/Library/Homebrew/extend/os/linux/extend/ENV/super.rb:20:in `setup_build_environment'
/home/linuxbrew/.linuxbrew/Homebrew/Library/Homebrew/build.rb:83:in `install'
/home/linuxbrew/.linuxbrew/Homebrew/Library/Homebrew/build.rb:229:in `<main>'

I found all gcc formulas had version_suffix method except gcc@11.

def version_suffix
if build.head?
"HEAD"
else
version.major.to_s
end
end

So should we add version_suffix to gcc@11?

@BrewTestBot BrewTestBot added legacy Relates to a versioned @ formula long build Set a long timeout for formula testing labels Dec 26, 2022
@SMillerDev
Copy link
Member

Where is this actually used? Because it shouldn't be now that we have version.major

@curoky
Copy link
Contributor Author

curoky commented Dec 26, 2022

Where is this actually used? Because it shouldn't be now that we have version.major

Exception stack is follow.

/home/linuxbrew/.linuxbrew/Homebrew/Library/Homebrew/extend/ENV/shared.rb:292:in `gcc_version_formula'
/home/linuxbrew/.linuxbrew/Homebrew/Library/Homebrew/extend/ENV/super.rb:151:in `determine_path'
/home/linuxbrew/.linuxbrew/Homebrew/Library/Homebrew/extend/ENV/super.rb:68:in `setup_build_environment'
/home/linuxbrew/.linuxbrew/Homebrew/Library/Homebrew/extend/os/linux/extend/ENV/super.rb:20:in `setup_build_environment'
/home/linuxbrew/.linuxbrew/Homebrew/Library/Homebrew/build.rb:83:in `install'
/home/linuxbrew/.linuxbrew/Homebrew/Library/Homebrew/build.rb:229:in `<main>'
module Superenv
  ...
  def determine_path
    ...
    begin
      path.append(gcc_version_formula(T.must(homebrew_cc)).opt_bin) if homebrew_cc&.match?(GNU_GCC_REGEXP)
    rescue FormulaUnavailableError
      # Don't fail and don't add these formulae to the path if they don't exist.
      nil
    end
  end
  ...
end

https://github.com/Homebrew/brew/blob/master/Library/Homebrew/extend/ENV/super.rb#L141-L158

module SharedEnvExtension
  ...
  def gcc_version_formula(name)
    version = name[GNU_GCC_REGEXP, 1]
    gcc_version_name = "gcc@#{version}"

    gcc = Formulary.factory("gcc")
    if gcc.version_suffix == version
      gcc
    else
      Formulary.factory(gcc_version_name)
    end
  end
  ...
 end

https://github.com/Homebrew/brew/blob/master/Library/Homebrew/extend/ENV/shared.rb#L286-L297

It seems that homebrew_cc&.match?(GNU_GCC_REGEXP) has a problem.

@curoky
Copy link
Contributor Author

curoky commented Dec 26, 2022

I tried to set export HOMEBREW_CC=gcc, and it works.

@curoky
Copy link
Contributor Author

curoky commented Dec 26, 2022

This is my Dockerfile, it will fail when remove HOMEBREW_CC=gcc, in addition, it seems only happened when using custom tap.

FROM ubuntu:22.10 as homebrew2
ENV HOMEBREW_NO_ANALYTICS=1 \
  HOMEBREW_NO_AUTO_UPDATE=1 \
  HOMEBREW_INSTALL_FROM_API=1 \
  HOMEBREW_CC=gcc \
  DEBIAN_FRONTEND=noninteractive \
  PATH="/home/linuxbrew/.linuxbrew/bin:/home/linuxbrew/.linuxbrew/sbin:${PATH}"
RUN apt-get update -qq \
  && apt-get install -y -qq --no-install-recommends \
    ca-certificates git curl zip unzip tar make g++ patch file less \
  && bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)" \
  && brew install curoky/tap/zsh-bundle

@carlocab
Copy link
Member

This should be fixed in brew instead of adding an unused method in a formula.

@cho-m cho-m added the brew Issue may be Homebrew/brew related label Dec 30, 2022
@fxcoudert
Copy link
Member

Agreed with the above, brew should be fixed. Closing this PR.

@fxcoudert fxcoudert closed this Dec 31, 2022
@yermulnik
Copy link
Contributor

Is there an issue in brew to track this? Today I hit this which looks a bit alike:

> brew upgrade
Running `brew update --auto-update`...
==> Auto-updated Homebrew!
==> Updated Homebrew from 518c961f4 to d636f5bc0.
No changes to formulae.

==> Upgrading 1 outdated package:
snyk/tap/snyk 1.1088.0 -> 1.1089.0
==> Fetching snyk/tap/snyk
==> Downloading https://static.snyk.io/cli/v1.1089.0/snyk-linux
######################################################################## 100.0%
==> Upgrading snyk/tap/snyk
  1.1088.0 -> 1.1089.0

Error: An exception occurred within a child process:
  NoMethodError: undefined method `version_suffix' for #<Formulary::FormulaNamespaceAPIe0d511356bd44120af49cc96c9dcf3b3::Gcc:0x0000000008d80290>
Did you mean?  version_scheme

snyk's formulae has no version_suffix in it (https://github.com/snyk/homebrew-tap/blob/master/Formula/snyk.rb), so I'm assuming it is something else (though I'm not quite familiar with brew to figure this myself).
Thanks for any clue (or should I just ignore this?).

@yermulnik
Copy link
Contributor

Just ran brew upgrade once again and I can see this is perpetual error 😢

> brew upgrade
Running `brew update --auto-update`...
==> Upgrading 2 outdated packages:
linux-headers@5.15 5.15.89 -> 5.15.90
snyk/tap/snyk 1.1088.0 -> 1.1089.0
==> Fetching linux-headers@5.15
==> Downloading https://ghcr.io/v2/homebrew/core/linux-headers/5.15/manifests/5.15.90
######################################################################## 100.0%
==> Downloading https://ghcr.io/v2/homebrew/core/linux-headers/5.15/blobs/sha256:74d8d15daf4367651a72a46c7aba
==> Downloading from https://pkg-containers.githubusercontent.com/ghcr1/blobs/sha256:74d8d15daf4367651a72a46c
######################################################################## 100.0%
==> Fetching snyk/tap/snyk
==> Downloading https://static.snyk.io/cli/v1.1089.0/snyk-linux
Already downloaded: /home/yz/.cache/Homebrew/downloads/55a2484afb83e3dec9dc4ead5a78c5941c9fd5cf8704c0742a2b95552--snyk-linux
==> Upgrading linux-headers@5.15
  5.15.89 -> 5.15.90

==> Pouring linux-headers@5.15--5.15.90.x86_64_linux.bottle.tar.gz
✔  /home/linuxbrew/.linuxbrew/Cellar/linux-headers@5.15/5.15.90: 963 files, 5.7MB
==> Running `brew cleanup linux-headers@5.15`...
Disable this behaviour by setting HOMEBREW_NO_INSTALL_CLEANUP.
Hide these hints with HOMEBREW_NO_ENV_HINTS (see `man brew`).
Removing: /home/linuxbrew/.linuxbrew/Cellar/linux-headers@5.15/5.15.89... (963 files, 5.7MB)
Removing: /home/yz/.cache/Homebrew/linux-headers@5.15--5.15.89... (1.5MB)
==> Upgrading snyk/tap/snyk
  1.1088.0 -> 1.1089.0

Error: An exception occurred within a child process:
  NoMethodError: undefined method `version_suffix' for #<Formulary::FormulaNamespaceAPIe0d511356bd44120af49cc3b3::Gcc:0x0000000009a164c8>
Did you mean?  version_scheme

@curoky
Copy link
Contributor Author

curoky commented Jan 25, 2023

@yermulnik I sidestep that by set env HOMEBREW_CC=gcc, you can try it.

@yermulnik
Copy link
Contributor

@curoky Yay, that worked! Thanks 👍🏻

@carlocab
Copy link
Member

Note: this should have been fixed in Homebrew/brew#14426.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
brew Issue may be Homebrew/brew related legacy Relates to a versioned @ formula long build Set a long timeout for formula testing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants