[pacman-dev] [PATCH v3] makepkg: implement error codes

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

For your convenience, makepkg now has 16 distinct ways to fail.
Also closes FS#54204.
---
 doc/makepkg.8.txt   |  57 +
 scripts/Makefile.am |   1 +
 scripts/libmakepkg/util/error.sh.in |  41 
 scripts/makepkg.sh.in   | 120 ++--
 4 files changed, 158 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..37d4b7ae 100644
--- a/doc/makepkg.8.txt
+++ b/doc/makepkg.8.txt
@@ -272,6 +272,63 @@ 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.
+
+0::
+   Normal exit condition.
+
+1::
+   Unknown cause of failure.
+
+2::
+   Error in configuration file.
+
+3::
+   User specified an invalid option
+
+4::
+   Error in user-supplied function in PKGBUILD.
+
+5::
+   Failed to create a viable package.
+
+6::
+   A source or auxiliary file specified in the PKGBUILD is
+   missing.
+
+7::
+   The PKGDIR is missing.
+
+8::
+   Failed to install dependencies.
+
+9::
+   Failed to remove dependencies.
+
+10::
+   User attempted to run makepkg as root.
+
+11::
+   User lacks permissions to build or install to a given
+   location.
+
+12::
+   Error parsing PKGBUILD.
+
+13::
+   A package has already been built.
+
+14::
+   The package failed to install.
+
+15::
+   Programs necessary to run makepkg are missing.
+
+16::
+   Specified GPG key does not exist.
+
 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 ..1ddc214d
--- /dev/null
+++ b/scripts/libmakepkg/util/error.sh.in
@@ -0,0 +1,41 @@
+#!/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
+E_CONFIG_ERROR=2
+E_INVALID_OPTION=3
+E_USER_FUNCTION_FAILED=4
+E_PACKAGE_FAILED=5
+E_MISSING_FILE=6
+E_MISSING_PKGDIR=7
+E_INSTALL_DEPS_FAILED=8
+E_REMOVE_DEPS_FAILED=9
+E_ROOT=10
+E_FS_PERMISSIONS=11
+E_PKGBUILD_ERROR=12
+E_ALREADY_BUILT=13
+E_INSTALL_FAILED=14
+E_MISSING_MAKEPKG_DEPS=15
+E_PRETTY_BAD_PRIVACY=16
diff --git a/scripts/makepkg.sh.in b/scripts/makepkg.sh.in
index 46eefd1f..3b9a54e0 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@ "s:^pkgver=[^ ]*:pkgver=$newpkgver:" 
"$BUILDFILE"; then
error "$(gettext "Failed to update %s from %s 
to %s")" \
"pkgver" "$pkgver" "$newpkgver"
-   exit 1
+   exit $E_PKGBUILD_ERROR
fi
@SEDINPLACE@ "s:^pkgrel=[^ ]*:pkgrel=1:" "$BU

[pacman-dev] Changes to v3 of makepkg error codes patch

2017-09-22 Thread ivy . foster

This attempt fixes the error, pointed out by brainpower, in which I
accidentally dropped in an assignment when I was trying to use one of
the error variables.

This time, this patch depends on the trivial wording patch sent
earlier today, rather than the other way around.

It also incorporates Dave's suggestions:
- The manpage no longer names the errors.
- E_PRETTY_BAD_PRIVACY is correctly documented (its scope could
  probably stand to be expanded to include actual GPG errors, but
  that's another patch).
- E_BUILD_FAILED has been renamed E_USER_FUNCTION_FAILED, though I
  kept E_PACKAGE_FAILED because as implemented, it's being used for
  exits on the packaging process as a whole, rather than for the user
  package function.
- Error code 2 is no longer skipped over, since bash doesn't actually
  *reserve* it.

Thanks to everyone for the feedback!

iff


Re: [pacman-dev] [PATCH v2 2/2] makepkg: clarify error when user passes -F

2017-09-22 Thread Ivy Foster
Florian Pritz via pacman-dev  wrote:
> This seems like a very straight forward change. It's generally better if
> you commit less invasive/more likely to be merged changes first so that
> they can be merged more easily.

I've just sent a version of this patch that does not depend on the
makepkg errors patch. Revised makepkg errors patch to follow.

iff

[pacman-dev] [PATCH v3] makepkg: clarify error when user passes -F

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

---
 scripts/makepkg.sh.in | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/scripts/makepkg.sh.in b/scripts/makepkg.sh.in
index 20e9dd7e..46eefd1f 100644
--- a/scripts/makepkg.sh.in
+++ b/scripts/makepkg.sh.in
@@ -1443,7 +1443,7 @@ catastrophic damage to your system.")" "makepkg"
fi
 else
if [[ -z $FAKEROOTKEY ]]; then
-   error "$(gettext "Do not use the %s option. This option is only 
for use by %s.")" "'-F'" "makepkg"
+   error "$(gettext "Do not use the %s option. This option is only 
for internal use by %s.")" "'-F'" "makepkg"
exit 1 # TODO: error code
fi
 fi
-- 
2.14.1