Re: [pacman-dev] [PATCH v2 1/2] makepkg: implement error codes

2017-09-20 Thread brainpower
Am 15.09.2017 um 20:30 schrieb ivy.fos...@gmail.com:
> @@ -1459,16 +1458,17 @@ unset "${!sha384sums_@}" "${!sha512sums_@}"
>  BUILDFILE=${BUILDFILE:-$BUILDSCRIPT}
>  if [[ ! -f $BUILDFILE ]]; then
>   error "$(gettext "%s does not exist.")" "$BUILDFILE"
> - exit 1
> + exit $E_BUILD_FAILED=5

Small thing everyone seems to have overlooked:
This line looks wrong to me.
bash probably won't like it either. ;)


-- 
regards,
brainpower



signature.asc
Description: OpenPGP digital signature


Re: [pacman-dev] [PATCH v2 1/2] makepkg: implement error codes

2017-09-17 Thread Ivy Foster
Dave Reisner  wrote:
> On Sun, Sep 17, 2017 at 05:34:15PM +1000, Allan McRae wrote:
> > On 16/09/17 06:54, Dave Reisner wrote:
> >>> +Errors
> >>> +--
> >>> +On exit, makepkg will return one of the following error codes.
> >>> +
> >>> +**E_OK**=0::
> >> I don't see the need to document internal details of how we refer to the
> >> error codes through named variables if we aren't making these public API.
> > 
> > To clarify - you are saying to remove "E_OK" etc from the documentation,
> > but keep the number and description? That seems fair enough to me.

> Yep, that's correct. Similar to how curl(1) documents its exit codes.

Ah, yes, I see what you mean.

iff


Re: [pacman-dev] [PATCH v2 1/2] makepkg: implement error codes

2017-09-17 Thread Dave Reisner
On Sun, Sep 17, 2017 at 05:34:15PM +1000, Allan McRae wrote:
> On 16/09/17 06:54, Dave Reisner wrote:
> >> +Errors
> >> +--
> >> +On exit, makepkg will return one of the following error codes.
> >> +
> >> +**E_OK**=0::
> > I don't see the need to document internal details of how we refer to the
> > error codes through named variables if we aren't making these public API.
> > 
> 
> To clarify - you are saying to remove "E_OK" etc from the documentation,
> but keep the number and description? That seems fair enough to me.
> 
> Allan

Yep, that's correct. Similar to how curl(1) documents its exit codes.


Re: [pacman-dev] [PATCH v2 1/2] makepkg: implement error codes

2017-09-17 Thread Allan McRae
On 16/09/17 06:54, Dave Reisner wrote:
>> +Errors
>> +--
>> +On exit, makepkg will return one of the following error codes.
>> +
>> +**E_OK**=0::
> I don't see the need to document internal details of how we refer to the
> error codes through named variables if we aren't making these public API.
> 

To clarify - you are saying to remove "E_OK" etc from the documentation,
but keep the number and description? That seems fair enough to me.

Allan


Re: [pacman-dev] [PATCH v2 1/2] makepkg: implement error codes

2017-09-15 Thread Ivy Foster
Dave Reisner  wrote:
> I didn't go over this in detail, but I'll point out a few concerns I
> have about this patch...

Fair enough, thanks for the feedback.

> On Fri, Sep 15, 2017 at 01:30:51PM -0500, ivy.fos...@gmail.com wrote:
> > +Errors
> > +--
> > +On exit, makepkg will return one of the following error codes.
> > +
> > +**E_OK**=0::
> 
> I don't see the need to document internal details of how we refer to the
> error codes through named variables if we aren't making these public API.

The rationale here was that it could be useful information for anybody
scripting builds, but I don't feel strongly about it. I do see your
point; anybody using these to (say) make tests for makepkg can easily
figure out what they all mean from the names in the source.

> > +**E_BUILD_FAILED**=5::
> > +   Error in PKGBUILD build function.
> > +
> > +**E_PACKAGE_FAILED**=6::
> > +   Failed to create a viable package.
> 
> What about failures in the prepare of pkgver functions (and any future
> functions which haven't yet been defined)? I think this ought to be more
> generic and be something like E_USER_FUNCTION_FAILED.

That's a good idea.

> > +**E_PRETTY_BAD_PRIVACY**=17::
> > +   Error signing package.
> 
> As implemented, this is only used when checking to see that the key
> exists, not as a failure when signing the package. To do that, you'd
> need to change scripts/libmakepkg/integrity/generate_signature.sh.in,
> and then make sure the error code is propagated down the stack.

...you're quite right. Will fix.

> > +# exit code 2 reserved by bash for misuse of shell builtins
> 
> Not sure I understand this... When would this clash?

I'm not sure that it would; I just happened across that tidbit in
tldp's bash scripting guide while looking for something else. Further
research (actually looking it up in bash(1)) reveals that it isn't
actually *reserved*, just used for that by bash. Will fix.

Thanks again for the critique. I'll get this stuff cleaned up sometime
in the next couple of days.

iff


Re: [pacman-dev] [PATCH v2 1/2] makepkg: implement error codes

2017-09-15 Thread Dave Reisner
I didn't go over this in detail, but I'll point out a few concerns I
have about this patch...

On Fri, Sep 15, 2017 at 01:30:51PM -0500, ivy.fos...@gmail.com wrote:
> From: Ivy Foster 
> 
> For your convenience, makepkg now has 16 distinct ways to fail.
> ---
>  doc/makepkg.8.txt   |  60 ++
>  scripts/Makefile.am |   1 +
>  scripts/libmakepkg/util/error.sh.in |  42 +
>  scripts/makepkg.sh.in   | 120 
> ++--
>  4 files changed, 162 insertions(+), 61 deletions(-)
>  create mode 100644 scripts/libmakepkg/util/error.sh.in
> 
> diff --git a/doc/makepkg.8.txt b/doc/makepkg.8.txt
> index 2dff1b19..224292a2 100644
> --- a/doc/makepkg.8.txt
> +++ b/doc/makepkg.8.txt
> @@ -272,6 +272,66 @@ See linkman:makepkg.conf[5] for more details on 
> configuring makepkg using the
>  'makepkg.conf' file.
>  
>  
> +Errors
> +--
> +On exit, makepkg will return one of the following error codes.
> +
> +**E_OK**=0::

I don't see the need to document internal details of how we refer to the
error codes through named variables if we aren't making these public API.

> + Normal exit condition.
> +
> +**E_FAIL**=1::
> + Unknown cause of failure.
> +
> +// Exit code 2 is reserved by bash for misuse of shell builtins
> +
> +**E_CONFIG_ERROR**=3::
> + Error in configuration file.
> +
> +**E_INVALID_OPTION**=4::
> + User specified an invalid option
> +
> +**E_BUILD_FAILED**=5::
> + Error in PKGBUILD build function.
> +
> +**E_PACKAGE_FAILED**=6::
> + Failed to create a viable package.

What about failures in the prepare of pkgver functions (and any future
functions which haven't yet been defined)? I think this ought to be more
generic and be something like E_USER_FUNCTION_FAILED.

> +**E_MISSING_FILE**=7::
> + A source or auxiliary file specified in the PKGBUILD is
> + missing.
> +
> +**E_MISSING_PKGDIR**=8::
> + The PKGDIR is missing.
> +
> +**E_INSTALL_DEPS_FAILED**=9::
> + Failed to install dependencies.
> +
> +**E_REMOVE_DEPS_FAILED**=10::
> + Failed to remove dependencies.
> +
> +**E_ROOT**=11::
> + User attempted to run makepkg as root.
> +
> +**E_FS_PERMISSIONS**=12::
> + User lacks permissions to build or install to a given
> + location.
> +
> +**E_PKGBUILD_ERROR**=13::
> + Error parsing PKGBUILD.
> +
> +**E_ALREADY_BUILT**=14::
> + A package has already been built.
> +
> +**E_INSTALL_FAILED**=15::
> + The package failed to install.
> +
> +**E_MISSING_MAKEPKG_DEPS**=16::
> + Programs necessary to run makepkg are missing.
> +
> +**E_PRETTY_BAD_PRIVACY**=17::
> + Error signing package.

As implemented, this is only used when checking to see that the key
exists, not as a failure when signing the package. To do that, you'd
need to change scripts/libmakepkg/integrity/generate_signature.sh.in,
and then make sure the error code is propagated down the stack.

> +
> +
>  See Also
>  
>  linkman:makepkg.conf[5], linkman:PKGBUILD[5], linkman:pacman[8]
> diff --git a/scripts/Makefile.am b/scripts/Makefile.am
> index 4bb08a24..3e7689bf 100644
> --- a/scripts/Makefile.am
> +++ b/scripts/Makefile.am
> @@ -96,6 +96,7 @@ LIBMAKEPKG_IN = \
>   libmakepkg/tidy/strip.sh \
>   libmakepkg/tidy/zipman.sh \
>   libmakepkg/util.sh \
> + libmakepkg/util/error.sh \
>   libmakepkg/util/message.sh \
>   libmakepkg/util/option.sh \
>   libmakepkg/util/parseopts.sh \
> diff --git a/scripts/libmakepkg/util/error.sh.in 
> b/scripts/libmakepkg/util/error.sh.in
> new file mode 100644
> index ..eefd5652
> --- /dev/null
> +++ b/scripts/libmakepkg/util/error.sh.in
> @@ -0,0 +1,42 @@
> +#!/bin/bash
> +#
> +#   error.sh.in - error variable definitions for makepkg
> +#
> +#   Copyright (c) 2006-2017 Pacman Development Team 
> 
> +#   Copyright (c) 2002-2006 by Judd Vinet 
> +#
> +#   This program is free software; you can redistribute it and/or modify
> +#   it under the terms of the GNU General Public License as published by
> +#   the Free Software Foundation; either version 2 of the License, or
> +#   (at your option) any later version.
> +#
> +#   This program is distributed in the hope that it will be useful,
> +#   but WITHOUT ANY WARRANTY; without even the implied warranty of
> +#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> +#   GNU General Public License for more details.
> +#
> +#   You should have received a copy of the GNU General Public License
> +#   along with this program.  If not, see .
> +#
> +
> +[[ -n "$LIBMAKEPKG_UTIL_ERROR_SH" ]] && return
> +LIBMAKEPKG_UTIL_ERROR_SH=1
> +
> +E_OK=0
> +E_FAIL=1 # Generic error
> +# exit code 2 reserved by bash for misuse of shell builtins

Not sure I understand this... When would this clash?

> +E_CONFIG_ERROR=3
> +E_INVALID_OPTION=4
> +E_BUILD_FAILED=5
> +E_PACKAGE_FAILED=6
> +E_MISSING_FILE=7
> +E_MISSING_PKGDIR=8
> +E_INSTALL_DEPS_FAILED=9
> 

[pacman-dev] [PATCH v2 1/2] makepkg: implement error codes

2017-09-15 Thread ivy . foster
From: Ivy Foster 

For your convenience, makepkg now has 16 distinct ways to fail.
---
 doc/makepkg.8.txt   |  60 ++
 scripts/Makefile.am |   1 +
 scripts/libmakepkg/util/error.sh.in |  42 +
 scripts/makepkg.sh.in   | 120 ++--
 4 files changed, 162 insertions(+), 61 deletions(-)
 create mode 100644 scripts/libmakepkg/util/error.sh.in

diff --git a/doc/makepkg.8.txt b/doc/makepkg.8.txt
index 2dff1b19..224292a2 100644
--- a/doc/makepkg.8.txt
+++ b/doc/makepkg.8.txt
@@ -272,6 +272,66 @@ See linkman:makepkg.conf[5] for more details on 
configuring makepkg using the
 'makepkg.conf' file.
 
 
+Errors
+--
+On exit, makepkg will return one of the following error codes.
+
+**E_OK**=0::
+   Normal exit condition.
+
+**E_FAIL**=1::
+   Unknown cause of failure.
+
+// Exit code 2 is reserved by bash for misuse of shell builtins
+
+**E_CONFIG_ERROR**=3::
+   Error in configuration file.
+
+**E_INVALID_OPTION**=4::
+   User specified an invalid option
+
+**E_BUILD_FAILED**=5::
+   Error in PKGBUILD build function.
+
+**E_PACKAGE_FAILED**=6::
+   Failed to create a viable package.
+
+**E_MISSING_FILE**=7::
+   A source or auxiliary file specified in the PKGBUILD is
+   missing.
+
+**E_MISSING_PKGDIR**=8::
+   The PKGDIR is missing.
+
+**E_INSTALL_DEPS_FAILED**=9::
+   Failed to install dependencies.
+
+**E_REMOVE_DEPS_FAILED**=10::
+   Failed to remove dependencies.
+
+**E_ROOT**=11::
+   User attempted to run makepkg as root.
+
+**E_FS_PERMISSIONS**=12::
+   User lacks permissions to build or install to a given
+   location.
+
+**E_PKGBUILD_ERROR**=13::
+   Error parsing PKGBUILD.
+
+**E_ALREADY_BUILT**=14::
+   A package has already been built.
+
+**E_INSTALL_FAILED**=15::
+   The package failed to install.
+
+**E_MISSING_MAKEPKG_DEPS**=16::
+   Programs necessary to run makepkg are missing.
+
+**E_PRETTY_BAD_PRIVACY**=17::
+   Error signing package.
+
+
 See Also
 
 linkman:makepkg.conf[5], linkman:PKGBUILD[5], linkman:pacman[8]
diff --git a/scripts/Makefile.am b/scripts/Makefile.am
index 4bb08a24..3e7689bf 100644
--- a/scripts/Makefile.am
+++ b/scripts/Makefile.am
@@ -96,6 +96,7 @@ LIBMAKEPKG_IN = \
libmakepkg/tidy/strip.sh \
libmakepkg/tidy/zipman.sh \
libmakepkg/util.sh \
+   libmakepkg/util/error.sh \
libmakepkg/util/message.sh \
libmakepkg/util/option.sh \
libmakepkg/util/parseopts.sh \
diff --git a/scripts/libmakepkg/util/error.sh.in 
b/scripts/libmakepkg/util/error.sh.in
new file mode 100644
index ..eefd5652
--- /dev/null
+++ b/scripts/libmakepkg/util/error.sh.in
@@ -0,0 +1,42 @@
+#!/bin/bash
+#
+#   error.sh.in - error variable definitions for makepkg
+#
+#   Copyright (c) 2006-2017 Pacman Development Team 
+#   Copyright (c) 2002-2006 by Judd Vinet 
+#
+#   This program is free software; you can redistribute it and/or modify
+#   it under the terms of the GNU General Public License as published by
+#   the Free Software Foundation; either version 2 of the License, or
+#   (at your option) any later version.
+#
+#   This program is distributed in the hope that it will be useful,
+#   but WITHOUT ANY WARRANTY; without even the implied warranty of
+#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#   GNU General Public License for more details.
+#
+#   You should have received a copy of the GNU General Public License
+#   along with this program.  If not, see .
+#
+
+[[ -n "$LIBMAKEPKG_UTIL_ERROR_SH" ]] && return
+LIBMAKEPKG_UTIL_ERROR_SH=1
+
+E_OK=0
+E_FAIL=1 # Generic error
+# exit code 2 reserved by bash for misuse of shell builtins
+E_CONFIG_ERROR=3
+E_INVALID_OPTION=4
+E_BUILD_FAILED=5
+E_PACKAGE_FAILED=6
+E_MISSING_FILE=7
+E_MISSING_PKGDIR=8
+E_INSTALL_DEPS_FAILED=9
+E_REMOVE_DEPS_FAILED=10
+E_ROOT=11
+E_FS_PERMISSIONS=12
+E_PKGBUILD_ERROR=13
+E_ALREADY_BUILT=14
+E_INSTALL_FAILED=15
+E_MISSING_MAKEPKG_DEPS=16
+E_PRETTY_BAD_PRIVACY=17
diff --git a/scripts/makepkg.sh.in b/scripts/makepkg.sh.in
index 20e9dd7e..a8a8eb41 100644
--- a/scripts/makepkg.sh.in
+++ b/scripts/makepkg.sh.in
@@ -130,7 +130,7 @@ clean_up() {
return
fi
 
-   if (( ! EXIT_CODE && CLEANUP )); then
+   if (( (EXIT_CODE == E_OK || EXIT_CODE == E_INSTALL_FAILED) && CLEANUP 
)); then
local pkg file
 
# If it's a clean exit and -c/--clean has been passed...
@@ -184,7 +184,7 @@ update_pkgver() {
newpkgver=$(run_function_safe pkgver)
if ! check_pkgver "$newpkgver"; then
error "$(gettext "pkgver() generated an invalid version: %s")" 
"$newpkgver"
-   exit 1
+   exit $E_PKGBUILD_ERROR
fi
 
if [[ -n $newpkgver && $newpkgver != "$pkgver" ]]; then
@@ -192,7 +192,7 @@ update_pkgver() {
if ! @SEDINPLACE