Commit b57268f921a3fa64cc64a2569ebb38e41510f58e

Thomas de Grivel 2023-02-13T16:34:02

shpkg_tag_log

diff --git a/share/shpkg/shpkg.subr b/share/shpkg/shpkg.subr
index f5ea192..8d06a90 100644
--- a/share/shpkg/shpkg.subr
+++ b/share/shpkg/shpkg.subr
@@ -59,8 +59,35 @@ err () {
 # Logging
 
 shpkg_start_logging () {
-    SHPKG_LOG="${SHPKG_LOG_DIR}/shpkg_${SHPKG_DATE}_$$.log"
-    verbose -n 2 "shpkg_start_logging: see log with less -R ${SHPKG_LOG}" | tee "${SHPKG_LOG}"
+    SHPKG_LOG="${SHPKG_LOG_DIR}/all/shpkg_${SHPKG_DATE}_$$.log"
+    SHPKG_LOG_RELATIVE="../all/$(basename "${SHPKG_LOG}")"
+    SHPKG_LOG_TAGS_DIR="${SHPKG_LOG_DIR}/tags"
+    if ! [ -d "${SHPKG_LOG_DIR}" ]; then
+        verbose 1 mkdir -p "${SHPKG_LOG_DIR}"
+    fi
+    if [ -f "${SHPKG_LOG}" ]; then
+        err 1 "log file already present"
+    fi
+    {
+        verbose -n 2 "shpkg_start_logging: see log with less -R ${SHPKG_LOG}"
+        if ! [ -d "${SHPKG_LOG_TAGS_DIR}" ]; then
+            verbose 1 mkdir -p "${SHPKG_LOG_TAGS_DIR}"
+        fi
+    } | tee "${SHPKG_LOG}"
+}
+
+shpkg_tag_log () {
+    SHPKG_LOG_TAG="$1"
+    SHPKG_LOG_TAG_DIR="$(dirname ${SHPKG_LOG_TAG})"
+    SHPKG_LOG_TAG_PATH="${SHPKG_LOG_TAGS_DIR}/${SHPKG_LOG_TAG}"
+    verbose -n 2 "logging to ${SHPKG_LOG_TAG_PATH}"
+    if [ -f "${SHPKG_LOG_TAG_PATH}" ]; then
+        verbose 1 rm "${SHPKG_LOG_TAG_PATH}.tmp"
+    fi
+    ( verbose 1 cd "${SHPKG_LOG_TAGS_DIR}" &&
+          verbose 1 mkdir -p "${SHPKG_LOG_TAG_DIR}" &&
+          verbose 1 ln -s "${SHPKG_LOG_RELATIVE}" "${SHPKG_LOG_TAG}.tmp" &&
+          verbose 1 mv "${SHPKG_LOG_TAG}.tmp" "${SHPKG_LOG_TAG}"; )
 }
 
 # C compiler
@@ -179,10 +206,15 @@ shpkg_checkout () {
         if ! [ -d "${SHPKG_REPO_SRC_DIR}" ]; then
             ( verbose 2 shpkg_clone "${SHPKG_REPO}"; )
         fi
+        SHPKG_REPO_VERSION_A="$(shpkg_version "${SHPKG_REPO}")"
         ( verbose 1 cd "${SHPKG_SRC_DIR}/${SHPKG_REPO_DIR}" &&
               verbose 1 git fetch origin "$TREE" &&
               verbose 1 git checkout "$TREE" &&
               verbose 1 git submodule update; )
+        SHPKG_REPO_VERSION_B="$(shpkg_version "${SHPKG_REPO}")"
+        if [ "x${SHPKG_REPO_VERSION_A}" != "x${SHPKG_REPO_VERSION_B}" ]; then
+            verbose 2 shpkg_tag_log "${SHPKG_REPO}.checkout"
+        fi
     done
 }
 
@@ -488,6 +520,7 @@ shpkg_install () {
 	    SHPKG_REPO_INSTALLED="${SHPKG_VAR_DB_DIR}/installed/${SHPKG_REPO_DIR}"
 	    SHPKG_REPO_INSTALLED_DIR="$(dirname "${SHPKG_REPO_INSTALLED}")"
 	    if ! shpkg_is_installed "${SHPKG_REPO}"; then
+                verbose 2 shpkg_tag_log "${SHPKG_REPO}.install.log"
 	        ( verbose 2 shpkg_install_dependencies "${SHPKG_REPO}"; )
 	        ( verbose 2 shpkg_build "${SHPKG_REPO}"; )
 	        ( verbose 2 shpkg_package "${SHPKG_REPO}"; )
@@ -555,6 +588,7 @@ shpkg_uninstall () {
         fi
 	SHPKG_REPO_INSTALLED="${SHPKG_VAR_DB_DIR}/installed/${SHPKG_REPO_DIR}"
         if [ -f "${SHPKG_REPO_INSTALLED}" ]; then
+            verbose 2 shpkg_tag_log "${SHPKG_REPO}.uninstall.log"
             verbose 1 cd "${SHPKG_DIR}"
             grep -v : "${SHPKG_REPO_INSTALLED}" |
                 cut -d '(' -f 2 |
@@ -587,6 +621,7 @@ shpkg_upgrade_rec () {
         if ! shpkg_is_system_package "${SHPKG_REPO_DIR}"; then
             verbose 2 shpkg_pull "${SHPKG_REPO}"
             if ! shpkg_latest_is_installed "${SHPKG_REPO}"; then
+                verbose 2 shpkg_tag_log "${SHPKG_REPO}.upgrade.log"
                 verbose 2 shpkg_build "${SHPKG_REPO}"
                 verbose 2 shpkg_package "${SHPKG_REPO}"
                 verbose 2 shpkg_uninstall "${SHPKG_REPO}"