[pacman-dev] makepkg: package_...() can export variables to each other
Eli Schwartz
eschwartz at archlinux.org
Fri Jun 5 14:30:17 UTC 2020
On 6/5/20 3:59 AM, Allan McRae wrote:
> On 5/6/20 5:39 pm, Erich Eckner wrote:
>> Hi,
>>
>> I stumbled upon the fact, that variables set in one package_...()
>> function of a split package are accessible by following package_...()
>> functions. Is this by design or may I try to provide a patch to restore
>> env after the call to package_...()?
>> Note: packaging-relevant variables (e.g. depends_x86_64) are cleaned
>> across function calls.
>>
>> Simple example:
>>
>> ------8<------8<------8<------
>> arch=(any)
>> pkgbase=test
>> pkgname=(ta tb)
>> pkgver=0
>> pkgrel=1
>>
>> package_ta() {
>> _test='hi, there!'
>> }
>>
>> package_tb() {
>> echo "$_test"
>> }
>> ------>8------>8------>8------
>>
>
> PKGBUILDs are bash. Bash scope rules apply.
... with the caveat that makepkg --nobuild && makepkg --noextract will
run prepare() and build() in separate program invocations, so you cannot
*depend* on variables being persisted. And all package_*() functions are
run -- together -- under fakeroot in a separate bash process, so they
are separated in scope from non-package_*() functions.
The packaging-relevant variables are special, we reset them precisely
because they're documented to only be local to the package that defines
them.
For all other variables, as Allan said it's your job to scope them as
you wish. People usually declare them with the "local" builtin.
--
Eli Schwartz
Bug Wrangler and Trusted User
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 1601 bytes
Desc: OpenPGP digital signature
URL: <https://lists.archlinux.org/pipermail/pacman-dev/attachments/20200605/d35f0fd3/attachment.sig>
More information about the pacman-dev
mailing list