formula: ensure rpath is passed a valid target

Setting `target` to a path outside `HOMEBREW_PREFIX` is not portable,
and will be invalid for some Homebrew installations.

If we want to add an `rpath` outside of `HOMEBREW_PREFIX`, we should
just use the absolute path instead.

See discussion at Homebrew/homebrew-core#110520.
This commit is contained in:
Carlo Cabrera 2022-10-08 00:15:37 +08:00
parent e23d7b6360
commit 252e398b78
No known key found for this signature in database
GPG Key ID: C74D447FC549A1D0

View File

@ -1615,6 +1615,10 @@ class Formula
# </pre>
sig { params(source: Pathname, target: Pathname).returns(String) }
def rpath(source: bin, target: lib)
unless target.to_s.start_with?(HOMEBREW_PREFIX)
odie "`target` should only be used for paths inside HOMEBREW_PREFIX!"
end
"#{loader_path}/#{target.relative_path_from(source)}"
end