From e8c75ee1c0d30a2eaa3835240963c81146c508b1 Mon Sep 17 00:00:00 2001 From: "dylan.araps@gmail.com" Date: Tue, 28 Jan 2020 08:08:14 +0000 Subject: kiss: Store builds logs on fail FossilOrigin-Name: 33ffe94d2469f1a37a9650173a7f9fd5754bb43b9739e977639cd55a51d2baac --- kiss | 21 +++++++++++++++++---- kiss.1 | 4 ++-- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/kiss b/kiss index 089fd2b..9768463 100755 --- a/kiss +++ b/kiss @@ -640,8 +640,18 @@ pkg_build() { log "$pkg" "Starting build" - # Call the build script. - "$repo_dir/build" "$pkg_dir/$pkg" || die "$pkg" "Build failed" + # Call the build script, log the output to the terminal + # and to a file. There's no PIPEFAIL in POSIX shelll so + # we must resort to tricks like killing the script ourselves. + { "$repo_dir/build" "$pkg_dir/$pkg" || { + log "$pkg" "Build failed" + pkg_clean + kill 0 + } } 2>&1 | tee "$log_dir/$pkg-$pid-$time" + + # Delete the log file if the build succeeded to prevent + # the directory from filling very quickly with useless logs. + [ "$KISS_DEBUG" = 1 ] || rm -f "$log_dir/$pkg-$pid-$time" # Copy the repository files to the package directory. # This acts as the database entry. @@ -1072,8 +1082,6 @@ pkg_clean() { # to the build. stty -F /dev/tty echo 2>/dev/null - [ "$KISS_DEBUG" != 1 ] || return - # Block 'Ctrl+C' while cache is being cleaned. trap '' INT @@ -1245,6 +1253,10 @@ main() { # POSIX correctness. grep=$(command -v ggrep) || grep='grep' + # Store the date and time of script invocation to be used as the name + # of the log files the package manager creates uring builds. + time=$(date '+%d-%m-%Y-%H:%M') + # This allows for automatic setup of a KISS chroot and will # do nothing on a normal system. mkdir -p "${sys_db:=$KISS_ROOT/$pkg_db}" 2>/dev/null ||: @@ -1256,6 +1268,7 @@ main() { "${pkg_dir:=$cac_dir/pkg-$pid}" \ "${tar_dir:=$cac_dir/extract-$pid}" \ "${src_dir:=$cac_dir/sources}" \ + "${log_dir:=$cac_dir/logs}" \ "${bin_dir:=$cac_dir/bin}" \ || die "Couldn't create cache directories" diff --git a/kiss.1 b/kiss.1 index 0b7e201..19e24cd 100644 --- a/kiss.1 +++ b/kiss.1 @@ -69,8 +69,8 @@ export KISS_FORCE=0 # This can be used to have the package manager run in a "fake root". export KISS_ROOT=/ -# Keep build, package and extraction cache directories for debugging -# purposes. +# Keep build logs around for successful builds and not just failing +# ones. Helpful when debugging. # # Set it to '1' to enable. export KISS_DEBUG=0 -- cgit v1.2.3