Add brew install --skip-link

We already have `--skip-post-install` and this adds similar behaviour
for e.g. `brew bundle` (and other users) to be able to install a
formula but skip the `brew link` stage afterwards.
This commit is contained in:
Mike McQuaid 2025-01-23 14:42:03 +00:00
parent e6b8ed8940
commit b49625a7dc
No known key found for this signature in database
9 changed files with 45 additions and 5 deletions

View File

@ -101,6 +101,9 @@ module Homebrew
[:switch, "--skip-post-install", { [:switch, "--skip-post-install", {
description: "Install but skip any post-install steps.", description: "Install but skip any post-install steps.",
}], }],
[:switch, "--skip-link", {
description: "Install but skip linking the keg into the prefix.",
}],
[:flag, "--bottle-arch=", { [:flag, "--bottle-arch=", {
depends_on: "--build-bottle", depends_on: "--build-bottle",
description: "Optimise bottles for the specified architecture rather than the oldest " \ description: "Optimise bottles for the specified architecture rather than the oldest " \
@ -289,6 +292,7 @@ module Homebrew
only_dependencies: args.only_dependencies?, only_dependencies: args.only_dependencies?,
force: args.force?, force: args.force?,
quiet: args.quiet?, quiet: args.quiet?,
skip_link: args.skip_link?,
overwrite: args.overwrite?, overwrite: args.overwrite?,
) )
end end
@ -319,6 +323,7 @@ module Homebrew
verbose: args.verbose?, verbose: args.verbose?,
dry_run: args.dry_run?, dry_run: args.dry_run?,
skip_post_install: args.skip_post_install?, skip_post_install: args.skip_post_install?,
skip_link: args.skip_link?,
) )
Upgrade.check_installed_dependents( Upgrade.check_installed_dependents(

View File

@ -60,6 +60,7 @@ class FormulaInstaller
show_header: T::Boolean, show_header: T::Boolean,
build_bottle: T::Boolean, build_bottle: T::Boolean,
skip_post_install: T::Boolean, skip_post_install: T::Boolean,
skip_link: T::Boolean,
force_bottle: T::Boolean, force_bottle: T::Boolean,
bottle_arch: T.nilable(String), bottle_arch: T.nilable(String),
ignore_deps: T::Boolean, ignore_deps: T::Boolean,
@ -88,6 +89,7 @@ class FormulaInstaller
show_header: false, show_header: false,
build_bottle: false, build_bottle: false,
skip_post_install: false, skip_post_install: false,
skip_link: false,
force_bottle: false, force_bottle: false,
bottle_arch: nil, bottle_arch: nil,
ignore_deps: false, ignore_deps: false,
@ -120,6 +122,7 @@ class FormulaInstaller
@build_from_source_formulae = build_from_source_formulae @build_from_source_formulae = build_from_source_formulae
@build_bottle = build_bottle @build_bottle = build_bottle
@skip_post_install = skip_post_install @skip_post_install = skip_post_install
@skip_link = skip_link
@bottle_arch = bottle_arch @bottle_arch = bottle_arch
@formula.force_bottle ||= force_bottle @formula.force_bottle ||= force_bottle
@force_bottle = T.let(@formula.force_bottle, T::Boolean) @force_bottle = T.let(@formula.force_bottle, T::Boolean)
@ -195,6 +198,11 @@ class FormulaInstaller
@skip_post_install.present? @skip_post_install.present?
end end
sig { returns(T::Boolean) }
def skip_link?
@skip_link.present?
end
sig { params(output_warning: T::Boolean).returns(T::Boolean) } sig { params(output_warning: T::Boolean).returns(T::Boolean) }
def pour_bottle?(output_warning: false) def pour_bottle?(output_warning: false)
return false if !formula.bottle_tag? && !formula.local_bottle_path return false if !formula.bottle_tag? && !formula.local_bottle_path
@ -866,7 +874,15 @@ on_request: installed_on_request?, options:)
ohai "Finishing up" if verbose? ohai "Finishing up" if verbose?
keg = Keg.new(formula.prefix) keg = Keg.new(formula.prefix)
link(keg) if skip_link?
unless quiet?
ohai "Skipping 'link' on request"
puts "You can run it manually using:"
puts " brew link #{formula.full_name}"
end
else
link(keg)
end
install_service install_service

View File

@ -70,6 +70,7 @@ module Homebrew
only_dependencies: false, only_dependencies: false,
force: false, force: false,
quiet: false, quiet: false,
skip_link: false,
overwrite: false overwrite: false
) )
# head-only without --HEAD is an error # head-only without --HEAD is an error
@ -201,7 +202,7 @@ module Homebrew
To upgrade to #{formula.pkg_version}, run: To upgrade to #{formula.pkg_version}, run:
#{unpin_cmd_if_needed}brew upgrade #{formula.full_name} #{unpin_cmd_if_needed}brew upgrade #{formula.full_name}
EOS EOS
elsif only_dependencies elsif only_dependencies || skip_link
return true return true
else else
onoe <<~EOS onoe <<~EOS
@ -250,7 +251,8 @@ module Homebrew
quiet: false, quiet: false,
verbose: false, verbose: false,
dry_run: false, dry_run: false,
skip_post_install: false skip_post_install: false,
skip_link: false
) )
formula_installers = formulae_to_install.filter_map do |formula| formula_installers = formulae_to_install.filter_map do |formula|
Migrator.migrate_if_needed(formula, force:, dry_run:) Migrator.migrate_if_needed(formula, force:, dry_run:)
@ -279,6 +281,7 @@ module Homebrew
quiet:, quiet:,
verbose:, verbose:,
skip_post_install:, skip_post_install:,
skip_link:,
) )
begin begin

View File

@ -152,6 +152,9 @@ class Homebrew::Cmd::InstallCmd::Args < Homebrew::CLI::Args
sig { returns(T::Boolean) } sig { returns(T::Boolean) }
def skip_cask_deps?; end def skip_cask_deps?; end
sig { returns(T::Boolean) }
def skip_link?; end
sig { returns(T::Boolean) } sig { returns(T::Boolean) }
def skip_post_install?; end def skip_post_install?; end

View File

@ -1342,6 +1342,7 @@ _brew_instal() {
--screen-saverdir --screen-saverdir
--servicedir --servicedir
--skip-cask-deps --skip-cask-deps
--skip-link
--skip-post-install --skip-post-install
--verbose --verbose
--vst-plugindir --vst-plugindir
@ -1405,6 +1406,7 @@ _brew_install() {
--screen-saverdir --screen-saverdir
--servicedir --servicedir
--skip-cask-deps --skip-cask-deps
--skip-link
--skip-post-install --skip-post-install
--verbose --verbose
--vst-plugindir --vst-plugindir

View File

@ -912,6 +912,7 @@ __fish_brew_complete_arg 'instal' -l require-sha -d 'Require all casks to have a
__fish_brew_complete_arg 'instal' -l screen-saverdir -d 'Target location for Screen Savers (default: `~/Library/Screen Savers`)' __fish_brew_complete_arg 'instal' -l screen-saverdir -d 'Target location for Screen Savers (default: `~/Library/Screen Savers`)'
__fish_brew_complete_arg 'instal' -l servicedir -d 'Target location for Services (default: `~/Library/Services`)' __fish_brew_complete_arg 'instal' -l servicedir -d 'Target location for Services (default: `~/Library/Services`)'
__fish_brew_complete_arg 'instal' -l skip-cask-deps -d 'Skip installing cask dependencies' __fish_brew_complete_arg 'instal' -l skip-cask-deps -d 'Skip installing cask dependencies'
__fish_brew_complete_arg 'instal' -l skip-link -d 'Install but skip linking the keg into the prefix'
__fish_brew_complete_arg 'instal' -l skip-post-install -d 'Install but skip any post-install steps' __fish_brew_complete_arg 'instal' -l skip-post-install -d 'Install but skip any post-install steps'
__fish_brew_complete_arg 'instal' -l verbose -d 'Print the verification and post-install steps' __fish_brew_complete_arg 'instal' -l verbose -d 'Print the verification and post-install steps'
__fish_brew_complete_arg 'instal' -l vst-plugindir -d 'Target location for VST Plugins (default: `~/Library/Audio/Plug-Ins/VST`)' __fish_brew_complete_arg 'instal' -l vst-plugindir -d 'Target location for VST Plugins (default: `~/Library/Audio/Plug-Ins/VST`)'
@ -966,6 +967,7 @@ __fish_brew_complete_arg 'install' -l require-sha -d 'Require all casks to have
__fish_brew_complete_arg 'install' -l screen-saverdir -d 'Target location for Screen Savers (default: `~/Library/Screen Savers`)' __fish_brew_complete_arg 'install' -l screen-saverdir -d 'Target location for Screen Savers (default: `~/Library/Screen Savers`)'
__fish_brew_complete_arg 'install' -l servicedir -d 'Target location for Services (default: `~/Library/Services`)' __fish_brew_complete_arg 'install' -l servicedir -d 'Target location for Services (default: `~/Library/Services`)'
__fish_brew_complete_arg 'install' -l skip-cask-deps -d 'Skip installing cask dependencies' __fish_brew_complete_arg 'install' -l skip-cask-deps -d 'Skip installing cask dependencies'
__fish_brew_complete_arg 'install' -l skip-link -d 'Install but skip linking the keg into the prefix'
__fish_brew_complete_arg 'install' -l skip-post-install -d 'Install but skip any post-install steps' __fish_brew_complete_arg 'install' -l skip-post-install -d 'Install but skip any post-install steps'
__fish_brew_complete_arg 'install' -l verbose -d 'Print the verification and post-install steps' __fish_brew_complete_arg 'install' -l verbose -d 'Print the verification and post-install steps'
__fish_brew_complete_arg 'install' -l vst-plugindir -d 'Target location for VST Plugins (default: `~/Library/Audio/Plug-Ins/VST`)' __fish_brew_complete_arg 'install' -l vst-plugindir -d 'Target location for VST Plugins (default: `~/Library/Audio/Plug-Ins/VST`)'

View File

@ -1145,6 +1145,7 @@ _brew_instal() {
'(--formula)--screen-saverdir[Target location for Screen Savers (default: `~/Library/Screen Savers`)]' \ '(--formula)--screen-saverdir[Target location for Screen Savers (default: `~/Library/Screen Savers`)]' \
'(--formula)--servicedir[Target location for Services (default: `~/Library/Services`)]' \ '(--formula)--servicedir[Target location for Services (default: `~/Library/Services`)]' \
'(--formula)--skip-cask-deps[Skip installing cask dependencies]' \ '(--formula)--skip-cask-deps[Skip installing cask dependencies]' \
'(--cask)--skip-link[Install but skip linking the keg into the prefix]' \
'(--cask)--skip-post-install[Install but skip any post-install steps]' \ '(--cask)--skip-post-install[Install but skip any post-install steps]' \
'--verbose[Print the verification and post-install steps]' \ '--verbose[Print the verification and post-install steps]' \
'(--formula)--vst-plugindir[Target location for VST Plugins (default: `~/Library/Audio/Plug-Ins/VST`)]' \ '(--formula)--vst-plugindir[Target location for VST Plugins (default: `~/Library/Audio/Plug-Ins/VST`)]' \
@ -1154,7 +1155,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]' \ '(--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' \ '*::formula:__brew_formulae' \
- cask \ - 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 --bottle-arch --interactive --git --overwrite)--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 --bottle-arch --interactive --git --overwrite)--cask[Treat all named arguments as casks]' \
'*::cask:__brew_casks' '*::cask:__brew_casks'
} }
@ -1203,6 +1204,7 @@ _brew_install() {
'(--formula)--screen-saverdir[Target location for Screen Savers (default: `~/Library/Screen Savers`)]' \ '(--formula)--screen-saverdir[Target location for Screen Savers (default: `~/Library/Screen Savers`)]' \
'(--formula)--servicedir[Target location for Services (default: `~/Library/Services`)]' \ '(--formula)--servicedir[Target location for Services (default: `~/Library/Services`)]' \
'(--formula)--skip-cask-deps[Skip installing cask dependencies]' \ '(--formula)--skip-cask-deps[Skip installing cask dependencies]' \
'(--cask)--skip-link[Install but skip linking the keg into the prefix]' \
'(--cask)--skip-post-install[Install but skip any post-install steps]' \ '(--cask)--skip-post-install[Install but skip any post-install steps]' \
'--verbose[Print the verification and post-install steps]' \ '--verbose[Print the verification and post-install steps]' \
'(--formula)--vst-plugindir[Target location for VST Plugins (default: `~/Library/Audio/Plug-Ins/VST`)]' \ '(--formula)--vst-plugindir[Target location for VST Plugins (default: `~/Library/Audio/Plug-Ins/VST`)]' \
@ -1212,7 +1214,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]' \ '(--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' \ '*::formula:__brew_formulae' \
- cask \ - 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 --bottle-arch --interactive --git --overwrite)--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 --bottle-arch --interactive --git --overwrite)--cask[Treat all named arguments as casks]' \
'*::cask:__brew_casks' '*::cask:__brew_casks'
} }

View File

@ -644,6 +644,10 @@ upgrade *`formula`* if it is already installed but outdated.
: Install but skip any post-install steps. : Install but skip any post-install steps.
`--skip-link`
: Install but skip linking the keg into the prefix.
`--bottle-arch` `--bottle-arch`
: Optimise bottles for the specified architecture rather than the oldest : Optimise bottles for the specified architecture rather than the oldest

View File

@ -403,6 +403,9 @@ Prepare the formula for eventual bottling during installation, skipping any post
\fB\-\-skip\-post\-install\fP \fB\-\-skip\-post\-install\fP
Install but skip any post\-install steps\. Install but skip any post\-install steps\.
.TP .TP
\fB\-\-skip\-link\fP
Install but skip linking the keg into the prefix\.
.TP
\fB\-\-bottle\-arch\fP \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\. Optimise bottles for the specified architecture rather than the oldest architecture supported by the version of macOS the bottles are built on\.
.TP .TP