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.
This commit is contained in:
Carlo Cabrera 2022-08-19 17:32:43 +08:00
parent 6eca55a60d
commit c7030eaba0
No known key found for this signature in database
GPG Key ID: C74D447FC549A1D0
2 changed files with 19 additions and 5 deletions

View File

@ -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 }

View File

@ -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.
#
# <pre>
# rpath #=> "@loader_path/../lib"
# rpath(target: frameworks) #=> "@loader_path/../Frameworks"
# rpath(source: libexec/"bin") #=> "@loader_path/../../lib"
# </pre>
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.