]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Script cleanup
authorDr. Jaska <drjaska83@gmail.com>
Mon, 22 Jul 2024 20:44:12 +0000 (20:44 +0000)
committerDr. Jaska <drjaska83@gmail.com>
Mon, 22 Jul 2024 20:44:12 +0000 (20:44 +0000)
qcsrc/Makefile
qcsrc/tools/compilationunits.sh
qcsrc/tools/qcc.sh
qcsrc/tools/sv_game-hashtest.sh

index ee9e7e64ab9c6e6016fd362b3e2faca5a801b369..ae9a8e61c02d358780b3afcfe2cabbc99d4a3438 100644 (file)
@@ -6,12 +6,6 @@ WORKDIR ?= ../.tmp
 
 QCCFLAGS_WATERMARK ?= $(shell git describe --tags --dirty='~')
 VER = $(subst *,\*,$(QCCFLAGS_WATERMARK))
-NDEBUG ?= 1
-XONOTIC ?= 1
-ENABLE_EFFECTINFO ?= 0
-ENABLE_DEBUGDRAW ?= 0
-ENABLE_DEBUGTRACE ?= 0
-BUILD_MOD ?=
 
 ifndef ZIP
        ifneq ($(shell which zip 2>/dev/null),)
@@ -23,42 +17,12 @@ ifndef ZIP
        ifneq ($(shell which 7za 2>/dev/null),)
                ZIP := 7za a -tzip -mx=9 -sdel
        endif
-    ifndef ZIP
-        $(warning "No zip / 7z / 7za in ($(PATH))")
-        ZIP := : zip_not_found
-    endif
+       ifndef ZIP
+               $(warning "No zip / 7z / 7za in ($(PATH))")
+               ZIP := : zip_not_found
+       endif
 endif
 
-# Set to empty string to temporarily enable warnings when debugging
-QCCFLAGS_WERROR ?= \
-       -Werror
-
-# We eventually need to get rid of these
-QCCFLAGS_WTFS ?= \
-       -Wno-field-redeclared
-
-QCCDEFS ?= \
-       -DXONOTIC=$(XONOTIC) \
-       -DWATERMARK="$(QCCFLAGS_WATERMARK)" \
-       -DNDEBUG=$(NDEBUG) \
-       -DENABLE_EFFECTINFO=$(ENABLE_EFFECTINFO) \
-       -DENABLE_DEBUGDRAW=$(ENABLE_DEBUGDRAW) \
-       -DENABLE_DEBUGTRACE=$(ENABLE_DEBUGTRACE) \
-       $(if $(BUILD_MOD), -DBUILD_MOD="$(BUILD_MOD)" -I$(BUILD_MOD), ) \
-       $(QCCDEFS_EXTRA)
-
-# -Ooverlap-locals is required
-QCCFLAGS ?= \
-       -std=gmqcc \
-       -Ooverlap-locals \
-       -O3 \
-       $(QCCFLAGS_WERROR) \
-       -Wall \
-       $(QCCFLAGS_WTFS) \
-       -flno -futf8 -fno-bail-on-werror \
-       -frelaxed-switch -freturn-assignments \
-       $(QCCFLAGS_EXTRA)
-
 
 
 .PHONY: all
@@ -126,8 +90,6 @@ $(QCCVERSIONFILE): | $(WORKDIR)
 export WORKDIR
 export CPP
 export QCC
-export QCCDEFS
-export QCCFLAGS
 
 $(PROGS_OUT)/csprogs.dat: client/progs.inc $(QCCVERSIONFILE) | $(WORKDIR)
        @ echo make[1]: Entering directory \`$(CURDIR)/client\'
index d13cb6e091e8f2dd9e350f78e25fc30f7de33d35..5a74c6919416f2ef027c1330df44f8718a133282 100755 (executable)
@@ -1,7 +1,8 @@
 #!/usr/bin/env bash
-[ -z "$QCCFLAGS_WATERMARK" ] && export QCCFLAGS_WATERMARK=$(git describe --tags --dirty='~')
+
 set -eu
-cd ${0%/*}
+
+cd "$(realpath "$(dirname "$0")")"
 
 # This script attempts to build the codebase in every possible header configuration,
 # to check that all files #include what they need, so that we can eventually move away
@@ -10,83 +11,64 @@ cd ${0%/*}
 # If these files exist from previous compilation, `./all compile` will stop
 # detecting changes after running this script so delete them to trigger
 # a recompile next time.
-if [ -f ../../csprogs.dat ]; then
-    rm ../../csprogs.dat
-fi
+[ -f ../../csprogs.dat ] && rm ../../csprogs.dat
+[ -f ../../menu.dat    ] && rm ../../menu.dat
+[ -f ../../progs.dat   ] && rm ../../progs.dat
 
-if [ -f ../../menu.dat ]; then
-    rm ../../menu.dat
-fi
-
-if [ -f ../../progs.dat ]; then
-    rm ../../progs.dat
-fi
+CPP="cc -xc -E"
 
-WORKDIR=../.tmp
+[ -z "${QCC-}" ] && \
+       export QCC="$PWD/../../../../gmqcc/gmqcc"
 
-CPP="cc -xc -E"
-: ${QCC:=$PWD/../../../../gmqcc/gmqcc}
+# when used does this lead to .tmp or qcsrc/.tmp ?? both?
+export WORKDIR=../.tmp
 
-declare -a QCCDEFS=(
-    -DNDEBUG=1
-    -DXONOTIC=1
-    -DWATERMARK="\"$QCCFLAGS_WATERMARK\""
-    -DENABLE_EFFECTINFO=0
-    -DENABLE_DEBUGDRAW=0
-    -DENABLE_DEBUGTRACE=0
-)
-QCCDEFS="${QCCDEFS[@]}"
+# source additional functions and variables for compiling
+. qcc.sh
 
-declare -a QCCFLAGS=(
-    -std=gmqcc
-    # Without -O3, GMQCC thinks some variables are used uninitialized if the initialization is done inside an `if (1)` block
-    # (which is created by e.g. BEGIN_MACRO) which would cause the compilation units test to fail.
-    # There doesn't appear to be any measurable increase in compile time
-    # and it allows us to get rid of some explicit initializations which are just useless noise.
-    -O3
-    -Wall -Werror
-    -futf8
-    -freturn-assignments
-    -frelaxed-switch
-    -Ooverlap-locals
-)
 declare -a NOWARN=(
-    -Wno-field-redeclared
-    -Wno-unused-variable
-    -Wno-implicit-function-pointer
-    -Wno-missing-return-values
+       # -Wno-field-redeclared is included via WTFS by default
+       -Wno-unused-variable
+       -Wno-implicit-function-pointer
+       -Wno-missing-return-values
 )
-QCCFLAGS="${QCCFLAGS[@]} ${NOWARN[@]}"
+QCCFLAGS+=("${NOWARN[@]}")
 
-. qcc.sh
+# move to qcsrc
 cd ..
 
 function check1() {
-    declare -l prog="${1}"
-    declare -l file="${2}"
-    MODE=${prog}
-    includes="-include lib/_all.inc"
-    [ -f ${prog}/_all.qh ] && includes="${includes} -include ${prog}/_all.qh"
-    qpp ${file} test-${prog}.dat \
-            ${includes} \
-            -I. ${QCCIDENT} ${QCCDEFS} > ${WORKDIR}/${prog}.qc
-    qcc ${QCCFLAGS} -o ../${WORKDIR}/test-${prog}.dat ../${WORKDIR}/${prog}.qc >/dev/null
+       declare -l prog="$1"
+       declare -l file="$2"
+       export MODE="$prog"
+
+       declare -a includes=("-include" "lib/_all.inc")
+       [ -f "$prog/_all.qh" ] && includes+=("-include $prog/_all.qh")
+
+       qpp "$file" "test-$prog.dat" \
+               "${includes[@]}" \
+               -I. "$QCCIDENT" "${QCCDEFS[@]}" > "$WORKDIR/$prog.qc"
+       qcc "${QCCFLAGS[@]}" -o "../$WORKDIR/test-$prog.dat" "../$WORKDIR/$prog.qc" >/dev/null
 }
 
 function check() {
-    declare -l prog="${1}"
-    find ${prog} -type f -name '*.qc' -print0 | sort -z | while read -r -d '' file; do
-        check1 ${prog} ${file}
-    done
+       declare -l prog="$1"
+       find "$prog" -type f -name '*.qc' -print0 | sort -z | while read -r -d '' file
+       do
+               check1 "$prog" "$file"
+       done
 }
 
-if [ ${#@} -eq 0 ]; then
-    check client
-    check server
-    check menu
-else
-    for var in ${@}; do
-        var=${var#test-}
-        check ${var}
-    done
+# check argument array length
+if [ "${#@}" = "0" ]
+then # no args, run all checks
+       check client
+       check server
+       check menu
+else # run a specific check
+       for var in "$@"
+       do
+               var="${var#test-}"
+               check "$var"
+       done
 fi
index dfc375bb5a984fab52d12b4720c62b2e7e70c225..4b650862ab9029ccdc6d04904f2438b1496cf095 100755 (executable)
 #!/usr/bin/env bash
+
 set -euo pipefail
 IFS=$' \n\t'
 
-WORKDIR=${WORKDIR}
-CPP=${CPP}
-QCC=${QCC}
+# check that we have all necessary env vars
+if [ -z "${WORKDIR-}" ] \
+|| [ -z "${CPP-}" ] \
+|| [ -z "${QCC-}" ]
+then
+       printf "%s: Necessary env vars were not set\n" \
+               "${BASH_SOURCE[0]}" > /dev/stderr
+       exit 1
+fi
+
+# make sure to initialize these variables,
+# give them default values if they are valueless
+NDEBUG="${NDEBUG:-1}"
+XONOTIC="${XONOTIC:-1}"
+QCCFLAGS_WATERMARK="${QCCFLAGS_WATERMARK:-"$(git describe --tags --dirty='~')"}"
+ENABLE_EFFECTINFO="${ENABLE_EFFECTINFO:-0}"
+ENABLE_DEBUGDRAW="${ENABLE_DEBUGDRAW:-0}"
+ENABLE_DEBUGTRACE="${ENABLE_DEBUGTRACE:-0}"
+
 QCCIDENT="-DGMQCC"
-QCCDEFS=${QCCDEFS}
-QCCFLAGS=${QCCFLAGS}
+
+# {{{ QCCDEFS
+
+declare -a QCCDEFS=(
+       -DNDEBUG="$NDEBUG"
+       -DXONOTIC="$XONOTIC"
+       -DWATERMARK="\"$QCCFLAGS_WATERMARK\""
+       -DENABLE_EFFECTINFO="$ENABLE_EFFECTINFO"
+       -DENABLE_DEBUGDRAW="$ENABLE_DEBUGDRAW"
+       -DENABLE_DEBUGTRACE="$ENABLE_DEBUGTRACE"
+)
+if [ -n "${BUILD_MOD-}" ]
+then
+       QCCDEFS+=(
+               -DBUILD_MOD=\""$BUILD_MOD"\"
+               -I"$BUILD_MOD"
+       )
+fi
+for extradef in ${QCCDEFS_EXTRA-}
+do
+       QCCDEFS+=("$extradef")
+done
+
+# }}}
+
+# {{{ QCCFLAGS
+
+# Set to empty string to temporarily enable warnings when debugging
+for flag in ${QCCFLAGS_WERROR-'-Werror'}
+do
+       QCCFLAGS_WERROR+=("$flag")
+done
+
+# We eventually need to get rid of these
+for flag in ${QCCFLAGS_WTFS-'-Wno-field-redeclared'}
+do
+       QCCFLAGS_WTFS+=("$flag")
+done
+
+declare -a QCCFLAGS=(
+       -std=gmqcc
+       # Without -O3, GMQCC thinks some variables are used uninitialized if the initialization is done inside an `if (1)` block
+       # (which is created by e.g. BEGIN_MACRO) which would cause the compilation units test to fail.
+       # There doesn't appear to be any measurable increase in compile time
+       # and it allows us to get rid of some explicit initializations which are just useless noise.
+       -O3
+       "${QCCFLAGS_WERROR[@]}"
+       -Wall
+       "${QCCFLAGS_WTFS[@]}"
+       -futf8
+       -freturn-assignments
+       -frelaxed-switch
+       # -Ooverlap-locals is required
+       -Ooverlap-locals
+)
+
+for extraflag in ${QCCFLAGS_EXTRA-}
+do
+       QCCFLAGS+=("$extraflag")
+done
+
+# }}}
 
 function qpp() {
-    IN=$1
-    OUT=$2
-    case ${MODE} in
-        client) DEFS="-DGAMEQC -DCSQC"
-        ;;
-        menu) DEFS="-DMENUQC"
-        ;;
-        server) DEFS="-DGAMEQC -DSVQC"
-        ;;
-    esac
-    #>&2 echo + ${CPP} "${@:3}" ${DEFS} "${IN}"
-    set +e
-    # additional information
-    ${CPP} "${@:3}" ${DEFS} \
-        -dM 1>"${WORKDIR}/${MODE}_macros.txt" \
-        -H 2>"${WORKDIR}/${MODE}_includes.txt" \
-        "${IN}"
-    # main step
-    ${CPP} "${@:3}" ${DEFS} -MMD -MP -MT "${OUT}" -Wall -Wundef -Werror "${IN}" -o "${WORKDIR}/${MODE}.txt"
-    err=$?
-    set -e
-    if [ ${err} -ne 0 ]; then return ${err}; fi
-    sed -E 's/^#(line)? ([[:digit:]]+) "(.*)".*/'$'\\\n''#pragma file(\3)'$'\\\n''#pragma line(\2)/g' "${WORKDIR}/${MODE}.txt"
+       IN="$1"
+       OUT="$2"
+       case "$MODE" in
+               client)
+                       DEFS=("-DGAMEQC" "-DCSQC")
+                       ;;
+               menu)
+                       DEFS=("-DMENUQC")
+                       ;;
+               server)
+                       DEFS=("-DGAMEQC" "-DSVQC")
+                       ;;
+       esac
+
+       #>&2 echo + $CPP "${@:3}" "${DEFS[@]}" "$IN"
+
+       # don't exit from additional info step
+       set +e
+
+       # additional information
+       $CPP "${@:3}" "${DEFS[@]}" \
+               -dM 1>"$WORKDIR/${MODE}_macros.txt" \
+               -H 2>"$WORKDIR/${MODE}_includes.txt" \
+               "$IN"
+
+       # main step
+       $CPP "${@:3}" "${DEFS[@]}" -MMD -MP -MT "$OUT" -Wall -Wundef -Werror "$IN" -o "$WORKDIR/$MODE.txt"
+
+       err=$?
+
+       # exit with error code if main step gave one
+       [ "$err" != "0" ] && return "$err"
+
+       set -e
+
+       # TODO: document what this does
+       sed -E 's/^#(line)? ([[:digit:]]+) "(.*)".*/'$'\\\n''#pragma file(\3)'$'\\\n''#pragma line(\2)/g' "$WORKDIR/$MODE.txt"
 }
 
 function qcc() {
-    #>&2 echo + $(basename ${QCC}) $@
-    # FIXME: relative compiler path is too deep
-    (cd tools && ${QCC} "$@")
-}
+       #>&2 echo + $(basename $QCC) $@
 
-$(return >/dev/null 2>&1) || {
-    MODE=$1
-    OUT=$2
-    IN=$3
-    case "${OUT}" in
-      /*)
-        OUT_ABSOLUTE=${OUT}
-        ;;
-      *)
-        OUT_ABSOLUTE=${PWD}/${OUT}
-        ;;
-    esac
-    set -x
-    qpp "${IN}" "${OUT}" -I. ${QCCIDENT} ${QCCDEFS} > "${WORKDIR}/${MODE}.qc"
-    qcc ${QCCFLAGS} -o "${OUT_ABSOLUTE}" "../${WORKDIR}/${MODE}.qc"
+       # FIXME: relative compiler path is too deep
+       (cd tools && $QCC "$@")
 }
+
+# Driver code which is not ran if this file is sourced from elsewhere.
+# If it is not sourced then the driver code block is executed.
+# If it is sourced from elsewher then the driver code bock
+# is not executed and this file gives the above functions.
+#
+# Bashism: if this script file is the main executing program
+if [[ "${BASH_SOURCE[0]}" == "$0" ]]
+then
+       MODE="$1"
+       OUT="$2"
+       IN="$3"
+       case "$OUT" in
+       /*)
+               OUT_ABSOLUTE="$OUT"
+               ;;
+       *)
+               OUT_ABSOLUTE="$PWD/$OUT"
+               ;;
+       esac
+
+       QCCFLAGS+=(
+               -flno
+               -fno-bail-on-werror
+       )
+
+       set -x
+       qpp "$IN" "$OUT" -I. "$QCCIDENT" "${QCCDEFS[@]}" > "$WORKDIR/$MODE.qc"
+       qcc "${QCCFLAGS[@]}" -o "$OUT_ABSOLUTE" "../$WORKDIR/$MODE.qc"
+fi
index 431a6f7c1636f80cd750cb7469d48193366b1c70..980f1265ec07a83f7669c15c2d61fa773b000bfa 100755 (executable)
@@ -23,7 +23,6 @@ command -V md5sum    > /dev/null
 command -V mkdir     > /dev/null
 command -V mktemp    > /dev/null
 command -V rm        > /dev/null
-command -V rmdir     > /dev/null
 command -V sed       > /dev/null
 command -V tee       > /dev/null
 command -V test      > /dev/null
@@ -55,22 +54,22 @@ hashtestcleanup() {
        # Few files' removal has been disabled for file reuse
        # It's possible to get rate limited with enough testing
 
-       rm lock
-       rm data/darkplaces_history.txt
-       rm data/xonotic-data.pk3dir
-       #rm data/stormkeep.pk3
-       rm data/data/defaultSVQC.cfg
-       rm data/data/hits---1.plot
-       rm data/data/hits---2.plot
-       rm data/data/hits---3.plot
-       rm data/data/notifications_dump.cfg
-       rm data/data/server.db
-       rmdir data/data/
-       #rm data/maps/_init.bsp
-       #rm data/maps/stormkeep.mapinfo
-       #rm data/maps/stormkeep.waypoints
-       #rm data/maps/stormkeep.waypoints.cache
-       #rmdir data/maps/
+       rm -fv lock
+       rm -fv data/darkplaces_history.txt
+       rm -fv data/xonotic-data.pk3dir
+       #rm -fv data/stormkeep.pk3
+       rm -fv data/data/defaultSVQC.cfg
+       rm -fv data/data/hits---1.plot
+       rm -fv data/data/hits---2.plot
+       rm -fv data/data/hits---3.plot
+       rm -fv data/data/notifications_dump.cfg
+       rm -fv data/data/server.db
+       rm -dfv data/data/
+       #rm -fv data/maps/_init.bsp
+       #rm -fv data/maps/stormkeep.mapinfo
+       #rm -fv data/maps/stormkeep.waypoints
+       #rm -fv data/maps/stormkeep.waypoints.cache
+       #rm -dfv data/maps/
 
        set -e
 }
@@ -90,7 +89,7 @@ then # file exists
        then # file exists but it's not a symlink, replace it
                if [ -d data/xonotic-data.pk3dir ]
                then # it's a dir
-                       rmdir data/xonotic-data.pk3dir
+                       rm -dfv data/xonotic-data.pk3dir
                        ln -s "$PWD" data/xonotic-data.pk3dir
                else # it's not a dir
                        rm data/xonotic-data.pk3dir
@@ -206,13 +205,11 @@ createdtoday "data/maps/stormkeep.waypoints" \
 createdtoday "data/maps/stormkeep.waypoints.cache" \
        || wget -nv -O data/maps/stormkeep.waypoints.cache https://gitlab.com/xonotic/xonotic-maps.pk3dir/raw/master/maps/stormkeep.waypoints.cache
 
-set +u
-if [ -z "$EXPECT" ]
+if [ -z "${EXPECT-}" ]
 then
        # find the line with expected hash from .gitlab-ci.yml, extract the hash and remove carriage return
        EXPECT="$(grep 'EXPECT=' './.gitlab-ci.yml' | cut -d '=' -f 2 | tr -d $'\r')"
 fi
-set -u
 HASH=$(${ENGINE} +exec serverbench.cfg \
       | tee /dev/stderr \
       | grep '^:' \