Subject: Re: Making pkgsrc more robust
To: None <tech-pkg@netbsd.org>
From: Roland Illig <rillig@NetBSD.org>
List: tech-pkg
Date: 02/06/2006 23:28:01
Roland Illig wrote:
> Hi,
> 
> to make pkgsrc (in general; especially the bulk builds) more robust 
> against unforeseen errors, I'd like to add the command "set -e -u" at 
> the top of every shell program that is used in the pkgsrc infrastructure.
> 
> The -e option terminates the program as soon as a command fails, which 
> is much more often appropriate than just continuing. The current shell 
> programs contain lots of lines like:
> 
>     cd "$some_directory"
>     do_something
> 
> So what should be done if the directory $some_directory is not accessible?
> 
> The -u option terminates the program as soon as an uninitialized 
> variable is used. This prevents from spelling mistakes. If you want to 
> use a possibly-undefined variable, you can provide a default value using 
> ${possibly_undefined_variable-default_value} instead of 
> $possibly_undefined_variable.
> 
> Together these two options will probably make pkgsrc break more often 
> than before, but almost always at points where the error checking had 
> not be done in the past. These points must be fixed anyway, so this is 
> just a help to find them early.

Today I had the idea to add the following to mk/defaults/mk.conf:

# This variable determines which amount of self-checks should be done
# in pkgsrc. The higher this value is, the more packages will probably
# fail. Currently, the levels 0, 1 and 2 are supported.
PKG_STRICT_LEVEL?=      0

And the following for mk/bsd.pkg.mk:

.if ${PKG_STRICT_LEVEL} >= 1
_PKG_DEBUG+=            set -e;
.endif
.if ${PKG_STRICT_LEVEL} >= 2
_PKG_DEBUG+=            set -u;
.endif

SCRIPTS_ENV+=           PKG_STRICT_LEVEL=${PKG_STRICT_LEVEL:Q}
# (and maybe some other environment variable lists)

This would catch many errors in the packages, as well as some of the 
infrastructure code. Standalone shell programs should then start with 
the following two lines.

test "${PKG_STRICT_LEVEL-0}" -lt 1 || set -e
test "${PKG_STRICT_LEVEL-0}" -lt 2 || set -u

Roland