KEMBAR78
Add `Formula#tap_path` and use `Formula#latest_formula` by Rylan12 · Pull Request #20895 · Homebrew/brew · GitHub
Skip to content

Conversation

Rylan12
Copy link
Member

@Rylan12 Rylan12 commented Oct 17, 2025

This PR extracts some of the changes from #20830

These changes include:

  1. Adding Formula#tap_path which outputs the expected path within a tap that a formula will live, regardless of whether the tap is currently installed or not.
  2. Uses Formula#latest_formula in several places where we eventually will need the latest formula explicitly.

Note, until a later PR, these changes should not affect any behavior.

@Copilot Copilot AI review requested due to automatic review settings October 17, 2025 14:00
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR introduces a new Formula#tap_path method that returns the expected path within a tap for a formula, regardless of whether the tap is currently installed, and replaces several direct references to self with Formula#latest_formula to explicitly obtain the latest formula version. These changes prepare the codebase for future functionality without altering current behavior.

Key Changes

  • Added Formula#tap_path method that returns the formula's expected path within its tap
  • Updated Formula#latest_formula to call Formulary.factory(name) instead of returning self
  • Enhanced test stubs to include name method on FormulaLoader instances

Reviewed Changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated no comments.

Show a summary per file
File Description
Library/Homebrew/formula.rb Added tap_path method; updated latest_formula to use Formulary.factory(name); updated outdated_kegs to use latest_formula
Library/Homebrew/formula_versions.rb Changed to use tap_path instead of path
Library/Homebrew/dev-cmd/bottle.rb Updated bottle metadata to use tap_path instead of path
Library/Homebrew/cmd/reinstall.rb Updated to use latest_formula when building install context
Library/Homebrew/cmd/outdated.rb Updated to use latest_formula.pkg_version
Library/Homebrew/test/support/helper/formula.rb Added name method stub to FormulaLoader double
Library/Homebrew/test/migrator_spec.rb Added Formulary.factory stubs for formula names
Library/Homebrew/test/formula_spec.rb Added stub_formula_loader calls and cache clearing

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@Rylan12 Rylan12 force-pushed the tap-path-and-latest-formula branch from 192168d to de7e904 Compare October 17, 2025 14:01
@Rylan12 Rylan12 added this pull request to the merge queue Oct 17, 2025
@Rylan12
Copy link
Member Author

Rylan12 commented Oct 17, 2025

Maintainers: if this causes something to break, please ping me. I am lightly monitoring for the next several hours, and will try to fix forward if I can

Merged via the queue into main with commit 0ac4836 Oct 17, 2025
35 checks passed
@Rylan12 Rylan12 deleted the tap-path-and-latest-formula branch October 17, 2025 15:45
@yermulnik
Copy link
Contributor

yermulnik commented Oct 19, 2025

Maintainers: if this causes something to break, please ping me. I am lightly monitoring for the next several hours, and will try to fix forward if I can

Hi @Rylan12,
Not a maintainer, but pinging you: seems like the de7e904 has brought a regression, where Brew upgrade doesn't respect Tap if the formulae in Core has the same name. See #16213 for a somewhat alike issue (though a bit different) identified back in 2023.
The commit fa68f3d, which is right before the mentioned commit, is all good though.

Please see the below output where Brew replaces madh93/tap/tpm with tpm from Core (brew developer is turned on and HOMEBREW_NO_AUTO_UPDATE env var is set to 1 to prevent auto-updates):

> git -C /home/linuxbrew/.linuxbrew/Homebrew/ checkout de7e904887
HEAD is now at de7e904887 Explicitly use `Formula#latest_formula` where needed

> brew --version
Homebrew 4.6.17-52-gde7e904

> brew uninstall tpm && brew install madh93/tap/tpm && brew upgrade
Uninstalling /home/linuxbrew/.linuxbrew/Cellar/tpm/3.1.0... (43 files, 109KB)
==> Fetching downloads for: tpm
==> Fetching madh93/tap/tpm
==> Downloading https://github.com/Madh93/tpm/releases/download/v0.4.0/tpm_Linux_x86_64.tar.gz
==> Downloading from https://release-assets.githubusercontent.com/github-production-release-asset/6287
############################################################################################### 100.0%
==> Installing tpm from madh93/tap
✔  /home/linuxbrew/.linuxbrew/Cellar/tpm/0.4.0: 6 files, 8.9MB, built in 1 second
==> Running `brew cleanup tpm`...
Disable this behaviour by setting `HOMEBREW_NO_INSTALL_CLEANUP=1`.
Hide these hints with `HOMEBREW_NO_ENV_HINTS=1` (see `man brew`).
Removing: /home/georgii/.cache/Homebrew/tpm_bottle_manifest--3.1.0-1... (2.5KB)
Removing: /home/georgii/.cache/Homebrew/tpm--3.1.0... (15.2KB)
==> Upgrading 1 outdated package:
tpm 0.4.0 -> 3.1.0
==> Fetching downloads for: tpm
==> Fetching tpm
==> Downloading https://ghcr.io/v2/homebrew/core/tpm/blobs/sha256:585e25b7dbe7d14caa7056eb0cc5f180256d
############################################################################################### 100.0%
==> Upgrading tpm
  0.4.0 -> 3.1.0
==> Pouring tpm--3.1.0.all.bottle.1.tar.gz
==> Caveats
To initialize TPM add this to your tmux configuration file
(~/.tmux.conf or $XDG_CONFIG_HOME/tmux/tmux.conf):
  run '/home/linuxbrew/.linuxbrew/opt/tpm/share/tpm/tpm'
==> Summary
✔  /home/linuxbrew/.linuxbrew/Cellar/tpm/3.1.0: 43 files, 109KB
==> Running `brew cleanup tpm`...
Disable this behaviour by setting `HOMEBREW_NO_INSTALL_CLEANUP=1`.
Hide these hints with `HOMEBREW_NO_ENV_HINTS=1` (see `man brew`).
Removing: /home/linuxbrew/.linuxbrew/Cellar/tpm/0.4.0... (6 files, 8.9MB)
Removing: /home/georgii/.cache/Homebrew/tpm--0.4.0.tar.gz... (3.6MB)

Good commit, where formulae from Tap isn't replaced by one from Core (fa68f3d):

> git -C /home/linuxbrew/.linuxbrew/Homebrew/ checkout fa68f3d30f
Previous HEAD position was de7e904887 Explicitly use `Formula#latest_formula` where needed
HEAD is now at fa68f3d30f Add `Formula#tap_path` method for theoretical formula file location in tap

> brew --version
Homebrew 4.6.17-51-gfa68f3d

> brew uninstall tpm && brew install madh93/tap/tpm && brew upgrade
Uninstalling /home/linuxbrew/.linuxbrew/Cellar/tpm/3.1.0... (43 files, 109KB)
==> Fetching downloads for: tpm
==> Fetching madh93/tap/tpm
==> Downloading https://github.com/Madh93/tpm/releases/download/v0.4.0/tpm_Linux_x86_64.tar.gz
==> Downloading from https://release-assets.githubusercontent.com/github-production-release-asset/6287
############################################################################################### 100.0%
==> Installing tpm from madh93/tap
✔  /home/linuxbrew/.linuxbrew/Cellar/tpm/0.4.0: 6 files, 8.9MB, built in 1 second
==> Running `brew cleanup tpm`...
Disable this behaviour by setting `HOMEBREW_NO_INSTALL_CLEANUP=1`.
Hide these hints with `HOMEBREW_NO_ENV_HINTS=1` (see `man brew`).
Removing: /home/georgii/.cache/Homebrew/tpm_bottle_manifest--3.1.0-1... (2.5KB)
Removing: /home/georgii/.cache/Homebrew/tpm--3.1.0... (15.2KB)

Please let me know if you'd like me to "convert" this to an issue.
Thanks.

@Rylan12
Copy link
Member Author

Rylan12 commented Oct 20, 2025

Thanks for the ping, @yermulnik, and I appreciate the thorough reproduction instructions!

I can indeed reproduce this, and @botantony's PR linked above fixes the issue for me. Once that's fully merged, try running brew update and checking if the issue is resolved. If not, can you open an actual issue, and I'll dive into this more?

@yermulnik
Copy link
Contributor

It works as expected with Brew 4.6.17-67-g00001be for me now.
Thanks @Rylan12 and @botantony 👍🏻

ZhongRuoyu added a commit that referenced this pull request Oct 21, 2025
This broke in fa68f3d (#20895). Since `Formula#tap_path` returns the
theoretical/canonical location within a tap that a formula will live, it
may not correspond to the actual location of the formula file (e.g.,
when a non-official tap is sharded). Using `Formula#path` instead
correctly tracks the actual file location.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants