From: Ivy Foster
For your convenience, makepkg now has 16 distinct ways to fail.
---
doc/makepkg.8.txt | 60 ++
scripts/makepkg.sh.in | 140 --
2 files changed, 139 insertions(+), 61 deletions(-)
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/makepkg.sh.in b/scripts/makepkg.sh.in
index 20e9dd7e..8ef3c48d 100644
--- a/scripts/makepkg.sh.in
+++ b/scripts/makepkg.sh.in
@@ -87,6 +87,26 @@ SPLITPKG=0
SOURCEONLY=0
VERIFYSOURCE=0
+# Errors
+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
+
export SOURCE_DATE_EPOCH=${SOURCE_DATE_EPOCH:-$(date +%s)}
PACMAN_OPTS=()
@@ -130,7 +150,7 @@ clean_up() {
return
fi
- if (( ! EXIT_CODE && CLEANUP )); then
+ if (( (EXIT_CODE == E_OK || EXIT_CODE == 15) && CLEANUP )); then
local pkg file
# If it's a clean exit and -c/--clean has been passed...
@@ -184,7 +204,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 +212,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:" "$BUILDFILE"
source_safe "$BUILDFILE"
@@ -209,7 +229,7 @@ update_pkgver() {
missing_source_file() {
error "$(gettext "Unable to find source file %s.")" "$(get_filename
"$1")"
plain "$(gettext "Aborting...")"
- exit 1 # $E_MISSING_FILE
+ exit $E_MISSING_FILE
}
run_pacman() {
@@ -263,7 +283,7 @@ handle_deps() {
if ! run_pacman -S --asdeps "${deplist[@]}"; then
error "$(gettext "'%s' failed to install missing
dependencies.")" "$PACMAN"
- exit 1 # TODO: error code
+ exit $E_INSTALL_DEPS_FAILED
fi
fi
@@ -284,12 +304,12 @@ resolve_deps() {
# deplist cannot be declared like this: local deplist=$(foo)
# Otherwise, the return value will depend on the assignment.
local deplist
- deplist=($(check_deps "$@")) || exit 1
+ deplist=($(check_deps "$@")) || exit $E_INSTALL_DEPS_FAILED
[[ -z $deplist ]] && return $R_DEPS_SATISFIED
if handle_deps "${deplist[@]}"; then
# check deps again to make sure they were resolved
- de