Skip to content

Commit

Permalink
Add brew install --skip-link
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
MikeMcQuaid committed Jan 23, 2025
1 parent e6b8ed8 commit 5517871
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 6 deletions.
4 changes: 4 additions & 0 deletions Library/Homebrew/cmd/install.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ class InstallCmd < AbstractCommand
[:switch, "--skip-post-install", {
description: "Install but skip any post-install steps.",
}],
[:switch, "--skip-link", {
description: "Install but skip linking the keg into the prefix.",
}],
[:flag, "--bottle-arch=", {
depends_on: "--build-bottle",
description: "Optimise bottles for the specified architecture rather than the oldest " \
Expand Down Expand Up @@ -319,6 +322,7 @@ def run
verbose: args.verbose?,
dry_run: args.dry_run?,
skip_post_install: args.skip_post_install?,
skip_link: args.skip_link?,
)

Upgrade.check_installed_dependents(
Expand Down
18 changes: 17 additions & 1 deletion Library/Homebrew/formula_installer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class FormulaInstaller
show_header: T::Boolean,
build_bottle: T::Boolean,
skip_post_install: T::Boolean,
skip_link: T::Boolean,
force_bottle: T::Boolean,
bottle_arch: T.nilable(String),
ignore_deps: T::Boolean,
Expand Down Expand Up @@ -88,6 +89,7 @@ def initialize(
show_header: false,
build_bottle: false,
skip_post_install: false,
skip_link: false,
force_bottle: false,
bottle_arch: nil,
ignore_deps: false,
Expand Down Expand Up @@ -120,6 +122,7 @@ def initialize(
@build_from_source_formulae = build_from_source_formulae
@build_bottle = build_bottle
@skip_post_install = skip_post_install
@skip_link = skip_link
@bottle_arch = bottle_arch
@formula.force_bottle ||= force_bottle
@force_bottle = T.let(@formula.force_bottle, T::Boolean)
Expand Down Expand Up @@ -195,6 +198,11 @@ def skip_post_install?
@skip_post_install.present?
end

sig { returns(T::Boolean) }
def skip_link?
@skip_link.present?
end

sig { params(output_warning: T::Boolean).returns(T::Boolean) }
def pour_bottle?(output_warning: false)
return false if !formula.bottle_tag? && !formula.local_bottle_path
Expand Down Expand Up @@ -866,7 +874,15 @@ def finish
ohai "Finishing up" if verbose?

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

Expand Down
6 changes: 5 additions & 1 deletion Library/Homebrew/install.rb
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,8 @@ def install_formula?(
EOS
elsif only_dependencies
return true
elsif skip_link
return true
else
onoe <<~EOS
#{message}
Expand Down Expand Up @@ -250,7 +252,8 @@ def install_formulae(
quiet: false,
verbose: false,
dry_run: false,
skip_post_install: false
skip_post_install: false,
skip_link: false
)
formula_installers = formulae_to_install.filter_map do |formula|
Migrator.migrate_if_needed(formula, force:, dry_run:)
Expand Down Expand Up @@ -279,6 +282,7 @@ def install_formulae(
quiet:,
verbose:,
skip_post_install:,
skip_link:
)

begin
Expand Down
2 changes: 2 additions & 0 deletions completions/bash/brew
Original file line number Diff line number Diff line change
Expand Up @@ -1342,6 +1342,7 @@ _brew_instal() {
--screen-saverdir
--servicedir
--skip-cask-deps
--skip-link
--skip-post-install
--verbose
--vst-plugindir
Expand Down Expand Up @@ -1405,6 +1406,7 @@ _brew_install() {
--screen-saverdir
--servicedir
--skip-cask-deps
--skip-link
--skip-post-install
--verbose
--vst-plugindir
Expand Down
2 changes: 2 additions & 0 deletions completions/fish/brew.fish
Original file line number Diff line number Diff line change
Expand Up @@ -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 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-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 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`)'
Expand Down Expand Up @@ -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 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-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 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`)'
Expand Down
6 changes: 4 additions & 2 deletions completions/zsh/_brew
Original file line number Diff line number Diff line change
Expand Up @@ -1145,6 +1145,7 @@ _brew_instal() {
'(--formula)--screen-saverdir[Target location for Screen Savers (default: `~/Library/Screen Savers`)]' \
'(--formula)--servicedir[Target location for Services (default: `~/Library/Services`)]' \
'(--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]' \
'--verbose[Print the verification and post-install steps]' \
'(--formula)--vst-plugindir[Target location for VST Plugins (default: `~/Library/Audio/Plug-Ins/VST`)]' \
Expand All @@ -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]' \
'*::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 --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'
}

Expand Down Expand Up @@ -1203,6 +1204,7 @@ _brew_install() {
'(--formula)--screen-saverdir[Target location for Screen Savers (default: `~/Library/Screen Savers`)]' \
'(--formula)--servicedir[Target location for Services (default: `~/Library/Services`)]' \
'(--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]' \
'--verbose[Print the verification and post-install steps]' \
'(--formula)--vst-plugindir[Target location for VST Plugins (default: `~/Library/Audio/Plug-Ins/VST`)]' \
Expand All @@ -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]' \
'*::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 --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'
}

Expand Down
12 changes: 11 additions & 1 deletion docs/Manpage.md
Original file line number Diff line number Diff line change
Expand Up @@ -644,6 +644,10 @@ upgrade *`formula`* if it is already installed but outdated.

: Install but skip any post-install steps.

`--skip-link`

: Install but skip linking the keg into the prefix.

`--bottle-arch`

: Optimise bottles for the specified architecture rather than the oldest
Expand Down Expand Up @@ -3140,7 +3144,13 @@ flags which will help with finding keg-only dependencies like `openssl`,

: `install` does not run `brew upgrade` on outdated dependencies. `check` does
not check for outdated dependencies. Note they may still be upgraded by `brew
install` if needed.
install` if needed.This is enabled by default if `HOMEBREW_BUNDLE_NO_UPGRADE`
is set.

`--upgrade`

: `install` runs `brew upgrade` on outdated dependencies, even if
`HOMEBREW_BUNDLE_NO_UPGRADE` is set.

`-f`, `--force`

Expand Down
8 changes: 7 additions & 1 deletion manpages/brew.1
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,9 @@ Prepare the formula for eventual bottling during installation, skipping any post
\fB\-\-skip\-post\-install\fP
Install but skip any post\-install steps\.
.TP
\fB\-\-skip\-link\fP
Install but skip linking the keg into the prefix\.
.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
Expand Down Expand Up @@ -2011,7 +2014,10 @@ Read the \fBBrewfile\fP from \fB~/\.Brewfile\fP or the \fBHOMEBREW_BUNDLE_FILE_G
\fBinstall\fP prints output from commands as they are run\. \fBcheck\fP lists all missing dependencies\.
.TP
\fB\-\-no\-upgrade\fP
\fBinstall\fP does not run \fBbrew upgrade\fP on outdated dependencies\. \fBcheck\fP does not check for outdated dependencies\. Note they may still be upgraded by \fBbrew install\fP if needed\.
\fBinstall\fP does not run \fBbrew upgrade\fP on outdated dependencies\. \fBcheck\fP does not check for outdated dependencies\. Note they may still be upgraded by \fBbrew install\fP if needed\.This is enabled by default if \fBHOMEBREW_BUNDLE_NO_UPGRADE\fP is set\.
.TP
\fB\-\-upgrade\fP
\fBinstall\fP runs \fBbrew upgrade\fP on outdated dependencies, even if \fBHOMEBREW_BUNDLE_NO_UPGRADE\fP is set\.
.TP
\fB\-f\fP, \fB\-\-force\fP
\fBinstall\fP runs with \fB\-\-force\fP/\fB\-\-overwrite\fP\&\. \fBdump\fP overwrites an existing \fBBrewfile\fP\&\. \fBcleanup\fP actually performs its cleanup operations\.
Expand Down

0 comments on commit 5517871

Please sign in to comment.