From e41a1f6d8ae241836dc27b726d2d1aea66b5f635 Mon Sep 17 00:00:00 2001 From: Mike McQuaid Date: Fri, 21 Mar 2025 15:49:22 +0000 Subject: [PATCH] Add `brew install --as-dependency` This option avoids needing to immediately use `brew tab --no-installed-on-request` when manually installing a dependency. --- Library/Homebrew/cmd/install.rb | 7 ++++++- Library/Homebrew/install.rb | 6 ++++-- .../Homebrew/sorbet/rbi/dsl/homebrew/cmd/install_cmd.rbi | 3 +++ completions/bash/brew | 2 ++ completions/fish/brew.fish | 2 ++ completions/zsh/_brew | 6 ++++-- docs/Manpage.md | 4 ++++ manpages/brew.1 | 3 +++ 8 files changed, 28 insertions(+), 5 deletions(-) diff --git a/Library/Homebrew/cmd/install.rb b/Library/Homebrew/cmd/install.rb index 5f19ce4671..c4125ba426 100644 --- a/Library/Homebrew/cmd/install.rb +++ b/Library/Homebrew/cmd/install.rb @@ -104,6 +104,9 @@ module Homebrew [:switch, "--skip-link", { description: "Install but skip linking the keg into the prefix.", }], + [:switch, "--as-dependency", { + description: "Install but mark as installed as a dependency and not installed on request.", + }], [:flag, "--bottle-arch=", { depends_on: "--build-bottle", description: "Optimise bottles for the specified architecture rather than the oldest " \ @@ -311,6 +314,8 @@ module Homebrew Install.install_formulae( installed_formulae, + installed_on_request: !args.as_dependency?, + installed_as_dependency: args.as_dependency?, build_bottle: args.build_bottle?, force_bottle: args.force_bottle?, bottle_arch: args.bottle_arch, @@ -336,7 +341,7 @@ module Homebrew Upgrade.check_installed_dependents( installed_formulae, flags: args.flags_only, - installed_on_request: args.named.present?, + installed_on_request: !args.as_dependency?, force_bottle: args.force_bottle?, build_from_source_formulae: args.build_from_source_formulae, interactive: args.interactive?, diff --git a/Library/Homebrew/install.rb b/Library/Homebrew/install.rb index 16af0215a6..140f7953cd 100644 --- a/Library/Homebrew/install.rb +++ b/Library/Homebrew/install.rb @@ -233,6 +233,8 @@ module Homebrew def install_formulae( formulae_to_install, + installed_on_request: true, + installed_as_dependency: false, build_bottle: false, force_bottle: false, bottle_arch: nil, @@ -261,8 +263,8 @@ module Homebrew formula_installer = FormulaInstaller.new( formula, options: build_options.used_options, - installed_on_request: true, - installed_as_dependency: false, + installed_on_request:, + installed_as_dependency:, build_bottle:, force_bottle:, bottle_arch:, diff --git a/Library/Homebrew/sorbet/rbi/dsl/homebrew/cmd/install_cmd.rbi b/Library/Homebrew/sorbet/rbi/dsl/homebrew/cmd/install_cmd.rbi index 164120bae8..8215d6dc05 100644 --- a/Library/Homebrew/sorbet/rbi/dsl/homebrew/cmd/install_cmd.rbi +++ b/Library/Homebrew/sorbet/rbi/dsl/homebrew/cmd/install_cmd.rbi @@ -20,6 +20,9 @@ class Homebrew::Cmd::InstallCmd::Args < Homebrew::CLI::Args sig { returns(T.nilable(String)) } def appdir; end + sig { returns(T::Boolean) } + def as_dependency?; end + sig { returns(T::Boolean) } def ask?; end diff --git a/completions/bash/brew b/completions/bash/brew index c1ee9ed284..c1f63c5822 100644 --- a/completions/bash/brew +++ b/completions/bash/brew @@ -1402,6 +1402,7 @@ _brew_instal() { --HEAD --adopt --appdir + --as-dependency --ask --audio-unit-plugindir --binaries @@ -1467,6 +1468,7 @@ _brew_install() { --HEAD --adopt --appdir + --as-dependency --ask --audio-unit-plugindir --binaries diff --git a/completions/fish/brew.fish b/completions/fish/brew.fish index 234412aa5f..1f854a1722 100644 --- a/completions/fish/brew.fish +++ b/completions/fish/brew.fish @@ -944,6 +944,7 @@ __fish_brew_complete_arg 'info; and not __fish_seen_argument -l formula -l formu __fish_brew_complete_arg 'instal' -l HEAD -d 'If formula defines it, install the HEAD version, aka. main, trunk, unstable, master' __fish_brew_complete_arg 'instal' -l adopt -d 'Adopt existing artifacts in the destination that are identical to those being installed. Cannot be combined with `--force`' __fish_brew_complete_arg 'instal' -l appdir -d 'Target location for Applications (default: `/Applications`)' +__fish_brew_complete_arg 'instal' -l as-dependency -d 'Install but mark as installed as a dependency and not installed on request' __fish_brew_complete_arg 'instal' -l ask -d 'Ask for confirmation before downloading and installing formulae. Print bottles and dependencies download size and install size' __fish_brew_complete_arg 'instal' -l audio-unit-plugindir -d 'Target location for Audio Unit Plugins (default: `~/Library/Audio/Plug-Ins/Components`)' __fish_brew_complete_arg 'instal' -l binaries -d 'Disable/enable linking of helper executables (default: enabled)' @@ -1000,6 +1001,7 @@ __fish_brew_complete_cmd 'install' 'Install a formula or cask' __fish_brew_complete_arg 'install' -l HEAD -d 'If formula defines it, install the HEAD version, aka. main, trunk, unstable, master' __fish_brew_complete_arg 'install' -l adopt -d 'Adopt existing artifacts in the destination that are identical to those being installed. Cannot be combined with `--force`' __fish_brew_complete_arg 'install' -l appdir -d 'Target location for Applications (default: `/Applications`)' +__fish_brew_complete_arg 'install' -l as-dependency -d 'Install but mark as installed as a dependency and not installed on request' __fish_brew_complete_arg 'install' -l ask -d 'Ask for confirmation before downloading and installing formulae. Print bottles and dependencies download size and install size' __fish_brew_complete_arg 'install' -l audio-unit-plugindir -d 'Target location for Audio Unit Plugins (default: `~/Library/Audio/Plug-Ins/Components`)' __fish_brew_complete_arg 'install' -l binaries -d 'Disable/enable linking of helper executables (default: enabled)' diff --git a/completions/zsh/_brew b/completions/zsh/_brew index 6e978ed4af..afca1826b9 100644 --- a/completions/zsh/_brew +++ b/completions/zsh/_brew @@ -1187,6 +1187,7 @@ _brew_instal() { '(--cask)--HEAD[If formula defines it, install the HEAD version, aka. main, trunk, unstable, master]' \ '(--formula --force)--adopt[Adopt existing artifacts in the destination that are identical to those being installed. Cannot be combined with `--force`]' \ '(--formula)--appdir[Target location for Applications (default: `/Applications`)]' \ + '(--cask)--as-dependency[Install but mark as installed as a dependency and not installed on request]' \ '(--cask)--ask[Ask for confirmation before downloading and installing formulae. Print bottles and dependencies download size and install size]' \ '(--formula)--audio-unit-plugindir[Target location for Audio Unit Plugins (default: `~/Library/Audio/Plug-Ins/Components`)]' \ '(--formula)--binaries[Disable/enable linking of helper executables (default: enabled)]' \ @@ -1237,7 +1238,7 @@ _brew_instal() { '(--casks --binaries --require-sha --quarantine --adopt --skip-cask-deps --zap --appdir --keyboard-layoutdir --colorpickerdir --prefpanedir --qlplugindir --mdimporterdir --dictionarydir --fontdir --servicedir --input-methoddir --internet-plugindir --audio-unit-plugindir --vst-plugindir --vst3-plugindir --screen-saverdir --language)--formula[Treat all named arguments as formulae]' \ '*::formula:__brew_formulae' \ - cask \ - '(--formulae --env --ignore-dependencies --only-dependencies --cc --build-from-source --force-bottle --include-test --HEAD --fetch-HEAD --keep-tmp --debug-symbols --build-bottle --skip-post-install --skip-link --bottle-arch --interactive --git --overwrite --ask)--cask[Treat all named arguments as casks]' \ + '(--formulae --env --ignore-dependencies --only-dependencies --cc --build-from-source --force-bottle --include-test --HEAD --fetch-HEAD --keep-tmp --debug-symbols --build-bottle --skip-post-install --skip-link --as-dependency --bottle-arch --interactive --git --overwrite --ask)--cask[Treat all named arguments as casks]' \ '*::cask:__brew_casks' } @@ -1247,6 +1248,7 @@ _brew_install() { '(--cask)--HEAD[If formula defines it, install the HEAD version, aka. main, trunk, unstable, master]' \ '(--formula --force)--adopt[Adopt existing artifacts in the destination that are identical to those being installed. Cannot be combined with `--force`]' \ '(--formula)--appdir[Target location for Applications (default: `/Applications`)]' \ + '(--cask)--as-dependency[Install but mark as installed as a dependency and not installed on request]' \ '(--cask)--ask[Ask for confirmation before downloading and installing formulae. Print bottles and dependencies download size and install size]' \ '(--formula)--audio-unit-plugindir[Target location for Audio Unit Plugins (default: `~/Library/Audio/Plug-Ins/Components`)]' \ '(--formula)--binaries[Disable/enable linking of helper executables (default: enabled)]' \ @@ -1297,7 +1299,7 @@ _brew_install() { '(--casks --binaries --require-sha --quarantine --adopt --skip-cask-deps --zap --appdir --keyboard-layoutdir --colorpickerdir --prefpanedir --qlplugindir --mdimporterdir --dictionarydir --fontdir --servicedir --input-methoddir --internet-plugindir --audio-unit-plugindir --vst-plugindir --vst3-plugindir --screen-saverdir --language)--formula[Treat all named arguments as formulae]' \ '*::formula:__brew_formulae' \ - cask \ - '(--formulae --env --ignore-dependencies --only-dependencies --cc --build-from-source --force-bottle --include-test --HEAD --fetch-HEAD --keep-tmp --debug-symbols --build-bottle --skip-post-install --skip-link --bottle-arch --interactive --git --overwrite --ask)--cask[Treat all named arguments as casks]' \ + '(--formulae --env --ignore-dependencies --only-dependencies --cc --build-from-source --force-bottle --include-test --HEAD --fetch-HEAD --keep-tmp --debug-symbols --build-bottle --skip-post-install --skip-link --as-dependency --bottle-arch --interactive --git --overwrite --ask)--cask[Treat all named arguments as casks]' \ '*::cask:__brew_casks' } diff --git a/docs/Manpage.md b/docs/Manpage.md index fe83f47dff..4c52da70ef 100644 --- a/docs/Manpage.md +++ b/docs/Manpage.md @@ -835,6 +835,10 @@ upgrade *`formula`* if it is already installed but outdated. : Install but skip linking the keg into the prefix. +`--as-dependency` + +: Install but mark as installed as a dependency and not installed on request. + `--bottle-arch` : Optimise bottles for the specified architecture rather than the oldest diff --git a/manpages/brew.1 b/manpages/brew.1 index 21ec4d3a20..58cc2e6324 100644 --- a/manpages/brew.1 +++ b/manpages/brew.1 @@ -520,6 +520,9 @@ Install but skip any post\-install steps\. \fB\-\-skip\-link\fP Install but skip linking the keg into the prefix\. .TP +\fB\-\-as\-dependency\fP +Install but mark as installed as a dependency and not installed on request\. +.TP \fB\-\-bottle\-arch\fP Optimise bottles for the specified architecture rather than the oldest architecture supported by the version of macOS the bottles are built on\. .TP