From 252e398b78448b4fb97649d7127388078235db9e Mon Sep 17 00:00:00 2001 From: Carlo Cabrera <30379873+carlocab@users.noreply.github.com> Date: Sat, 8 Oct 2022 00:15:37 +0800 Subject: [PATCH] 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. --- Library/Homebrew/formula.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Library/Homebrew/formula.rb b/Library/Homebrew/formula.rb index de6596ff15..24e4a1da11 100644 --- a/Library/Homebrew/formula.rb +++ b/Library/Homebrew/formula.rb @@ -1615,6 +1615,10 @@ class Formula # 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