Revert "Improve @-versioned formulae linking."

This commit is contained in:
Shaun Jackman 2020-10-30 10:40:10 -07:00 committed by GitHub
parent 5c2714f068
commit 099af8cf9c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 27 additions and 57 deletions

View File

@ -4,7 +4,6 @@
require "ostruct"
require "caveats"
require "cli/parser"
require "unlink"
module Homebrew
module_function
@ -67,27 +66,26 @@ module Homebrew
next
end
formula = keg.to_formula
if keg_only
if Homebrew.default_prefix? && formula.keg_only_reason.by_macos?
caveats = Caveats.new(formula)
opoo <<~EOS
Refusing to link macOS provided/shadowed software: #{keg.name}
#{caveats.keg_only_text(skip_reason: true).strip}
EOS
next
if Homebrew.default_prefix?
f = keg.to_formula
if f.keg_only_reason.by_macos?
caveats = Caveats.new(f)
opoo <<~EOS
Refusing to link macOS provided/shadowed software: #{keg.name}
#{caveats.keg_only_text(skip_reason: true).strip}
EOS
next
end
end
if !formula.keg_only_reason.versioned_formula? && !args.force?
unless args.force?
opoo "#{keg.name} is keg-only and must be linked with --force"
puts_keg_only_path_message(keg)
next
end
end
Unlink.unlink_versioned_formulae(formula, verbose: args.verbose?)
keg.lock do
print "Linking #{keg}... "
puts if args.verbose?

View File

@ -17,7 +17,6 @@ module Homebrew
EOS
named 2
hide_from_man_page!
end
end
@ -29,8 +28,6 @@ module Homebrew
odie "#{name} not found in the Cellar." unless rack.directory?
# odeprecated "`brew switch`", "`brew link` @-versioned formulae"
versions = rack.subdirs
.map { |d| Keg.new(d).version }
.sort

View File

@ -3,7 +3,6 @@
require "ostruct"
require "cli/parser"
require "unlink"
module Homebrew
module_function
@ -37,7 +36,11 @@ module Homebrew
next
end
Unlink.unlink(keg, dry_run: args.dry_run?, verbose: args.verbose?)
keg.lock do
print "Unlinking #{keg}... "
puts if args.verbose?
puts "#{keg.unlink(**options)} symlinks removed"
end
end
end
end

View File

@ -414,12 +414,12 @@ class Formula
name.include?("@")
end
# Returns any `@`-versioned formulae for any formula (including versioned formulae).
# Returns any `@`-versioned formulae for an non-`@`-versioned formula.
def versioned_formulae
Pathname.glob(path.to_s.gsub(/(@[\d.]+)?\.rb$/, "@*.rb")).map do |versioned_path|
next if versioned_path == path
return [] if versioned_formula?
Formula[versioned_path.basename(".rb").to_s]
Pathname.glob(path.to_s.gsub(/\.rb$/, "@*.rb")).map do |path|
Formula[path.basename(".rb").to_s]
rescue FormulaUnavailableError
nil
end.compact.sort_by(&:version).reverse

View File

@ -22,7 +22,6 @@ require "cmd/install"
require "find"
require "utils/spdx"
require "deprecate_disable"
require "unlink"
# Installer for a formula.
#
@ -885,8 +884,6 @@ class FormulaInstaller
keg.remove_linked_keg_record
end
Homebrew::Unlink.unlink_versioned_formulae(formula, verbose: verbose?)
link_overwrite_backup = {} # Hash: conflict file -> backup file
backup_dir = HOMEBREW_CACHE/"Backup"

View File

@ -335,7 +335,6 @@ class Keg
EOS
end
# TODO: refactor to use keyword arguments.
def unlink(**options)
ObserverPathnameExtension.reset_counts!
@ -449,7 +448,6 @@ class Keg
end
end
# TODO: refactor to use keyword arguments.
def link(**options)
raise AlreadyLinkedError, self if linked_keg_record.directory?

View File

@ -1,30 +0,0 @@
# typed: false
# frozen_string_literal: true
module Homebrew
# Provides helper methods for unlinking formulae and kegs with consistent output.
module Unlink
module_function
def unlink_versioned_formulae(formula, verbose: false)
formula.versioned_formulae
.select(&:linked?)
.map(&:any_installed_keg)
.compact
.select(&:directory?)
.each do |keg|
unlink(keg, verbose: verbose)
end
end
def unlink(keg, dry_run: false, verbose: false)
options = { dry_run: dry_run, verbose: verbose }
keg.lock do
print "Unlinking #{keg}... "
puts if verbose
puts "#{keg.unlink(**options)} symlinks removed"
end
end
end
end

View File

@ -537,6 +537,10 @@ Print export statements. When run in a shell, this installation of Homebrew will
The variables `HOMEBREW_PREFIX`, `HOMEBREW_CELLAR` and `HOMEBREW_REPOSITORY` are also exported to avoid querying them multiple times.
Consider adding evaluation of this command's output to your dotfiles (e.g. `~/.profile`, `~/.bash_profile`, or `~/.zprofile`) with: `eval $(brew shellenv)`
### `switch` *`formula`* *`version`*
Symlink all of the specified *`version`* of *`formula`*'s installation into Homebrew's prefix.
### `tap` [*`options`*] [*`user`*`/`*`repo`*] [*`URL`*]
Tap a formula repository.

View File

@ -773,6 +773,9 @@ Print export statements\. When run in a shell, this installation of Homebrew wil
.P
The variables \fBHOMEBREW_PREFIX\fR, \fBHOMEBREW_CELLAR\fR and \fBHOMEBREW_REPOSITORY\fR are also exported to avoid querying them multiple times\. Consider adding evaluation of this command\'s output to your dotfiles (e\.g\. \fB~/\.profile\fR, \fB~/\.bash_profile\fR, or \fB~/\.zprofile\fR) with: \fBeval $(brew shellenv)\fR
.
.SS "\fBswitch\fR \fIformula\fR \fIversion\fR"
Symlink all of the specified \fIversion\fR of \fIformula\fR\'s installation into Homebrew\'s prefix\.
.
.SS "\fBtap\fR [\fIoptions\fR] [\fIuser\fR\fB/\fR\fIrepo\fR] [\fIURL\fR]"
Tap a formula repository\.
.