fix: fix message by write to a temp message file

fixes #1
This commit is contained in:
2025-12-26 18:02:02 -05:00
parent c682ef1049
commit a11405d93f

61
leaf
View File

@@ -28,6 +28,9 @@ done
declare -A BUILD_OPTIONS
BUILD_OPTIONS=([strip]="0" [libtool]="0" [zipman]="0")
# global message file list
declare -a LEAF_MESSAGE_FILES=()
main() {
leaf_check_directories
if [ $# -le 1 ]; then
@@ -55,6 +58,7 @@ main() {
leaf_find_pkgbuild "${_item}"
fi
leaf_reset_state
leaf_message_init
if [[ x"$1" == x"remove" ]]; then
source "${TRACE_DIR}/${PKG_PREFIX}/${PKG_NAME}/PKGBUILD" || leaf_record_message "cannot find PKGBUILD, ingore."
else
@@ -89,9 +93,7 @@ main() {
leaf_print_usage
;;
esac
if [ -n "${MESSAGE}" ]; then
echo -e "${MESSAGE}"
fi
leaf_print_message
fi
}
@@ -168,9 +170,7 @@ leaf_compress_man_pages() {
}
leaf_error() {
if [ -n "${MESSAGE}" ]; then
echo -e "${MESSAGE}"
fi
leaf_print_message
echo -e "${RED_COLOR}* $1${CLEAR_COLOR}" && exit 1
}
@@ -291,7 +291,7 @@ Usage: leaf [option] [packages]
Option: prepare prepare packages but do not build
build build packages but do not install
install install packages
forece-install install packages even if test faild
forece-install install packages even if test failed
dirct-install install packages directly from previous build
remove remove packages
clean clean all source folders
@@ -304,14 +304,53 @@ Option: prepare prepare packages but do not build
EOF
}
leaf_message_init() {
# one log per package invocation
local d="${TEMP_DIR}/leaf-messages/${PKG_PREFIX}/${PKG_NAME}"
install -dm755 -- "$d"
LEAF_MESSAGE_FILE="${d}/messages.$$.$(date +%Y%m%d%H%M%S).log"
: > "${LEAF_MESSAGE_FILE}"
export LEAF_MESSAGE_FILE
LEAF_MESSAGE_FILES+=("${LEAF_MESSAGE_FILE}")
}
leaf_record_message() {
MESSAGE+="\n${PURPLE_COLOR}* Message from ${PKG_PREFIX}/${PKG_NAME}${CLEAR_COLOR}\n"
local out
local _item
for _item in "${@:1}"; do
MESSAGE+="${GREEN_COLOR}* ${_item}${CLEAR_COLOR}\n"
out+="${GREEN_COLOR}* ${_item}${CLEAR_COLOR}\n"
done
if [ -n "${LEAF_MESSAGE_FILE}" ]; then
# printf %b will explain \n 和 \e
printf '%b' "${out}" >> "${LEAF_MESSAGE_FILE}"
fi
}
leaf_print_message() {
local f prefix name
for f in "${LEAF_MESSAGE_FILES[@]}"; do
[ -n "$f" ] || continue
[ -s "$f" ] || continue
# ${TEMP_DIR}/leaf-messages/<prefix>/<name>/messages....
prefix="${f#${TEMP_DIR}/leaf-messages/}"
prefix="${prefix%%/*}"
name="${f#${TEMP_DIR}/leaf-messages/${prefix}/}"
name="${name%%/*}"
echo -e "\n${PURPLE_COLOR}* Message from ${prefix}/${name}${CLEAR_COLOR}\n"
cat -- "$f"
rm -f -- "$f"
done
LEAF_MESSAGE_FILES=()
unset LEAF_MESSAGE_FILE
}
leaf_remove_libtool_files() {
find "${pkgdir}" -name "*.la" -delete
}
@@ -492,12 +531,12 @@ leaf_prepare_package() {
popd >/dev/null || true
echo "Sources ready."
leaf_phase_must "Preparing" src_prepare "Prepare faild."
leaf_phase_must "Preparing" src_prepare "Prepare failed."
}
leaf_build_package() {
leaf_prepare_package
leaf_phase_must "Building" src_build "Build faild."
leaf_phase_must "Building" src_build "Build failed."
leaf_phase_try "Checking" src_check
if [ "${LEAF_PHASE_RC}" -ne 0 ]; then