From: otta8634 Date: Sat, 1 Mar 2025 11:09:08 +0000 (+0800) Subject: Update check-cvars.sh to only disallow changing extra settings in custom balance... X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=d0ceeac635f9b9f55a2326cb9c242e7c25e5a20d;p=xonotic%2Fxonotic-data.pk3dir.git Update check-cvars.sh to only disallow changing extra settings in custom balance files Now custom balance files like balance-overkill.cfg don't have to change every single cvar balance-xonotic.cfg does, so that the same defaults don't need to repeated for every single balance file. The only requirement now is that balance-overkill.cfg can't set any cvars which aren't also set in balance-xonotic.cfg. Additionally balance files can't set cvars with the wrong prefix (like cl_ or r_), and likewise hud files can't set cvars with prefixes other than hud_ or _hud_. This doesn't apply to the hud cfg files, since they're compared against _hud_descriptions.cfg, which doesn't set defaults, so they must do it themselves. Changes weren't made to the cfg files in question yet. --- diff --git a/check-cvars.sh b/check-cvars.sh index 387d93720..277d67f45 100755 --- a/check-cvars.sh +++ b/check-cvars.sh @@ -2,38 +2,102 @@ errord=false -check_files() +# Make sure the config file doesn't set cvars with the wrong prefix +correct_prefixes() { - countw=`awk ''"$3"' { print $2; }' "$1" | sort -u | tr -d '\r' | git hash-object --stdin | cut -c 1-32` - for b in $2; do - if [ "$b" = "balance-testing.cfg" ] || [ "$b" = "balance-testingxpm.cfg" ]; then - continue - fi + local allRegex="$1" + local validRegex="$2" + local configFile="$3" + local tmpFile="$4" + + awk ''"$allRegex"' && !'"$validRegex"' { print $2; }' "$configFile" | tr -d '\r' | sort -u > "$tmpFile" + if [ -s "$tmpFile" ] + then + printf "\033[31m%s\033[0m\n" "Invalid cvars changed in $configFile. Aborting." + echo "The following cvars are in $configFile but shouldn't be there:" + diff /dev/null "$tmpFile" | grep "^>" + echo + errord=true + fi +} + +# Make sure the files set the same cvars, or the custom doesn't set any which the default doesn't +correct_cvars() +{ + local validRegex="$1" + local customFile="$2" + local defaultFile="$3" + local mustSetAll="$4" + local A="$5" + local B="$6" - countb=`awk ''"$3"' { print $2; }' "$b" | sort -u | tr -d '\r' | git hash-object --stdin | cut -c 1-32` - if [ "$countw" != "$countb" ]; then - echo "Mismatch between $1 and $b. Aborting." + awk ''"$validRegex"' { print $2; }' "$defaultFile" | tr -d '\r' | sort -u > "$A" + awk ''"$validRegex"' { print $2; }' "$customFile" | tr -d '\r' | sort -u > "$B" + extra="" + if $mustSetAll + then + # Files must change identical cvars, extract all differences + extra="$(diff "$A" "$B" | grep "^[<>]")" + else + # Only extract cvars that are in $customFile but not $defaultFile + # $customFile is allowed to override $defaultFile, but not change anything else + extra="$(diff "$A" "$B" | grep "^>")" + fi + if [ "$extra" != "" ] + then + printf "\033[31m%s\033[0m\n" "Cvar mismatch between $defaultFile and $customFile. Aborting." + if $mustSetAll + then echo "Differences are:" - echo "< missing in $b" - echo "> must get removed from $b" - A=`mktemp || echo a.tmp` - B=`mktemp || echo b.tmp` - awk ''"$3"' { print $2; }' "$1" | sort -u | tr -d '\r' > "$A" - awk ''"$3"' { print $2; }' "$b" | sort -u | tr -d '\r' > "$B" - diff "$A" "$B" | grep '^[<>]' | sort - rm -f "$A" "$B" - errord=true + echo "< missing in $customFile" + echo "> must be removed from $customFile" + else + echo "The following cvars are missing from $defaultFile, so must be either added to $defaultFile or more likely removed from $customFile:" + fi + echo "$extra" + echo + errord=true + fi +} + +check_files() +{ + local defaultFile="$1" + local customFiles="$2" + local validRegex="$3" + local allRegex="$4" + local mustSetAll="$5" + + A="$(mktemp || echo a.tmp)" + B="$(mktemp || echo b.tmp)" + + # First check defaultFile + correct_prefixes "$allRegex" "$validRegex" "$defaultFile" "$A" + + # Now compare defaultFile to the customFiles + for customFile in $customFiles + do + if [ "$customFile" = "balance-testing.cfg" ] \ + || [ "$customFile" = "balance-testingxpm.cfg" ] \ + || [ "$customFile" = "$defaultFile" ] + then + continue fi + correct_prefixes "$allRegex" "$validRegex" "$customFile" "$B" + correct_cvars "$validRegex" "$customFile" "$defaultFile" "$mustSetAll" "$A" "$B" done + rm -f "$A" "$B" } -check_files "balance-xonotic.cfg" "balance-*.cfg" "/^seta? g_/" -check_files "bal-wep-xonotic.cfg" "bal-wep-*.cfg" "/^seta? g_/" -check_files "_hud_descriptions.cfg" "hud_*.cfg" "/^seta? hud_/" +check_files "balance-xonotic.cfg" "balance-*.cfg" "/^seta? +g_/" "/^seta? +/" false +check_files "bal-wep-xonotic.cfg" "bal-wep-*.cfg" "/^seta? +g_/" "/^seta? +/" false +check_files "_hud_descriptions.cfg" "hud_*.cfg" "/^seta? +_?hud_/" "/^seta? +/" true -if $errord; then - if [ "$CMAKE" != "" ]; then - exit 1 +if $errord +then + if [ "$CMAKE" != "" ] + then + exit 1 fi echo "Please wait for 30 seconds, so you have had enough time to read this..." sleep 30