Homebrew / homebrew-bundle

📦 Bundler for non-Ruby dependencies from Homebrew, Homebrew Cask and the Mac App Store.
MIT License
5.34k stars 287 forks source link

An option to skip transitive dependencies when dumping #1489

Closed ELLIOTTCABLE closed 3 hours ago

ELLIOTTCABLE commented 4 hours ago

Would it be possible to dump only to dump "installed formulae that are not dependencies of another installed formula" just like brew leaves does?

This is already the case. brew leaves (as-is_ is not the right tool for the job here, though; just because something is a leaf does not mean you don't want it listed in your Brewfile. brew bundle effectively runs brew leaves --installed-on-request. If there's something being brew bundle dumpd that you don't want: it's because at some point you or some tool brew installed it.

To resolve this for your particular case e.g. libfido2 you should do something like:

brew uninstall --ignore-dependencies libfido2
brew install --only-dependencies mysql mysql-client

then, if my memory serves me correctly, it'll no longer brew bundle dump libfido2.

Originally posted by @MikeMcQuaid in https://github.com/Homebrew/homebrew-bundle/issues/1260#issuecomment-1759397149

This was brought up previously, but closed, due to it not actually being a behaviour at the time. However, since then, it appears to be have been added as an intentional behaviour (i.e. brew bundle dump is currently including packages that do not appear in brew leaves - in fact, they're sorted non-alphabetically, before their leaf dependants, so it's pretty clear it's an intentional process.)

It'd be nice to be able to disable this behaviour optionally. Especially because there's no differentiation in the file between what was a leaf, and what was not; so that metadata is lost upon installation to a new system (or just ... existing for a couple of years, and forgetting what you've installed and why. 😅)

$ brew --version      
Homebrew 4.4.4-41-g451c3a8
Homebrew/homebrew-cask (git revision 7ee2e0d5f65; last commit 2024-11-05)
MikeMcQuaid commented 3 hours ago

Sorry, passing on this. This is intentional behaviour. Homebrew has no concept of leaves: only things installed on request or as dependencies. As mentioned previously: dependencies that are installed on request must be dumped earlier because they will be installed earlier and otherwise the error messages if they fail to install are unnecessarily confusing.

Especially because there's no differentiation in the file between what was a leaf, and what was not; so that metadata is lost upon installation to a new system

This metadata was never stored. What is installed on request, however, is not lost: it will still be installed on request on a new system and installed as a dependency when not specified in the Brewfile.

ELLIOTTCABLE commented 3 hours ago

This metadata was never stored. What is installed on request, however, is not lost: it will still be installed on request on a new system and installed as a dependency when not specified in the Brewfile.

Wait, I'm confused; it's not lost?

As in, if I run one of the new brewfiles (that includes, say, brew "aom" before brew "imagemagick") on a new system, then brew leaves --installed-on-request won't print "aom"? Because that's my primary concern, polluting of the 'installed on request' list, which is a pretty crucial resource when working across a lot of languages, stacks, and projects, across multiple machines. 😅