Use HOMEBREW_CELLAR_PLACEHOLDER

Similarly to HOMEBREW_PREFIX_PLACEHOLDER, this allows the substitution
of HOMEBREW_CELLAR in JSON output when using the API.

Fixes #15668.
This commit is contained in:
Mike McQuaid 2023-07-18 10:59:27 +01:00
parent 1ec7f0acaa
commit c940e15a5c
No known key found for this signature in database
GPG Key ID: 3338A31AFDB1D829
7 changed files with 11 additions and 1 deletions

View File

@ -349,6 +349,7 @@ module Cask
string.to_s
.gsub(HOMEBREW_HOME_PLACEHOLDER, Dir.home)
.gsub(HOMEBREW_PREFIX_PLACEHOLDER, HOMEBREW_PREFIX)
.gsub(HOMEBREW_CELLAR_PLACEHOLDER, HOMEBREW_CELLAR)
.gsub(HOMEBREW_CASK_APPDIR_PLACEHOLDER, appdir)
end

View File

@ -8,9 +8,11 @@ module APIHashable
# Apply monkeypatches for API generation
@old_homebrew_prefix = HOMEBREW_PREFIX
@old_homebrew_cellar = HOMEBREW_CELLAR
@old_home = Dir.home
Object.send(:remove_const, :HOMEBREW_PREFIX)
Object.const_set(:HOMEBREW_PREFIX, Pathname.new(HOMEBREW_PREFIX_PLACEHOLDER))
Object.const_set(:HOMEBREW_CELLAR, Pathname.new(HOMEBREW_CELLAR_PLACEHOLDER))
ENV["HOME"] = HOMEBREW_HOME_PLACEHOLDER
@generating_hash = true
@ -22,6 +24,8 @@ module APIHashable
# Revert monkeypatches for API generation
Object.send(:remove_const, :HOMEBREW_PREFIX)
Object.const_set(:HOMEBREW_PREFIX, @old_homebrew_prefix)
Object.send(:remove_const, :HOMEBREW_CELLAR)
Object.const_set(:HOMEBREW_CELLAR, @old_homebrew_cellar)
ENV["HOME"] = @old_home
@generating_hash = false

View File

@ -2173,7 +2173,8 @@ class Formula
"conflicts_with" => conflicts.map(&:name),
"conflicts_with_reasons" => conflicts.map(&:reason),
"link_overwrite" => self.class.link_overwrite_paths.to_a,
"caveats" => caveats&.gsub(HOMEBREW_PREFIX, HOMEBREW_PREFIX_PLACEHOLDER),
"caveats" => caveats&.gsub(HOMEBREW_PREFIX, HOMEBREW_PREFIX_PLACEHOLDER)
&.gsub(HOMEBREW_CELLAR, HOMEBREW_CELLAR_PLACEHOLDER),
"installed" => [],
"linked_keg" => linked_version&.to_s,
"pinned" => pinned?,

View File

@ -342,6 +342,7 @@ module Formulary
def caveats
self.class.instance_variable_get(:@caveats_string)
&.gsub(HOMEBREW_PREFIX_PLACEHOLDER, HOMEBREW_PREFIX)
&.gsub(HOMEBREW_CELLAR_PLACEHOLDER, HOMEBREW_CELLAR)
&.gsub(HOMEBREW_HOME_PLACEHOLDER, Dir.home)
end

View File

@ -57,6 +57,7 @@ HOMEBREW_MACOS_ARM_DEFAULT_REPOSITORY = ENV.fetch("HOMEBREW_MACOS_ARM_DEFAULT_RE
HOMEBREW_LINUX_DEFAULT_PREFIX = ENV.fetch("HOMEBREW_LINUX_DEFAULT_PREFIX").freeze
HOMEBREW_LINUX_DEFAULT_REPOSITORY = ENV.fetch("HOMEBREW_LINUX_DEFAULT_REPOSITORY").freeze
HOMEBREW_PREFIX_PLACEHOLDER = "$HOMEBREW_PREFIX"
HOMEBREW_CELLAR_PLACEHOLDER = "$HOMEBREW_CELLAR"
# Needs a leading slash to avoid `File.expand.path` complaining about non-absolute home.
HOMEBREW_HOME_PLACEHOLDER = "/$HOME"
HOMEBREW_CASK_APPDIR_PLACEHOLDER = "$APPDIR"

View File

@ -633,6 +633,7 @@ module Homebrew
sig { params(string: String).returns(String) }
def self.replace_placeholders(string)
string.gsub(HOMEBREW_PREFIX_PLACEHOLDER, HOMEBREW_PREFIX)
.gsub(HOMEBREW_CELLAR_PLACEHOLDER, HOMEBREW_CELLAR)
.gsub(HOMEBREW_HOME_PLACEHOLDER, Dir.home)
end
end

View File

@ -5174,6 +5174,7 @@ class Object
HOMEBREW_CASK_APPDIR_PLACEHOLDER = ::T.let(nil, ::T.untyped)
HOMEBREW_CASK_TAP_CASK_REGEX = ::T.let(nil, ::T.untyped)
HOMEBREW_CELLAR = ::T.let(nil, ::T.untyped)
HOMEBREW_CELLAR_PLACEHOLDER = ::T.let(nil, ::T.untyped)
HOMEBREW_CORE_DEFAULT_GIT_REMOTE = ::T.let(nil, ::T.untyped)
HOMEBREW_DATA_PATH = ::T.let(nil, ::T.untyped)
HOMEBREW_DEFAULT_CACHE = ::T.let(nil, ::T.untyped)