[pacman-dev] [PATCH] makepkg: allow the use of only a package() function
Cedric Staniewski
cedric at gmx.ca
Sun Nov 1 12:45:27 EST 2009
Allan McRae wrote:
> Cedric Staniewski wrote:
>> For some packages, generally the 'any' arch ones, a build step is not
>> required and therefore can be skipped. In these cases, a package()
>> function without a build() one is sufficient.
>>
>> As a side effect, this commit makes meta packages without any function
>> at all in the PKGBUILD possible.
>>
>> Fixes FS#15147.
>>
>> Signed-off-by: Cedric Staniewski <cedric at gmx.ca>
>> ---
>> <snip>
>>
>> +# test for available PKGBUILD functions
>> +# The exclamation mark is required here to avoid triggering the ERR
>> trap when
>> +# a tested function does not exist.
>> +if [[ $(! type -t build) = "function" ]]; then
>> + BUILDFUNC=1
>> +fi
>>
>
> This certainly appears to work, but can you explain how? Here is my
> understanding. The "!" means that when build() is not present, the
> function will still return 0 (not triggering the err trap) and the
> comparison then fails. When build() function is present, the type
> -t... outputs "function" but returns 1. How is the err trap not set of
> then? Is it because there is a value output?
There is no real explanation, only "that's how it works in bash". ;)
>From bash's manpage:
> trap [-lp] [[arg] sigspec ...]
> [...]
> The ERR trap is not executed if the failed command is part of the command
> list immediately following a while or until keyword, part of the test in
> an if statement, part of a command executed in a && or || list, or if
> the command's return value is being inverted via !.
Note that apparently only the test/[ builtin is meant here.
Your explanation is correct for return codes, but it is not applicable here, because the ERR signal is not the same as a return code greater than zero.
Given this script:
-----------------
#!/bin/bash
set -E
trap 'echo >&2 "error"' ERR
echo test1
type -t package
echo ret: $?
echo
echo test2
! type -t package
echo ret: $?
echo
echo test3
type -t package || echo 1
echo ret: $?
echo
echo test4
type -t package && echo 1
echo ret: $?
echo
-----------------
It will generate the following output.
> $ ./test.sh
> test1
> error
> ret: 1
>
> test2
> ret: 0
>
> test3
> 1
> ret: 0
>
> test4
> ret: 1
The interesting case is the last one. "type -t package" returns the return code 1 and an ERR signal, but the ERR trap is not triggered, even though "echo 1" is actually never executed. So, there are several possibilities to catch the ERR signal and I only went for the exclamation mark, because it is the shortest one :). It would also be possible to use "|| echo" if you think it is easier to understand, however, it implies a wrong assumption (return code > 0 = ERR) in my opinion and the "echo" is not needed here.
>
> Anyway, this is certainly a good catch for when applying the [[ & ((
> patch. The rest of the patch looks good to me.
I thought I already comment about this in the thread. Anyway, you are aware of it now.
>
> Allan
More information about the pacman-dev
mailing list