From c7030eaba086bd104b4620540647acb99df2fc41 Mon Sep 17 00:00:00 2001 From: Carlo Cabrera <30379873+carlocab@users.noreply.github.com> Date: Fri, 19 Aug 2022 17:32:43 +0800 Subject: [PATCH] formula: add optional `source` and `target` args to `#rpath` There are about 10 formulae which need a bit more flexibility from `#rpath`. Most of them use `Pathname#relative_path_from`, so we can replace those instances with a call to `#rpath` instead once `#rpath` knows how to handle this. --- Library/Homebrew/extend/os/linux/formula.rb | 6 +++--- Library/Homebrew/formula.rb | 18 ++++++++++++++++-- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/Library/Homebrew/extend/os/linux/formula.rb b/Library/Homebrew/extend/os/linux/formula.rb index f3586103bc..5f46e710d0 100644 --- a/Library/Homebrew/extend/os/linux/formula.rb +++ b/Library/Homebrew/extend/os/linux/formula.rb @@ -3,7 +3,7 @@ class Formula undef shared_library - undef rpath + undef loader_path undef deuniversalize_machos sig { params(name: String, version: T.nilable(T.any(String, Integer))).returns(String) } @@ -17,8 +17,8 @@ class Formula end sig { returns(String) } - def rpath - "'$ORIGIN/../lib'" + def loader_path + "$ORIGIN" end sig { params(targets: T.nilable(T.any(Pathname, String))).void } diff --git a/Library/Homebrew/formula.rb b/Library/Homebrew/formula.rb index d6efeff0ef..0e4c7c079d 100644 --- a/Library/Homebrew/formula.rb +++ b/Library/Homebrew/formula.rb @@ -1572,9 +1572,23 @@ class Formula end # Executable/Library RPATH according to platform conventions. + # + # Optionally specify a `source` or `target` depending on the location + # of the file containing the RPATH command and where its target is located. + # + #
+ # rpath #=> "@loader_path/../lib" + # rpath(target: frameworks) #=> "@loader_path/../Frameworks" + # rpath(source: libexec/"bin") #=> "@loader_path/../../lib" + #+ sig { params(source: Pathname, target: Pathname).returns(String) } + def rpath(source: bin, target: lib) + "#{loader_path}/#{target.relative_path_from(source)}" + end + sig { returns(String) } - def rpath - "@loader_path/../lib" + def loader_path + "@loader_path" end # Creates a new `Time` object for use in the formula as the build time.