From 57ea39b406eac5a0f51bde313b0698f8c99c40bd Mon Sep 17 00:00:00 2001 From: Yingjie Wang Date: Fri, 26 Dec 2025 23:32:34 -0500 Subject: [PATCH] feat: check dummy function, do not echo --- leaf | 56 +++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 35 insertions(+), 21 deletions(-) diff --git a/leaf b/leaf index da4f94d..c89e63e 100755 --- a/leaf +++ b/leaf @@ -363,29 +363,38 @@ leaf_remove_libtool_files() { find "${pkgdir}" -name "*.la" -delete } +leaf_noop() { :; } + leaf_reset_state() { options=() - src_preinstall() { - : - } - src_postinstall() { - : - } - src_preremove() { - : - } - src_postremove() { - : - } - src_prepare() { - : - } - src_build() { - : - } - src_check() { - : - } + src_preinstall() { leaf_noop; } + src_postinstall() { leaf_noop; } + src_preremove() { leaf_noop; } + src_postremove() { leaf_noop; } + + src_prepare() { leaf_noop; } + src_build() { leaf_noop; } + src_check() { leaf_noop; } + src_install() { leaf_noop; } +} + +leaf_is_noop_func() { + # usage: leaf_is_noop_func + local fn="$1" body + + declare -F "$fn" >/dev/null || return 0 + + body="$(declare -f "$fn" \ + | sed -n '0,/{/d; :a; /}/q; p; n; ba')" + + body="$(printf '%s' "$body" | tr -d '[:space:]' | tr -d ';')" + + # allowd no-op form: leaf_noop, :, true + case "$body" in + leaf_noop|:|true) return 0 ;; + esac + + return 1 } leaf_strip_files() { @@ -463,6 +472,11 @@ leaf_run_phase() { return 0 } + if leaf_is_noop_func "$fn"; then + LEAF_PHASE_RC=0 + return 0 + fi + echo -e "${GREEN_COLOR}>>> ${PKG_PREFIX}/${PKG_NAME}: ${phase}${CLEAR_COLOR}" set +e