From 8b67dbd91f210f8379ee32bfef4c1aa9318f8a11 Mon Sep 17 00:00:00 2001 From: Pete Fotheringham Date: Mon, 2 Sep 2024 11:39:24 +0100 Subject: [PATCH] Add `do_cleanup` function --- src/new_build.sh | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/new_build.sh b/src/new_build.sh index 66dbdfc..ef6e327 100644 --- a/src/new_build.sh +++ b/src/new_build.sh @@ -45,3 +45,34 @@ # - call `post-build.sh` # - call `do_cleanup` # - call `end.sh` + +# do_cleanup function +do_cleanup() { + echo ">> [$(date)] Cleaning up" | tee -a "$DEBUG_LOG" + + if [ "$BUILD_OVERLAY" = true ]; then + # The Jack server must be stopped manually, as we want to unmount $TMP_DIR/merged + cd "$TMP_DIR" + if [ -f "$TMP_DIR/merged/prebuilts/sdk/tools/jack-admin" ]; then + "$TMP_DIR/merged/prebuilts/sdk/tools/jack-admin kill-server" &> /dev/null || true + fi + lsof | grep "$TMP_DIR/merged" | awk '{ print $2 }' | sort -u | xargs -r kill &> /dev/null || true + + while lsof | grep -q "$TMP_DIR"/merged; do + sleep 1 + done + + umount "$TMP_DIR/merged" + fi + + if [ "$CLEAN_AFTER_BUILD" = true ]; then + echo ">> [$(date)] Cleaning source dir for device $codename" | tee -a "$DEBUG_LOG" + if [ "$BUILD_OVERLAY" = true ]; then + cd "$TMP_DIR" + rm -rf ./* || true + else + cd "$source_dir" + (set +eu ; mka "${jobs_arg[@]}" clean) &>> "$DEBUG_LOG" + fi + fi +}