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

Formula dependency incorrectly marked as installed_on_request upon upgrade/migration #18754

Open
3 tasks done
kidonng opened this issue Nov 12, 2024 · 6 comments · May be fixed by #18768
Open
3 tasks done

Formula dependency incorrectly marked as installed_on_request upon upgrade/migration #18754

kidonng opened this issue Nov 12, 2024 · 6 comments · May be fixed by #18768
Labels
bug Reproducible Homebrew/brew bug

Comments

@kidonng
Copy link
Contributor

kidonng commented Nov 12, 2024

brew doctor output

Your system is ready to brew.

Verification

  • My "brew doctor output" above says Your system is ready to brew. and am still able to reproduce my issue.
  • I ran brew update twice and am still able to reproduce my issue.
  • This issue's title and/or description do not reference a single formula e.g. brew install wget. If they do, open an issue at https://github.com/Homebrew/homebrew-core/issues/new/choose instead.

brew config output

HOMEBREW_VERSION: 4.4.5
ORIGIN: https://github.com/Homebrew/brew
HEAD: 254bf3fe9d8fa2e1b2fb55dbcf535b2d870180c4
Last commit: 23 hours ago
Core tap JSON: 12 Nov 09:38 UTC
Core cask tap JSON: 12 Nov 09:38 UTC
HOMEBREW_PREFIX: /opt/homebrew
HOMEBREW_CASK_OPTS: []
HOMEBREW_EDITOR: code
HOMEBREW_MAKE_JOBS: 8
Homebrew Ruby: 3.3.6 => /opt/homebrew/Library/Homebrew/vendor/portable-ruby/3.3.6/bin/ruby
CPU: octa-core 64-bit arm_firestorm_icestorm
Clang: 16.0.0 build 1600
Git: 2.47.0 => /opt/homebrew/bin/git
Curl: 8.7.1 => /usr/bin/curl
macOS: 15.1-arm64
CLT: 16.1.0.0.1.1729049160
Xcode: N/A
Rosetta 2: false

What were you trying to do (and why)?

pkg-config was installed as a dependency of rust on my machine. Homebrew/homebrew-core#194885 replaced pkg-config with pkgconf, and after upgrading and doing brew bundle dump, I noticed pkgconf now becomes part of the generated Brewfile, which it probably shouldn't:

$ chezmoi diff --reverse
diff --git a/.Brewfile b/.Brewfile
index ea055bf1f44199bf23b351bd130cc91929545b74..2cf5aaa3d33c8d6b55eed2bbf4447aa89ebad047 100644
--- a/.Brewfile
+++ b/.Brewfile
@@ -8,6 +8,7 @@ brew "fzf"
 brew "git"
 brew "mpv"
 brew "node"
+brew "pkgconf"
 brew "rust"

What happened (include all command output)?

After investigation it turns out pkgconf is somehow marked as installed_on_request after upgrading:

$ jq .installed_as_dependency /opt/homebrew/Cellar/pkgconf/2.3.0_1/INSTALL_RECEIPT.json
false
$ jq .installed_on_request /opt/homebrew/Cellar/pkgconf/2.3.0_1/INSTALL_RECEIPT.json
true

What did you expect to happen?

Compared to a normal dependency:

$ jq .installed_as_dependency /opt/homebrew/Cellar/brotli/1.1.0/INSTALL_RECEIPT.json
true

$ jq .installed_on_request /opt/homebrew/Cellar/brotli/1.1.0/INSTALL_RECEIPT.json
false

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

1. Make sure on a older Core tap JSON before `pkg-config` migration
2. Have `pkg-config` installed as a dependency (e.g. by `brew install rust`)
3. `brew upgrade` to upgrade `pkg-config` to `pkgconf`
4. `brew bundle dump`
5. See `pkgconf` is in the generated `Brewfile`
@kidonng kidonng added the bug Reproducible Homebrew/brew bug label Nov 12, 2024
@gromgit
Copy link
Member

gromgit commented Nov 12, 2024

Did you do a targeted upgrade, i.e. brew upgrade pkg-config or brew upgrade pkgconf instead of just brew upgrade? If so, that marks the package as installed-on-request. The same goes for brew reinstall <formula>.

If all you did was brew upgrade, then that begs the question: should any install operation change the installed-on-request status of already-installed formulae?

Anyway, the workaround: brew tab --no-installed-on-request pkgconf.

@ZhongRuoyu
Copy link
Member

ZhongRuoyu commented Nov 12, 2024

It seems that a plain brew upgrade did cause pkgconf to be marked as installed on request although pkg-config wasn't previously. I reproduced this locally.

installed_as_dependency in the tab, on the other hand, changed from true to false.

@gromgit
Copy link
Member

gromgit commented Nov 12, 2024

That seems like a bug to me. In fact, as I mentioned elsewhere, it's puzzling that anything but the original formula install (requested or dependency) should automatically change those flags. Surely the fact that XYZ needs to be reinstalled doesn't change the reason it was installed in the first place?

@MikeMcQuaid
Copy link
Member

It seems that a plain brew upgrade did cause pkgconf to be marked as installed on request although pkg-config wasn't previously. I reproduced this locally.

@ZhongRuoyu seems like a bug with the alias migration stuff for png-config.

If all you did was brew upgrade, then that begs the question: should any install operation change the installed-on-request status of already-installed formulae?

brew install foo should at least change this status for foo. This is consistent with what apt-get does.

Increasingly I wonder if brew upgrade foo should do so, that seems a bit more ill advised.

brew upgrade should not/never.

@kidonng
Copy link
Contributor Author

kidonng commented Nov 12, 2024

Did you do a targeted upgrade, i.e. brew upgrade pkg-config or brew upgrade pkgconf instead of just brew upgrade?

Just brew upgrade, same as the result @ZhongRuoyu has reproduced.

Anyway, the workaround: brew tab --no-installed-on-request pkgconf.

I don't think that is enough to avoid it in Brewfile since brew bundle checks both installed_on_request and installed_as_dependency:

https://github.com/Homebrew/homebrew-bundle/blob/055eb6e7c6fc2e2d5fce43c6531a23ded4cb5d7a/lib/bundle/brew_dumper.rb#L55-L57

(As for my case I corrected the fields in INSTALL_RECEIPT.json manually)

@cho-m
Copy link
Member

cho-m commented Nov 12, 2024

I guess trying to find old Keg fails as new directory doesn't exist on filesystem for formula-to-alias as opposed to rename migrator

if formula.opt_prefix.directory?
keg = Keg.new(formula.opt_prefix.resolved_path)
tab = keg.tab

So false || nil is nil which gets compacted and the default installed_on_request: true is used.

installed_on_request: installed_on_request || tab&.installed_on_request,

@MikeMcQuaid MikeMcQuaid linked a pull request Nov 13, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Reproducible Homebrew/brew bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants