Re: [pacman-dev] makepkg: package_...() can export variables to each other

2020-06-05 Thread Eli Schwartz
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



signature.asc
Description: OpenPGP digital signature


Re: [pacman-dev] makepkg: package_...() can export variables to each other

2020-06-05 Thread Allan McRae
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.

Allan