Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use HOMEBREW_CELLAR_PLACEHOLDER #15699

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions Library/Homebrew/cask/cask_loader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,7 @@ def from_h_string_gsubs(string, appdir)
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

Expand Down
4 changes: 4 additions & 0 deletions Library/Homebrew/extend/api_hashable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ def generating_hash!

# 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
Expand All @@ -22,6 +24,8 @@ def generated_hash!
# 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
Expand Down
3 changes: 2 additions & 1 deletion Library/Homebrew/formula.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2173,7 +2173,8 @@ def to_hash
"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?,
Expand Down
1 change: 1 addition & 0 deletions Library/Homebrew/formulary.rb
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,7 @@ def post_install_defined?
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

Expand Down
1 change: 1 addition & 0 deletions Library/Homebrew/global.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
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"
Expand Down
1 change: 1 addition & 0 deletions Library/Homebrew/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -633,6 +633,7 @@ def self.deserialize(api_hash)
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
Expand Down
1 change: 1 addition & 0 deletions Library/Homebrew/sorbet/rbi/hidden-definitions/hidden.rbi
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down