libcosmicAppHook: fix wrapping skipped when separateDebugInfo = true

With separateDebugInfo, fixupOutputHooks runs the hook for the debug
output first, which has no bin/libexec, then the old boolean guard
causes the real output to be skipped entirely.

Switch to a per-prefix guard so each output is processed independently,
while still preventing duplicate runs for the same prefix.

Also adds debug logging throughout the hook to make future diagnosis
easier.

Signed-off-by: Kajus Naujokaitis <kajusn@gmail.com>
This commit is contained in:
Kajus Naujokaitis 2026-06-29 11:06:34 +03:00
commit 7492a9f55e
No known key found for this signature in database

View file

@ -5,6 +5,7 @@
# shellcheck shell=bash
libcosmicAppWrapperArgs=()
libcosmicAppWrapHookRanFor=()
libcosmicAppVergenHook() {
if [ -z "${VERGEN_GIT_COMMIT_DATE-}" ]; then
@ -51,9 +52,18 @@ wrapLibcosmicApp() {
# Note: $libcosmicAppWrapperArgs still gets defined even if ${dontWrapLibcosmicApp-} is set
libcosmicAppWrapHook() {
# guard against running multiple times (e.g. due to propagation)
[ -z "$libcosmicAppWrapHookHasRun" ] || return 0
libcosmicAppWrapHookHasRun=1
# guard against running multiple times for the same prefix (e.g. due to propagation)
for _ranFor in "${libcosmicAppWrapHookRanFor[@]}"; do
if [[ "$_ranFor" == "$prefix" ]]; then
echo "[libcosmicAppWrapHook] already ran for prefix='${prefix}', returning early"
return 0
fi
done
libcosmicAppWrapHookRanFor+=("$prefix")
echo "[libcosmicAppWrapHook] prefix='${prefix}'"
echo "[libcosmicAppWrapHook] dontWrapLibcosmicApp='${dontWrapLibcosmicApp:-}'"
echo "[libcosmicAppWrapHook] libcosmicAppWrapperArgs=(${libcosmicAppWrapperArgs[*]})"
if [[ -z "${dontWrapLibcosmicApp:-}" ]]; then
targetDirsThatExist=()
@ -61,35 +71,47 @@ libcosmicAppWrapHook() {
# wrap binaries
targetDirs=("${prefix}/bin" "${prefix}/libexec")
echo "[libcosmicAppWrapHook] checking targetDirs: ${targetDirs[*]}"
for targetDir in "${targetDirs[@]}"; do
echo "[libcosmicAppWrapHook] checking targetDir='${targetDir}' exists=$([ -d "${targetDir}" ] && echo yes || echo no)"
if [[ -d "${targetDir}" ]]; then
targetDirsThatExist+=("${targetDir}")
targetDirsRealPath+=("$(realpath "${targetDir}")/")
echo "[libcosmicAppWrapHook] finding executables in '${targetDir}'"
find "${targetDir}" -type f -executable -print0 |
while IFS= read -r -d '' file; do
echo "Wrapping program '${file}'"
echo "[libcosmicAppWrapHook] wrapping program '${file}'"
wrapLibcosmicApp "${file}"
done
fi
done
echo "[libcosmicAppWrapHook] targetDirsThatExist=(${targetDirsThatExist[*]})"
echo "[libcosmicAppWrapHook] targetDirsRealPath=(${targetDirsRealPath[*]})"
# wrap links to binaries that point outside targetDirs
# Note: links to binaries within targetDirs do not need
# to be wrapped as the binaries have already been wrapped
if [[ ${#targetDirsThatExist[@]} -ne 0 ]]; then
echo "[libcosmicAppWrapHook] finding symlinks in targetDirs"
find "${targetDirsThatExist[@]}" -type l -xtype f -executable -print0 |
while IFS= read -r -d '' linkPath; do
linkPathReal=$(realpath "${linkPath}")
echo "[libcosmicAppWrapHook] checking link '${linkPath}' -> '${linkPathReal}'"
for targetPath in "${targetDirsRealPath[@]}"; do
if [[ "$linkPathReal" == "$targetPath"* ]]; then
echo "Not wrapping link: '$linkPath' (already wrapped)"
echo "[libcosmicAppWrapHook] not wrapping link: '$linkPath' (already wrapped)"
continue 2
fi
done
echo "Wrapping link: '$linkPath'"
echo "[libcosmicAppWrapHook] wrapping link: '$linkPath'"
wrapLibcosmicApp "${linkPath}"
done
else
echo "[libcosmicAppWrapHook] no targetDirs exist, skipping symlink wrapping"
fi
else
echo "[libcosmicAppWrapHook] dontWrapLibcosmicApp is set, skipping all wrapping"
fi
}