anchor.diff:  endlocal & SET %~1=%OUTPUT%
   GOTO :EOF
   :CANONICALIZE_PATH_INNER
  -if "%~3" NEQ "" (pushd %~3 || GOTO :EOF)
  +if "%~3" NEQ "" (pushd %3 || GOTO :EOF)
   SET OUTPUT=%~f2
  -if "%~3" NEQ "" popd %~3
  -GOTO :EOF
  +if "%~3" NEQ "" popd
  +GOTO :EOF
  +
  +:DIFF_TIME
  +@REM Calculates elapsed time between two timestamps (TIME environment variable format)
  +@REM %1 - Output variable
  +@REM %2 - Start time
  +@REM %3 - End time
  +setlocal EnableDelayedExpansion
  +set START_ARG=%2
  +set END_ARG=%3
  +set END=!END_ARG:%TIME:~8,1%=%%100)*100+1!
  +set START=!START_ARG:%TIME:~8,1%=%%100)*100+1!
  +set /A DIFF=((((10!END:%TIME:~2,1%=%%100)*60+1!%%100)-((((10!START:%TIME:~2,1%=%%100)*60+1!%%100), DIFF-=(DIFF^>^>31)*24*60*60*100
  +set /A CC=DIFF%%100+100,DIFF/=100,SS=DIFF%%60+100,DIFF/=60,MM=DIFF%%60+100,HH=DIFF/60+100
  +@endlocal & set %1=%HH:~1%%TIME:~2,1%%MM:~1%%TIME:~2,1%%SS:~1%%TIME:~8,1%%CC:~1%
  +@GOTO :EOF
  +
  +:WRITE_CUSTOM_SCRIPT_SKELETON
  +@REM Writes the following text to the supplied file
  +@REM %1 - Output filename
  +setlocal
  +@(
  +ECHO @ECHO.
  +ECHO @ECHO ********************************************************************************
  +ECHO @ECHO ** This is a custom run script skeleton.
  +ECHO @ECHO ********************************************************************************
  +ECHO @ECHO.
  +ECHO @ECHO ********************************************************************************
  +ECHO @ECHO ** The working directory is:
  +ECHO @ECHO ********************************************************************************
  +ECHO dir
  +ECHO @ECHO.
  +ECHO @ECHO ********************************************************************************
  +ECHO @ECHO ** The environment is:
  +ECHO @ECHO ********************************************************************************
  +ECHO set
  +ECHO @ECHO.
  +ECHO @ECHO ********************************************************************************
  +ECHO @ECHO ** Edit or replace this script to run custom steps after a successful build:
  +ECHO @ECHO ** %~1
  +ECHO @ECHO ********************************************************************************
  +ECHO @ECHO.
  +) > "%~1"
  +endlocal
  +GOTO :EOF
  
positive.code: :MAKE_OR_CLEAN_DIRECTORY
  @REM Create directory if it doesn't exist or clean it if it does
  @REM %1 - Directory path to clean or create
  setlocal disableDelayedExpansion
  IF NOT EXIST "%~1" (
      ECHO Creating %~1
      mkdir "%~1" && GOTO :EOF
  )
  ECHO Cleaning %~1 ...
  for /F "usebackq delims=" %%I in (`dir /a /b "%~1"`) do (
      (rmdir /s /q  "%~1\%%I" 2>nul ) || del /q /f "%~1\%%I")
  GOTO :EOF
  
  :TOLOWER
  
negative.code: )
  
  REM Validate arguments
  SET PS_ASK_TO_CONTINUE=
  CALL :TOLOWER PS_ARCH
  SET PS_ARCH=%PS_ARCH:amd64=x64%
  CALL :PARSE_OPTION_VALUE %PS_CONFIG_LIST:;= % PS_CONFIG
  IF "%PS_CONFIG%" EQU "" GOTO :HELP
  REM RESOLVE_DESTDIR_CACHE must go after PS_ARCH and PS_CONFIG, but before PS STEPS
  CALL :RESOLVE_DESTDIR_CACHE
  IF "%PS_STEPS%" EQU "" SET PS_STEPS=%PS_STEPS_DEFAULT%
  CALL :PARSE_OPTION_VALUE "all all-dirty deps-dirty deps app-dirty app app-cmake" PS_STEPS
  IF "%PS_STEPS%" EQU "" GOTO :HELP
  (echo %PS_STEPS%)| findstr /I /C:"dirty">nul && SET PS_STEPS_DIRTY=1 || SET PS_STEPS_DIRTY=
  IF "%PS_STEPS%" EQU "app-cmake" SET PS_STEPS_DIRTY=1
  IF "%PS_DESTDIR%" EQU "" SET PS_DESTDIR=%PS_DESTDIR_CACHED%
  IF "%PS_DESTDIR%" EQU "" (
      @ECHO ERROR: Parameter required: -DESTDIR 1>&2
      GOTO :HELP
  )
  CALL :CANONICALIZE_PATH PS_DESTDIR "%PS_START_DIR%"
  IF "%PS_DESTDIR%" NEQ "%PS_DESTDIR_CACHED%" (
      (echo "all deps all-dirty deps-dirty")| findstr /I /C:"%PS_STEPS%">nul || (
          IF EXIST "%PS_DESTDIR%" (
              @ECHO WARNING: DESTDIR does not match cache: 1>&2
              @ECHO WARNING:  new: %PS_DESTDIR% 1>&2
              @ECHO WARNING:  old: %PS_DESTDIR_CACHED% 1>&2
              SET PS_ASK_TO_CONTINUE=1
          ) ELSE (
              @ECHO ERROR: Invalid parameter: DESTDIR=%PS_DESTDIR% 1>&2
              GOTO :HELP
          )
      )
  )
  SET PS_DESTDIR_DEFAULT_MSG=
  CALL :PARSE_OPTION_VALUE "console custom ide none viewer window" PS_RUN
  IF "%PS_RUN%" EQU "" GOTO :HELP
  IF "%PS_RUN%" NEQ "none" IF "%PS_STEPS:~0,4%" EQU "deps" (
      @ECHO ERROR: RUN=%PS_RUN% specified with STEPS=%PS_STEPS%
      @ECHO ERROR: RUN=none is the only valid option for STEPS "deps" or "deps-dirty"
      GOTO :HELP
  )
  REM Give the user a chance to cancel if we found something odd.
  IF "%PS_ASK_TO_CONTINUE%" EQU "" GOTO :BUILD_ENV
  @ECHO.
  @ECHO Unexpected parameters detected. Build paused for %PS_CHOICE_TIMEOUT% seconds.
  choice /T %PS_CHOICE_TIMEOUT% /C YN /D N /M "Continue"
  IF %ERRORLEVEL% NEQ 1 GOTO :HELP
  
  REM Set up MSVC environment
  :BUILD_ENV
  SET EXIT_STATUS=2
  SET PS_CURRENT_STEP=environment
  @ECHO **********************************************************************
  @ECHO ** Build Config: %PS_CONFIG%
  @ECHO ** Target Arch:  %PS_ARCH%
  @ECHO ** Build Steps:  %PS_STEPS%
  @ECHO ** Run App:      %PS_RUN%
  @ECHO ** Deps path:    %PS_DESTDIR%
  @ECHO ** Using Microsoft Visual Studio installation found at:
  SET VSWHERE=%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe
  IF NOT EXIST "%VSWHERE%" SET VSWHERE=%ProgramFiles%\Microsoft Visual Studio\Installer\vswhere.exe
  FOR /F "tokens=* USEBACKQ" %%I IN (`"%VSWHERE%" -nologo -property installationPath`) DO SET MSVC_DIR=%%I
  @ECHO **  %MSVC_DIR%
  CALL "%MSVC_DIR%\Common7\Tools\vsdevcmd.bat" -arch=%PS_ARCH% -host_arch=%PS_ARCH_HOST% -app_platform=Desktop
  IF %ERRORLEVEL% NEQ 0 GOTO :END
  REM Need to reset the echo state after vsdevcmd.bat clobbers it.
  @IF "%PS_ECHO_ON%" NEQ "" (echo on) ELSE (echo off)
  IF "%PS_DRY_RUN_ONLY%" NEQ "" (
      @ECHO Script terminated early because PS_DRY_RUN_ONLY is set. 1>&2
      GOTO :END
  