autobuild3
autobuild3 copied to clipboard
Fix error handling for custom build scripts
Our current error handling for sourced scripts involve testing what is returned from the script itself. For predefined build scripts this works well because we have many return-on-error hooks, but things go wild with poorly-written (read: every single one of) autobuild/build scripts.
We can either fix all the scripts, or at least partially switch to some "strict mode" handling by set -ueE and trap something ERR. (Hell, I don't even like how .() messes up scopes in the first place.) It is, however, still important to note that set -e does not properly handle lines with && and/or ||. And I also have no idea about how to re-enter the script from an error handler.
https://github.com/AOSC-Dev/autobuild3/blob/a471ed6fbeccacbaba351ff307e57196ab4a93c9/build/00-self.sh#L10-L16
Is this a hook?
Yes, it is. See https://github.com/AOSC-Dev/autobuild3/blob/d146b34/proc/50-build_exec.sh#L6-L25.
https://github.com/AOSC-Dev/autobuild3/blob/d146b34acfd90ad1b02579c47c6c4e306523c245/proc/50-build_exec.sh#L27
Looks good, but why do ABTYPE=self never exit when errors occur?
For example, autobuild/build:
false
echo It should not be here
Is it because set -e cannot work properly in this scope?
We have a set -e ???????
arch_loadfile_strict have.
It's probably the || thing that is breaking set -e here. Perhaps it should be rewritten into an explicit if (($?)); then ...