Update unit test build/run scripts to use build_rive.sh (#10320) 4bd8c63b93
* Update unit test scripts to use build_rive.sh

The unit test test.bat and test.sh were doing their own ad-hoc building instead of using build_rive.  This updates test.sh to call build_rive.sh for the build. This script could probably be pared down further but I did not want to break any of the existing command line arguments that people are probably using.

Additionally, test.bat did not have up-to-date build flags in it, so now it does a similar Windows development environment setup to build_rive.bat and then calls directly into test.sh, so it won't get out of sync with the main script anymore.

* Additional test.sh changes

- There was a block of code that I could have removed but didn't (made redundant by the call to build_rive)
- Add build_rive's parent directory to the path before calling it (will fix the test failing on Linux)
- Removed the `sh` before build_rive.sh as it does not need to be shell invoked.

* The pr_unit_tests.yaml execution for Mac needed to do a clean furing the asan build

because it had already done a build without asan before, the change to build_rive means that we now catch the premake parameter change (adding asan), and so clean needs to happen for that build to be correct.

* For now, move the build_rive.sh call into the two branches that previously had the build calls (linux, for instance, does not build, which seems incorrect given the github workflow is trying to run it.

* Adding a note to test.sh to describe why the build_rive script is called in the way it is (vs. the obvious way)

* Additional unit test script fixes (unifying windows build further, and some warnings)

- Add the ability to specify a toolset on the command line (i.e. "--toolset=msc") that will get passed along to build_rive (thus making the 'clang' toolset in the windows build only a default)
- Update the unit_test_windows and unit_test_windows_msvc entries in the github unit test workflows to call test.bat now (which required combining the build/run steps, but this matches all the other configurations)
- Also added some additional parameter validation, mainly warnings on ignored/unsupported parameters

Co-authored-by: JoshJRive <joshua@rive.app>
diff --git a/.rive_head b/.rive_head
index 4922057..f929ff2 100644
--- a/.rive_head
+++ b/.rive_head
@@ -1 +1 @@
-51f1f66e318727871563949d737f92488728e460
+4bd8c63b93672af82819728be047578d71018049
diff --git a/tests/unit_tests/test.bat b/tests/unit_tests/test.bat
index 58b44cb..f390b5a 100644
--- a/tests/unit_tests/test.bat
+++ b/tests/unit_tests/test.bat
@@ -1,20 +1,9 @@
 @echo off
-call ..\..\dependencies\windows\config_directories.bat
-
-if not exist "%DEPENDENCIES%\bin\premake5.exe" (
-    pushd "%DEPENDENCIES_SCRIPTS%"
-    call .\get_premake5.bat || goto :error
-    popd
+REM use fxc because sometimes msbuild is there but fxc is not. The opposite appears to never be true
+WHERE fxc >nul 2>&1
+IF %ERRORLEVEL% NEQ 0 (
+    call %~p0\..\..\build\setup_windows_dev.bat
 )
+cd %CD%
 
-set "PREMAKE=%DEPENDENCIES%\bin\premake5.exe"
-%PREMAKE% --scripts=..\..\build --no-download-progress --with_rive_tools --with_rive_text --with_rive_audio=external vs2022
-
-MSBuild.exe /?  2> NUL
-if not %ERRORLEVEL%==9009 (
-    set "MSBuild=MSBuild.exe"
-) else (
-    set "MSBuild=%ProgramFiles%\Microsoft Visual Studio\2022\Community\Msbuild\Current\Bin\MSBuild.exe"
-)
-call "%MSBuild%" out\debug\rive.sln
-out\debug\unit_tests.exe
\ No newline at end of file
+sh ./test.sh %*
\ No newline at end of file
diff --git a/tests/unit_tests/test.sh b/tests/unit_tests/test.sh
index 885805a..1edbc36 100755
--- a/tests/unit_tests/test.sh
+++ b/tests/unit_tests/test.sh
@@ -13,6 +13,8 @@
 MATCH=
 COVERAGE=
 EXTRA_CONFIG=
+UTILITY=
+TOOLSET_ARG=
 while [[ $# -gt 0 ]]; do
   case $1 in
   -m | --match)
@@ -21,13 +23,27 @@
     shift # past value
     ;;
   lldb)
-    echo Starting debugger...
-    UTILITY='lldb'
+    if [[ $machine = "windows" ]]; then
+      echo "Warning: Ignoring 'lldb' command-line argument, which does not work on Windows."
+    else
+      echo Starting debugger...
+      if [[ ! -z $UTILITY ]]; then
+        echo "Warning: 'lldb' parameter overrides '$UTILITY' parameter."
+      fi
+      UTILITY='lldb'
+    fi
     shift # past argument
     ;;
   memory)
-    echo Will perform memory checks...
-    UTILITY='leaks --atExit --'
+    if [[ $machine = "macosx" ]]; then
+      echo Will perform memory checks...
+      if [[ ! -z $UTILITY ]]; then
+        echo "Warning: 'memory' parameter overrides '$UTILITY' parameter."
+      fi
+      UTILITY='leaks --atExit --'
+    else
+      echo "Warning: Ignoring 'memory' command-line argument, which only works on Mac."
+    fi
     shift # past argument
     ;;
   asan)
@@ -40,8 +56,12 @@
     shift # past argument
     ;;
   coverage)
-    COVERAGE=true
-    shift #
+    if [[ $machine = "macosx" ]]; then
+      COVERAGE=true
+    else
+      echo "Warning: Ignoring 'coverage' command-line argument, which only works on Mac."
+    fi
+    shift # past argument
     ;;
   rebaseline)
     export REBASELINE_SILVERS=true
@@ -51,68 +71,39 @@
     rm -fR out
     shift # past argument
     ;;
+  --toolset=*)
+    # Windows build specifies a default toolset but allow it to be overridden.
+    echo "Toolset has been specified."
+    TOOLSET_ARG=$1
+    shift
+    ;;
   *)
+    # We could pass any unrecognized arguments through instead of just eating them
+    echo "Warning: unrecognized argument '$1'"
     shift # past argument
     ;;
   esac
 done
 
-if [[ ! -f "dependencies/bin/premake5" ]]; then
-  mkdir -p dependencies/bin
-  pushd dependencies
-  if [[ $machine = "macosx" ]]; then
-    # v5.0.0-beta2 doesn't support apple silicon properly, update the branch
-    # once a stable one is avaialble that supports it
-    git clone --depth 1 --branch v5.0.0-beta3 https://github.com/premake/premake-core.git
-    pushd premake-core
-    git pull --tags
-    git checkout v5.0.0-beta3
-    # note, latest premake is not compatible with our fatal warnings...
-    if [[ $LOCAL_ARCH == "arm64" ]]; then
-      PREMAKE_MAKE_ARCH=ARM
-    else
-      PREMAKE_MAKE_ARCH=x86
-    fi
-    make -f Bootstrap.mak osx PLATFORM=$PREMAKE_MAKE_ARCH
-    cp bin/release/* ../bin
-    popd
-  elif [[ $machine = "windows" ]]; then
-    pushd bin
-    curl https://github.com/premake/premake-core/releases/download/v5.0.0-beta2/premake-5.0.0-beta2-windows.zip -L -o premake_windows.zip
-    unzip premake_windows.zip
-    rm premake_windows.zip
-    popd
-  fi
-  popd
-fi
-
-export PREMAKE=$PWD/dependencies/bin/premake5
-
-mkdir -p out
-
-if [[ $machine = "macosx" ]]; then
-  TARGET=gmake2
-elif [[ $machine = "windows" ]]; then
-  TARGET=vs2022
+if [[ $machine = "windows" ]] && [[ -z $TOOLSET_ARG ]]; then
+  echo "Using default Windows toolset of clang"
+  TOOLSET_ARG="--toolset=clang"
 fi
 
 pushd ../../
 RUNTIME=$PWD
 popd
 
-export PREMAKE_PATH="$RUNTIME/dependencies/export-compile-commands":"$RUNTIME/build":"$PREMAKE_PATH"
-PREMAKE_COMMANDS="--with_rive_text --with_rive_audio=external --with_rive_layout --with_rive_scripting --config=$CONFIG --no_ffp_contract $EXTRA_CONFIG"
+BUILD_RIVE_COMMANDS="$CONFIG --with_rive_tools --with_rive_audio=external --with_rive_scripting --no_ffp_contract $TOOLSET_ARG $EXTRA_CONFIG"
 
-out_dir() {
-  echo "out/$CONFIG"
-}
+OUT_DIR="out/$CONFIG"
+
 if [[ $machine = "macosx" ]]; then
-  OUT_DIR="$(out_dir)"
-  $PREMAKE $TARGET $PREMAKE_COMMANDS --out=$OUT_DIR
-  pushd $OUT_DIR
-  make -j$(($(sysctl -n hw.physicalcpu) + 1))
-  # make
-  popd
+  # Note that the build_rive.sh line is here (and in the windows block) and not outside of this (i.e. it doesn't always run)
+  #  because that is the way this script worked before it was converted to use build_rive.sh. This seems incorrect, but Linux
+  #  for instance currently does not build anything with this script (and the linux build fails on GitHub at PR time at the 
+  #  time of writing this, which is why for now it is this way instead).
+  build_rive.sh $BUILD_RIVE_COMMANDS
   rm -fR silvers/tarnished
   mkdir -p silvers/tarnished
   $UTILITY $OUT_DIR/unit_tests "$MATCH"
@@ -125,19 +116,8 @@
   fi
 
 elif [[ $machine = "windows" ]]; then
-  if [[ -f "$PROGRAMFILES/Microsoft Visual Studio/2022/Enterprise/Msbuild/Current/Bin/MSBuild.exe" ]]; then
-    export MSBUILD="$PROGRAMFILES/Microsoft Visual Studio/2022/Enterprise/Msbuild/Current/Bin/MSBuild.exe"
-  elif [[ -f "$PROGRAMFILES/Microsoft Visual Studio/2022/Community/Msbuild/Current/Bin/MSBuild.exe" ]]; then
-    export MSBUILD="$PROGRAMFILES/Microsoft Visual Studio/2022/Community/Msbuild/Current/Bin/MSBuild.exe"
-  fi
-  OUT_DIR="$(out_dir)"
-  echo $PREMAKE $TARGET $PREMAKE_COMMANDS --out=$OUT_DIR
-  ls -l
-  $PREMAKE $TARGET $PREMAKE_COMMANDS --out=$OUT_DIR
-  pushd $OUT_DIR
-  "$MSBUILD" rive.sln -m:$NUMBER_OF_PROCESSORS
-  popd
+  build_rive.sh $BUILD_RIVE_COMMANDS
   rm -fR silvers/tarnished
   mkdir -p silvers/tarnished
-  $OUT_DIR/unit_tests.exe
+  $UTILITY $OUT_DIR/unit_tests "$MATCH"
 fi