From 4aeeaa9cbd7dfb00bec5105b7910742052f76141 Mon Sep 17 00:00:00 2001 From: zoltanvb Date: Tue, 11 Mar 2025 07:07:17 +0100 Subject: [PATCH] Show a summary of libretro-fetch success. --- libretro-fetch.sh | 37 +++++++++++++++++++++++++++++++++++ script-modules/fetch-rules.sh | 13 ++++++++++++ 2 files changed, 50 insertions(+) diff --git a/libretro-fetch.sh b/libretro-fetch.sh index 6abacb32..e36f93c5 100755 --- a/libretro-fetch.sh +++ b/libretro-fetch.sh @@ -28,6 +28,30 @@ fi . "$BASE_DIR/rules.d/lutro-rules.sh" . "$BASE_DIR/build-config.sh" + +summary_fetch() { + # fmt is external and may not be available + fmt_output="$(find_tool "fmt")" + local num_success="$(numwords $fetch_success)" + local fmt_success="${fmt_output:+$(echo " $fetch_success" | $fmt_output)}" + local num_fail="$(numwords $fetch_fail)" + local fmt_fail="${fmt_output:+$(echo " $fetch_fail" | $fmt_output)}" + + if [[ -z "$fetch_success" && -z "$fetch_fail" ]]; then + secho "No fetch actions performed." + return + fi + + if [ -n "$fetch_success" ]; then + secho "$(color 32)$num_success core(s)$(color) successfully processed:" + secho "$fmt_success" + fi + if [ -n "$fetch_fail" ]; then + secho "$(color 31)$num_fail core(s)$(color) failed:" + secho "$fmt_fail" + fi +} + # libretro_fetch: Download the given core using its fetch rules # # $1 Name of the core to fetch @@ -66,6 +90,10 @@ libretro_fetch() { # TODO: Don't depend on fetch_rule being git echo "Fetching ${1}..." fetch_git "$git_url" "$module_dir" "$git_submodules" + if [ $? -ne 0 ]; then + return 1 + fi + ;; *) @@ -78,6 +106,9 @@ libretro_fetch() { if [ -n "$post_fetch_cmd" ]; then echo_cmd "cd \"$WORKDIR/$module_dir\"" echo_cmd "$post_fetch_cmd" + if [ $? -ne 0 ]; then + exit 1 + fi fi } @@ -126,4 +157,10 @@ done for a in $fetch_cores; do libretro_fetch "${a%%:*}" + if [ $? -eq 0 ]; then + export fetch_success="$fetch_success$a " + else + export fetch_fail="$fetch_fail$a " + fi done +summary_fetch diff --git a/script-modules/fetch-rules.sh b/script-modules/fetch-rules.sh index bc338c11..5a918822 100644 --- a/script-modules/fetch-rules.sh +++ b/script-modules/fetch-rules.sh @@ -14,18 +14,31 @@ fetch_git() { if [ -d "$fetch_dir/.git" ]; then echo_cmd "cd \"$fetch_dir\"" echo_cmd "git pull" + if [ $? -ne 0 ]; then + return 1 + fi if [ "$3" = "yes" ]; then echo_cmd "git submodule foreach git pull origin master" + if [ $? -ne 0 ]; then + return 1 + fi fi else clone_type= [ -n "$SHALLOW_CLONE" ] && depth="--depth 1 " echo_cmd "git clone $depth\"$1\" \"$WORKDIR/$2\"" + if [ $? -ne 0 ]; then + return 1 + fi if [[ "$3" = "yes" || "$3" = "clone" ]]; then echo_cmd "cd \"$fetch_dir\"" echo_cmd "git submodule update --init --recursive" + if [ $? -ne 0 ]; then + return 1 + fi fi fi + return $? } # fetch_revision_git: Output the hash of the last commit in a git repository