From 00f03e97036b599d7cdca02321aad73bf53f5545 Mon Sep 17 00:00:00 2001 From: TomIO Date: Thu, 30 Jan 2025 17:51:46 +0100 Subject: [PATCH] chore(script/update-packages): Script cleanup --- scripts/bin/update-packages | 40 ++++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/scripts/bin/update-packages b/scripts/bin/update-packages index 61f0d676b1015a..42685181b1fcf6 100755 --- a/scripts/bin/update-packages +++ b/scripts/bin/update-packages @@ -126,9 +126,9 @@ declare -A _LATEST_TAGS=() declare -A _FAILED_UPDATES=() declare -a _ALREADY_SEEN=() # Array of packages successfully updated or skipped. -# _fetch_and_cache_tags fetches all possible tags using termux_pkg_auto_update, but using Ninja build system. -# The key difference is that we make the process concurrent, allowing us to fetch tags simultaneously rather than one at a time. -# Once all tags are cached, the termux_pkg_auto_update function will operate much more quickly. +# _fetch_and_cache_tags fetches all possible tags using termux_pkg_auto_update, but using Ninja build system. +# The key difference is that we make the process concurrent, allowing us to fetch tags simultaneously rather than one at a time. +# Once all tags are cached, the termux_pkg_auto_update function will operate much more quickly. # We avoid packages with overwritten termux_pkg_auto_update to prevent unexpected modifications to the package`s build.sh. _fetch_and_cache_tags() { if [ "$(uname -o)" = "Android" ] || [ -e "/system/bin/app_process" ]; then @@ -137,7 +137,7 @@ _fetch_and_cache_tags() { return 0 fi fi - + if ! command -v ninja &> /dev/null; then echo "INFO: Fetching ninja build system" . "${TERMUX_SCRIPTDIR}"/scripts/build/termux_download.sh @@ -150,20 +150,26 @@ _fetch_and_cache_tags() { # First invocation of termux_repology_api_get_latest_version fetches and caches repology metadata. quiet termux_repology_api_get_latest_version ' ' - local __PACKAGES=() + local __PACKAGES=() for repo_dir in $(jq --raw-output 'del(.pkg_format) | keys | .[]' "${TERMUX_SCRIPTDIR}/repo.json"); do for pkg_dir in "${repo_dir}"/*; do - ! quiet _should_update "${pkg_dir}" && continue # Skip if not needed. + quiet _should_update "${pkg_dir}" || continue # Skip if not needed. grep -q '^termux_pkg_auto_update' "${pkg_dir}/build.sh" && continue # Skip if package has custom auto-update __PACKAGES+=("${pkg_dir}") done done + # This is called indirectly in the ninja file + # So silence shellcheck's unreachable code warning + # shellcheck disable=SC2317 __main__() { cd ${TERMUX_SCRIPTDIR} export TERMUX_PKG_NAME="${1##*/}" TERMUX_PKG_BUILDER_DIR=${1} set +eu; - for i in scripts/updates/{**/,}*.sh "${1}/build.sh"; do source ${i}; done + for i in scripts/updates/{**/,}*.sh "${1}/build.sh"; do + # shellcheck disable=SC1090 + source "${i}" + done set -eu termux_pkg_upgrade_version() { [[ -n "$1" ]] && echo "PKG|$TERMUX_PKG_NAME|${1#*:}" @@ -176,20 +182,22 @@ _fetch_and_cache_tags() { termux_pkg_auto_update } + # This function generates a ninja file for all packages in the ${__PACKAGES[@]} __generate__() { echo "rule update" - echo " command = bash -c \"\$\$F\" -- \$pkg_dir ||:" + echo " command = bash -c \"\$\$F\" -- \$pkg_dir || :" sed 's/[^ ]\+/\nbuild &: update\n pkg_dir=&/g' <<< "${__PACKAGES[@]}" - echo "build run_all: phony ${__PACKAGES[@]}" + echo "build run_all: phony ${__PACKAGES[*]}" echo "default run_all" } - - local LATEST_TAGS="$(\ + + local LATEST_TAGS + LATEST_TAGS="$( F="$(declare -p TERMUX_SCRIPTDIR GITHUB_TOKEN TERMUX_REPOLOGY_DATA_FILE); $(declare -f __main__ | sed 's/__main__ ()//')" \ - env --chdir=/tmp ninja -f /dev/stdin <<< "$(__generate__)" |& grep "^PKG|" + env --chdir=/tmp ninja -f /dev/stdin < <(__generate__ |& grep "^PKG|") )" - - unset -f __main__ __generate__ + + unset -f __main__ __generate__ while IFS='|' read -r _ pkg version; do _LATEST_TAGS["${pkg:-_}"]="$version" done <<< "$LATEST_TAGS" @@ -303,7 +311,7 @@ _update_dependencies() { termux_error_exit "ERROR: Obtaining update order failed for $(basename "${pkg_dir}")" fi _should_update "${dep_dir}" && ! _check_updated "${dep_dir}" && _run_update "${dep_dir}" - done <<<"$("${TERMUX_SCRIPTDIR}"/scripts/buildorder.py "${pkg_dir}" $TERMUX_PACKAGES_DIRECTORIES || echo "ERROR")" + done < <("${TERMUX_SCRIPTDIR}"/scripts/buildorder.py "${pkg_dir}" $TERMUX_PACKAGES_DIRECTORIES || echo "ERROR") } echo "INFO: Running update for: $*" @@ -367,7 +375,7 @@ _gh_create_new_issue() { fi # Extract origin URL, commit hash and builder directory and put everything together - link="$(git config --get remote.origin.url |sed -E 's|\.git$||; s|git@([^:]+):(.+)|https://\1/\2|')/blob/$(git rev-parse HEAD)/$(echo */$1)" + link="$(git config --get remote.origin.url | sed -E 's|\.git$||; s|git@([^:]+):(.+)|https://\1/\2|')/blob/$(git rev-parse HEAD)/$(echo */"$1")" body="$( cat <<-EOF