Homebrew / brew

🍺 The missing package manager for macOS (or Linux)
https://brew.sh
BSD 2-Clause "Simplified" License
41.18k stars 9.67k forks source link

Unable to install locally-created formula #14757

Closed slonopotamus closed 1 year ago

slonopotamus commented 1 year ago

brew doctor output

Your system is ready to brew.

Verification

brew config output

HOMEBREW_VERSION: 4.0.3-32-ga3207a0
ORIGIN: https://github.com/Homebrew/brew
HEAD: a3207a03900d7b012c999fad911a701baed82be5
Last commit: 4 hours ago
Core tap origin: https://github.com/Homebrew/homebrew-core
Core tap HEAD: 2139082eb669959892f14eb201421a2fe5069677
Core tap last commit: 17 hours ago
Core tap branch: master
Core tap JSON: 22 Feb 07:54 UTC
HOMEBREW_PREFIX: /usr/local
HOMEBREW_CASK_OPTS: []
HOMEBREW_MAKE_JOBS: 12
Homebrew Ruby: 2.6.8 => /usr/local/Homebrew/Library/Homebrew/vendor/portable-ruby/2.6.8_1/bin/ruby
CPU: dodeca-core 64-bit kabylake
Clang: 14.0.0 build 1400
Git: 2.33.0 => /usr/local/bin/git
Curl: 7.79.1 => /usr/bin/curl
macOS: 12.6.3-x86_64
CLT: 14.2.0.0.1.1668646533
Xcode: 14.0.1

What were you trying to do (and why)?

I'm trying to follow the basic formula creation procedure and absolutely fail.

The simplest thing that I try is:

% brew create --set-name bla https://github.com/octobuild/octobuild/archive/refs/tags/0.5.0.tar.gz && \
  brew install --build-from-source bla

However, I observe brew fully ignores the file I've created and instead tries to download formula with the same name from the internets (where it obviously doesn't exist, because I've just created it).

What happened (include all command output)?

% brew install --build-from-source bla 
==> Fetching bla
curl: (22) The requested URL returned error: 404                              

Error: Failure while executing; `/usr/bin/env /usr/local/Homebrew/Library/Homebrew/shims/shared/curl --disable --cookie /dev/null --globoff --show-error --user-agent Homebrew/4.0.3-32-ga3207a0\ \(Macintosh\;\ Intel\ Mac\ OS\ X\ 12.6.3\)\ curl/7.79.1 --header Accept-Language:\ en --fail --progress-bar --retry 3 --location --remote-time --output /Users/cucumber/Library/Caches/Homebrew/Formula/bla.rb https://raw.githubusercontent.com/Homebrew/homebrew-core/2139082eb669959892f14eb201421a2fe5069677/Formula/bla.rb` exited with 22. Here's the output:
curl: (22) The requested URL returned error: 404

What did you expect to happen?

I expected brew to use the formula file that I've just created.

Either I'm missing some step when following docs (this is the very first time I'm working with brew), or docs are not complete, or there's a bug in brew.

Step-by-step reproduction instructions (by running brew commands)

brew create --set-name bla https://github.com/octobuild/octobuild/archive/refs/tags/0.5.0.tar.gz
brew install --build-from-source bla
carlocab commented 1 year ago

Do

HOMEBREW_NO_INSTALL_FROM_API=1 brew install --build-from-source bla
slonopotamus commented 1 year ago

Thanks for the quick response, that works. I guess it should be documented on the page I'm referring to.

slonopotamus commented 1 year ago

Now, when I know about HOMEBREW_NO_INSTALL_FROM_API existense, it looks that the source of current issue is https://github.com/Homebrew/brew/pull/14520. Before that commit, I would at least get an error message that would refer to HOMEBREW_NO_INSTALL_FROM_API, but now it's gone.

carlocab commented 1 year ago

CC @Bo98

slonopotamus commented 1 year ago

Also, possibly related to https://github.com/Homebrew/brew/pull/14480. It's title talks about automatically enabling HOMEBREW_NO_INSTALL_FROM_API=1 when building from source, but that PR does something different. --build-from-source doesn't automatically enable HOMEBREW_NO_INSTALL_FROM_API=1 as we can see in current issue.

Bo98 commented 1 year ago

This is somewhat intentional. This is because when you pass --build-from-source you are in one of two scenarios and your intention isn't clear from that flag alone. You either:

The former scenario is far more common and is one that is more likely to be automated - so we break a lot by disrupting that. Personally: I also want as many people using the API where possible as the security & performance benefits of the API is substantial - if you use it you have bigger guarantees you are using what we are shipping.

However I recognise it may be confusing for contributors so I think we can do something smarter and show an env hint to anyone who passes and --build-from-source and either:

In terms of new formulae: there's also an open PR that will help here too. The current conditions are it does the current route if it's a core formula and API mode is enabled. This is slightly incorrect: it will be adjusted to only happen if the formulae has actually been loaded from API - which is not the case for your particular example so should hopefully work as expected automatically after that (will test to confirm).

slonopotamus commented 1 year ago

you are in one of two scenarios and your intention isn't clear from that flag alone

Well, you can easily make it explicit by adding some kind of brew install --local <formula> or brew install --file <path/to/formula> or brew install --dev <formula>.

However I recognise it may be confusing for contributors

Exactly. My main concern is not that HOMEBREW_NO_INSTALL_FROM_API exists (though I'd say that HOMEBREW_NO_INSTALL_FROM_API=1 brew install --build-from-source <formula> command could be a bit shorter). What concerns me is that Homebrew has multiple docs on how to create a new formula and neither of them mentions HOMEBREW_NO_INSTALL_FROM_API. Even PR checklist in https://github.com/Homebrew/homebrew-core just tells contributors to do brew install --build-from-source <formula>.

slonopotamus commented 1 year ago

BTW, this is how brew 4.0.3 behaves when given a full path to formula file:

% brew install --build-from-source /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/octobuild.rb
Error: Failed to load cask: /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/octobuild.rb
Cask 'octobuild' is unreadable: wrong constant name #<Class:0x00007f8e0329d8b0>
Warning: Treating /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/octobuild.rb as a formula.
==> Fetching octobuild
curl: (22) The requested URL returned error: 404                              

Error: Failure while executing; `/usr/bin/env /usr/local/Homebrew/Library/Homebrew/shims/shared/curl --disable --cookie /dev/null --globoff --show-error --user-agent Homebrew/4.0.3-32-ga3207a0\ \(Macintosh\;\ Intel\ Mac\ OS\ X\ 12.6.3\)\ curl/7.79.1 --header Accept-Language:\ en --fail --progress-bar --retry 3 --location --remote-time --output /Users/cucumber/Library/Caches/Homebrew/Formula/octobuild.rb https://raw.githubusercontent.com/Homebrew/homebrew-core/b416edcb1e2fba0793ff74ef3875f24174678b63/Formula/octobuild.rb` exited with 22. Here's the output:
curl: (22) The requested URL returned error: 404

It

  1. Errors that file is not a cask (obviously, I wrote a formula, not a cask)
  2. Nevertheless, continues execution (so maybe that was not so much of an error?)
  3. Warns that file is treated as a formula (what else can it be? why this is a warning?)
  4. Still proceeds to fully ignore the file and try to download formula from internets