From 259768e8969d5831be9d4c97462c86f667133254 Mon Sep 17 00:00:00 2001 From: Megamouse Date: Tue, 15 Apr 2025 00:33:50 +0200 Subject: [PATCH] Add submodule version check script --- 3rdparty/version_check.sh | 115 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 115 insertions(+) create mode 100644 3rdparty/version_check.sh diff --git a/3rdparty/version_check.sh b/3rdparty/version_check.sh new file mode 100644 index 0000000000..2b721fe28f --- /dev/null +++ b/3rdparty/version_check.sh @@ -0,0 +1,115 @@ +#!/bin/sh -ex + +verbose=0 +git_verbose=0 + +if [ "$1" = "-v" ]; then + verbose=1 +elif [ "$1" = "-vv" ]; then + verbose=1 + git_verbose=1 +fi + +max_dir_length=0 +result_dirs=() +result_msgs=() + +git_call() +{ + if [ "$git_verbose" -eq 1 ]; then + eval "git $@" + elif [[ "$1" == "fetch" ]]; then + eval "git $@ >/dev/null 2>&1" + else + eval "git $@ 2>/dev/null" + fi +} + +check_tags() +{ + path=$(echo "$1" | sed 's:/*$::') + + echo "Checking $path" + + git_call fetch --prune --all + + # Get the latest tag (by commit date, not tag name) + tag_list=$(git_call rev-list --tags --max-count=1) + latest_tag=$(git_call describe --tags "$tag_list") + + if [ -n "$latest_tag" ]; then + + # Get the current tag + current_tag=$(git_call describe --tags --abbrev=0) + + if [ -n "$current_tag" ]; then + + if [ "$verbose" -eq 1 ]; then + echo "$path -> latest: $latest_tag, current: $current_tag" + fi + + ts1=$(git_call log -1 --format=%ct $latest_tag) + ts2=$(git_call log -1 --format=%ct $current_tag) + + if (( ts1 > ts2 )); then + if [ "$verbose" -eq 1 ]; then + echo -e "\t $path: latest is newer" + elif [ "$verbose" -eq 0 ]; then + echo "$path -> latest: $latest_tag, current: $current_tag" + fi + + path_length=${#path} + if (( $path_length > $max_dir_length )); then + max_dir_length=$path_length + fi + result_dirs+=("$path") + result_msgs+=("latest: $latest_tag, current: $current_tag") + fi + + elif [ "$verbose" -eq 1 ]; then + echo "$path -> latest: $latest_tag" + fi + elif [ "$verbose" -eq 1 ]; then + + if [ -n "$current_tag" ]; then + echo "$path -> current: $current_tag" + else + echo "$path -> no tags found" + fi + fi +} + +for submoduledir in */ ; +do + cd "$submoduledir" || continue + + if [ -e ".git" ]; then + check_tags "$submoduledir" + else + # find */ -mindepth 1 -maxdepth 1 -type d | while read -r sub; + for sub in */ ; + do + if [ -e "$sub/.git" ]; then + cd "$sub" || continue + check_tags "$submoduledir$sub" + cd .. || exit + fi + done + fi + + cd .. || exit +done + +echo -e "\n\nResult:\n" +i=0 +for result_dir in "${result_dirs[@]}"; do + msg="" + diff=$(($max_dir_length - ${#result_dir})) + if (( $diff > 0 )); then + msg+=$(printf "%${diff}s" "") + fi + msg+="$result_dir" + echo "$msg -> ${result_msgs[$i]}" + ((i++)) +done +echo ""