build_win.bat 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452
  1. @setlocal disableDelayedExpansion enableExtensions
  2. @IF "%PS_ECHO_ON%" NEQ "" (echo on) ELSE (echo off)
  3. @GOTO :MAIN
  4. :HELP
  5. @ECHO.
  6. @ECHO Performs initial build or rebuild of the app (build) and deps (build/deps).
  7. @ECHO Default options are determined from build directories and system state.
  8. @ECHO.
  9. @ECHO Usage: build_win [-ARCH ^<arch^>] [-CONFIG ^<config^>] [-DESTDIR ^<directory^>]
  10. @ECHO [-STEPS ^<all^|all-dirty^|app^|app-dirty^|deps^|deps-dirty^>]
  11. @ECHO [-RUN ^<console^|custom^|none^|viewer^|window^>]
  12. @ECHO.
  13. @ECHO -a -ARCH Target processor architecture
  14. @ECHO Default: %PS_ARCH_HOST%
  15. @ECHO -c -CONFIG MSVC project config
  16. @ECHO Default: %PS_CONFIG_DEFAULT%
  17. @ECHO -s -STEPS Performs only the specified build steps:
  18. @ECHO all - clean and build deps and app
  19. @ECHO all-dirty - build deps and app without cleaning
  20. @ECHO app - clean and build main applications
  21. @ECHO app-dirty - build main applications without cleaning
  22. @ECHO deps - clean and build deps
  23. @ECHO deps-dirty - build deps without cleaning
  24. @ECHO Default: %PS_STEPS_DEFAULT%
  25. @ECHO -r -RUN Specifies what to perform at the run step:
  26. @ECHO console - run and wait on prusa-slicer-console.exe
  27. @ECHO custom - run and wait on your custom build/%PS_CUSTOM_RUN_FILE%
  28. @ECHO ide - open project in Visual Studio if not open (no wait)
  29. @ECHO none - run step does nothing
  30. @ECHO viewer - run prusa-gcodeviewer.exe (no wait)
  31. @ECHO window - run prusa-slicer.exe (no wait)
  32. @ECHO Default: none
  33. @ECHO -d -DESTDIR Deps destination directory
  34. @ECHO Warning: Changing destdir path will not delete the old destdir.
  35. @ECHO Default: %PS_DESTDIR_DEFAULT_MSG%
  36. @ECHO.
  37. @ECHO Examples:
  38. @ECHO.
  39. @ECHO Initial build: build_win -d "c:\src\PrusaSlicer-deps"
  40. @ECHO Build post deps change: build_win -s all
  41. @ECHO App dirty build: build_win
  42. @ECHO App dirty build ^& run: build_win -r console
  43. @ECHO All clean build ^& run: build_win -s all -r console -d "deps\build\out_deps"
  44. @ECHO.
  45. GOTO :END
  46. :MAIN
  47. REM Script constants
  48. SET START_TIME=%TIME%
  49. SET PS_START_DIR=%CD%
  50. SET PS_SOLUTION_NAME=PrusaSlicer
  51. SET PS_CHOICE_TIMEOUT=30
  52. SET PS_CUSTOM_RUN_FILE=custom_run.bat
  53. SET PS_DEPS_PATH_FILE_NAME=.DEPS_PATH.txt
  54. SET PS_DEPS_PATH_FILE=%~dp0deps\build\%PS_DEPS_PATH_FILE_NAME%
  55. SET PS_CONFIG_LIST="Debug;MinSizeRel;Release;RelWithDebInfo"
  56. REM Probe build directories and system state for reasonable default arguments
  57. pushd %~dp0
  58. SET PS_CONFIG=RelWithDebInfo
  59. SET PS_ARCH=%PROCESSOR_ARCHITECTURE:amd64=x64%
  60. CALL :TOLOWER PS_ARCH
  61. SET PS_RUN=none
  62. SET PS_DESTDIR=
  63. CALL :RESOLVE_DESTDIR_CACHE
  64. REM Set up parameters used by help menu
  65. SET PS_CONFIG_DEFAULT=%PS_CONFIG%
  66. SET PS_ARCH_HOST=%PS_ARCH%
  67. (echo " -help /help -h /h -? /? ")| findstr /I /C:" %~1 ">nul && GOTO :HELP
  68. REM Parse arguments
  69. SET EXIT_STATUS=1
  70. SET PS_CURRENT_STEP=arguments
  71. SET PARSER_STATE=
  72. SET PARSER_FAIL=
  73. FOR %%I in (%*) DO CALL :PARSE_OPTION "ARCH CONFIG DESTDIR STEPS RUN" PARSER_STATE "%%~I"
  74. IF "%PARSER_FAIL%" NEQ "" (
  75. @ECHO ERROR: Invalid switch: %PARSER_FAIL% 1>&2
  76. GOTO :HELP
  77. )ELSE IF "%PARSER_STATE%" NEQ "" (
  78. @ECHO ERROR: Missing parameter for: %PARSER_STATE% 1>&2
  79. GOTO :HELP
  80. )
  81. REM Validate arguments
  82. SET PS_ASK_TO_CONTINUE=
  83. CALL :TOLOWER PS_ARCH
  84. SET PS_ARCH=%PS_ARCH:amd64=x64%
  85. CALL :PARSE_OPTION_VALUE %PS_CONFIG_LIST:;= % PS_CONFIG
  86. IF "%PS_CONFIG%" EQU "" GOTO :HELP
  87. REM RESOLVE_DESTDIR_CACHE must go after PS_ARCH and PS_CONFIG, but before PS STEPS
  88. CALL :RESOLVE_DESTDIR_CACHE
  89. IF "%PS_STEPS%" EQU "" SET PS_STEPS=%PS_STEPS_DEFAULT%
  90. CALL :PARSE_OPTION_VALUE "all all-dirty deps-dirty deps app-dirty app app-cmake" PS_STEPS
  91. IF "%PS_STEPS%" EQU "" GOTO :HELP
  92. (echo %PS_STEPS%)| findstr /I /C:"dirty">nul && SET PS_STEPS_DIRTY=1 || SET PS_STEPS_DIRTY=
  93. IF "%PS_STEPS%" EQU "app-cmake" SET PS_STEPS_DIRTY=1
  94. IF "%PS_DESTDIR%" EQU "" SET PS_DESTDIR=%PS_DESTDIR_CACHED%
  95. IF "%PS_DESTDIR%" EQU "" (
  96. @ECHO ERROR: Parameter required: -DESTDIR 1>&2
  97. GOTO :HELP
  98. )
  99. CALL :CANONICALIZE_PATH PS_DESTDIR "%PS_START_DIR%"
  100. IF "%PS_DESTDIR%" NEQ "%PS_DESTDIR_CACHED%" (
  101. (echo "all deps all-dirty deps-dirty")| findstr /I /C:"%PS_STEPS%">nul || (
  102. IF EXIST "%PS_DESTDIR%" (
  103. @ECHO WARNING: DESTDIR does not match cache: 1>&2
  104. @ECHO WARNING: new: %PS_DESTDIR% 1>&2
  105. @ECHO WARNING: old: %PS_DESTDIR_CACHED% 1>&2
  106. SET PS_ASK_TO_CONTINUE=1
  107. ) ELSE (
  108. @ECHO ERROR: Invalid parameter: DESTDIR=%PS_DESTDIR% 1>&2
  109. GOTO :HELP
  110. )
  111. )
  112. )
  113. SET PS_DESTDIR_DEFAULT_MSG=
  114. CALL :PARSE_OPTION_VALUE "console custom ide none viewer window" PS_RUN
  115. IF "%PS_RUN%" EQU "" GOTO :HELP
  116. IF "%PS_RUN%" NEQ "none" IF "%PS_STEPS:~0,4%" EQU "deps" (
  117. @ECHO ERROR: RUN=%PS_RUN% specified with STEPS=%PS_STEPS%
  118. @ECHO ERROR: RUN=none is the only valid option for STEPS "deps" or "deps-dirty"
  119. GOTO :HELP
  120. )
  121. REM Give the user a chance to cancel if we found something odd.
  122. IF "%PS_ASK_TO_CONTINUE%" EQU "" GOTO :BUILD_ENV
  123. @ECHO.
  124. @ECHO Unexpected parameters detected. Build paused for %PS_CHOICE_TIMEOUT% seconds.
  125. choice /T %PS_CHOICE_TIMEOUT% /C YN /D N /M "Continue"
  126. IF %ERRORLEVEL% NEQ 1 GOTO :HELP
  127. REM Set up MSVC environment
  128. :BUILD_ENV
  129. SET EXIT_STATUS=2
  130. SET PS_CURRENT_STEP=environment
  131. @ECHO **********************************************************************
  132. @ECHO ** Build Config: %PS_CONFIG%
  133. @ECHO ** Target Arch: %PS_ARCH%
  134. @ECHO ** Build Steps: %PS_STEPS%
  135. @ECHO ** Run App: %PS_RUN%
  136. @ECHO ** Deps path: %PS_DESTDIR%
  137. @ECHO ** Using Microsoft Visual Studio installation found at:
  138. SET VSWHERE=%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe
  139. IF NOT EXIST "%VSWHERE%" SET VSWHERE=%ProgramFiles%\Microsoft Visual Studio\Installer\vswhere.exe
  140. FOR /F "tokens=* USEBACKQ" %%I IN (`"%VSWHERE%" -nologo -property installationPath`) DO SET MSVC_DIR=%%I
  141. @ECHO ** %MSVC_DIR%
  142. CALL "%MSVC_DIR%\Common7\Tools\vsdevcmd.bat" -arch=%PS_ARCH% -host_arch=%PS_ARCH_HOST% -app_platform=Desktop
  143. IF %ERRORLEVEL% NEQ 0 GOTO :END
  144. REM Need to reset the echo state after vsdevcmd.bat clobbers it.
  145. @IF "%PS_ECHO_ON%" NEQ "" (echo on) ELSE (echo off)
  146. IF "%PS_DRY_RUN_ONLY%" NEQ "" (
  147. @ECHO Script terminated early because PS_DRY_RUN_ONLY is set. 1>&2
  148. GOTO :END
  149. )
  150. IF /I "%PS_STEPS:~0,3%" EQU "app" GOTO :BUILD_APP
  151. REM Build deps
  152. :BUILD_DEPS
  153. SET EXIT_STATUS=3
  154. SET PS_CURRENT_STEP=deps
  155. IF "%PS_STEPS_DIRTY%" EQU "" CALL :MAKE_OR_CLEAN_DIRECTORY deps\build "%PS_DEPS_PATH_FILE_NAME%"
  156. cd deps\build || GOTO :END
  157. cmake.exe .. -DDESTDIR="%PS_DESTDIR%" || GOTO :END
  158. (echo %PS_DESTDIR%)> "%PS_DEPS_PATH_FILE%"
  159. msbuild /m ALL_BUILD.vcxproj /p:Configuration=%PS_CONFIG% || GOTO :END
  160. cd ..\..
  161. IF /I "%PS_STEPS:~0,4%" EQU "deps" GOTO :RUN_APP
  162. REM Build app
  163. :BUILD_APP
  164. SET EXIT_STATUS=4
  165. SET PS_CURRENT_STEP=app
  166. IF "%PS_STEPS_DIRTY%" EQU "" CALL :MAKE_OR_CLEAN_DIRECTORY build "%PS_CUSTOM_RUN_FILE%"
  167. cd build || GOTO :END
  168. REM Make sure we have a custom batch file skeleton for the run stage
  169. set PS_CUSTOM_BAT=%PS_CUSTOM_RUN_FILE%
  170. CALL :CANONICALIZE_PATH PS_CUSTOM_BAT
  171. IF NOT EXIST %PS_CUSTOM_BAT% CALL :WRITE_CUSTOM_SCRIPT_SKELETON %PS_CUSTOM_BAT%
  172. SET PS_PROJECT_IS_OPEN=
  173. FOR /F "tokens=2 delims=," %%I in (
  174. 'tasklist /V /FI "IMAGENAME eq devenv.exe " /NH /FO CSV ^| find "%PS_SOLUTION_NAME%"'
  175. ) do SET PS_PROJECT_IS_OPEN=%%~I
  176. cmake.exe .. -DCMAKE_PREFIX_PATH="%PS_DESTDIR%\usr\local" -DCMAKE_CONFIGURATION_TYPES=%PS_CONFIG_LIST% || GOTO :END
  177. REM Skip the build step if we're using the undocumented app-cmake to regenerate the full config from inside devenv
  178. IF "%PS_STEPS%" NEQ "app-cmake" msbuild /m ALL_BUILD.vcxproj /p:Configuration=%PS_CONFIG% || GOTO :END
  179. (echo %PS_DESTDIR%)> "%PS_DEPS_PATH_FILE_FOR_CONFIG%"
  180. REM Run app
  181. :RUN_APP
  182. REM All build steps complete.
  183. CALL :DIFF_TIME ELAPSED_TIME %START_TIME% %TIME%
  184. IF "%PS_CURRENT_STEP%" NEQ "arguments" (
  185. @ECHO.
  186. @ECHO Total Build Time Elapsed %ELAPSED_TIME%
  187. )
  188. SET EXIT_STATUS=5
  189. SET PS_CURRENT_STEP=run
  190. cd src\%PS_CONFIG% || GOTO :END
  191. IF "%PS_RUN%" EQU "none" GOTO :PROLOGUE
  192. SET PS_PROJECT_IS_OPEN=
  193. FOR /F "tokens=2 delims=," %%I in (
  194. 'tasklist /V /FI "IMAGENAME eq devenv.exe " /NH /FO CSV ^| find "%PS_SOLUTION_NAME%"'
  195. ) do SET PS_PROJECT_IS_OPEN=%%~I
  196. @ECHO.
  197. @ECHO Running %PS_RUN% application...
  198. @REM icacls below is just a hack for file-not-found error handling
  199. IF "%PS_RUN%" EQU "console" (
  200. icacls prusa-slicer-console.exe >nul || GOTO :END
  201. start /wait /b prusa-slicer-console.exe
  202. ) ELSE IF "%PS_RUN%" EQU "window" (
  203. icacls prusa-slicer.exe >nul || GOTO :END
  204. start prusa-slicer.exe
  205. ) ELSE IF "%PS_RUN%" EQU "viewer" (
  206. icacls prusa-gcodeviewer.exe >nul || GOTO :END
  207. start prusa-gcodeviewer.exe
  208. ) ELSE IF "%PS_RUN%" EQU "custom" (
  209. icacls %PS_CUSTOM_BAT% >nul || GOTO :END
  210. CALL %PS_CUSTOM_BAT%
  211. ) ELSE IF "%PS_RUN%" EQU "ide" (
  212. IF "%PS_PROJECT_IS_OPEN%" NEQ "" (
  213. @ECHO WARNING: Solution is already open in Visual Studio. Skipping ide run step. 1>&2
  214. ) ELSE (
  215. @ECHO Preparing to run Visual Studio...
  216. cd ..\.. || GOTO :END
  217. REM This hack generates a single config for MSVS, guaranteeing it gets set as the active config.
  218. cmake.exe .. -DCMAKE_PREFIX_PATH="%PS_DESTDIR%\usr\local" -DCMAKE_CONFIGURATION_TYPES=%PS_CONFIG% > nul 2> nul || GOTO :END
  219. REM Now launch devenv with the single config (setting it active) and a /command switch to re-run cmake and generate the full config list
  220. start devenv.exe %PS_SOLUTION_NAME%.sln /command ^"shell /o ^^^"%~f0^^^" -d ^^^"%PS_DESTDIR%^^^" -c %PS_CONFIG% -a %PS_ARCH% -r none -s app-cmake^"
  221. REM If devenv fails to launch just directly regenerate the full config list.
  222. IF %ERRORLEVEL% NEQ 0 (
  223. cmake.exe .. -DCMAKE_PREFIX_PATH="%PS_DESTDIR%\usr\local" -DCMAKE_CONFIGURATION_TYPES=%PS_CONFIG_LIST% 2> nul 1> nul || GOTO :END
  224. )
  225. )
  226. )
  227. @REM ********** DON'T ADD ANY CODE BETWEEN THESE TWO SECTIONS **********
  228. @REM RUN_APP may hand off control, so let exit codes fall through to PROLOGUE.
  229. :PROLOGUE
  230. SET EXIT_STATUS=%ERRORLEVEL%
  231. :END
  232. @IF "%PS_ECHO_ON%%PS_DRY_RUN_ONLY%" NEQ "" (
  233. @ECHO **********************************************************************
  234. @ECHO ** Script Parameters:
  235. @ECHO **********************************************************************
  236. @SET PS_
  237. )
  238. IF "%EXIT_STATUS%" NEQ "0" (
  239. IF "%PS_CURRENT_STEP%" NEQ "arguments" (
  240. @ECHO.
  241. @ECHO ERROR: *** Build process failed at %PS_CURRENT_STEP% step. *** 1>&2
  242. )
  243. ) ELSE (
  244. @ECHO All steps completed successfully.
  245. )
  246. popd
  247. exit /B %EXIT_STATUS%
  248. GOTO :EOF
  249. REM Functions and stubs start here.
  250. :RESOLVE_DESTDIR_CACHE
  251. @REM Resolves all DESTDIR cache values and sets PS_STEPS_DEFAULT
  252. @REM Note: This just sets global variableq, so it doesn't use setlocal.
  253. SET PS_DEPS_PATH_FILE_FOR_CONFIG=%~dp0build\%PS_ARCH%\%PS_CONFIG%\%PS_DEPS_PATH_FILE_NAME%
  254. CALL :CANONICALIZE_PATH PS_DEPS_PATH_FILE_FOR_CONFIG
  255. IF EXIST "%PS_DEPS_PATH_FILE_FOR_CONFIG%" (
  256. FOR /F "tokens=* USEBACKQ" %%I IN ("%PS_DEPS_PATH_FILE_FOR_CONFIG%") DO (
  257. SET PS_DESTDIR_CACHED=%%I
  258. SET PS_DESTDIR_DEFAULT_MSG=%%I
  259. )
  260. SET PS_STEPS_DEFAULT=app-dirty
  261. ) ELSE IF EXIST "%PS_DEPS_PATH_FILE%" (
  262. FOR /F "tokens=* USEBACKQ" %%I IN ("%PS_DEPS_PATH_FILE%") DO (
  263. SET PS_DESTDIR_CACHED=%%I
  264. SET PS_DESTDIR_DEFAULT_MSG=%%I
  265. )
  266. SET PS_STEPS_DEFAULT=app
  267. ) ELSE (
  268. SET PS_DESTDIR_CACHED=
  269. SET PS_DESTDIR_DEFAULT_MSG=Cache missing. Argument required.
  270. SET PS_STEPS_DEFAULT=all
  271. )
  272. GOTO :EOF
  273. :PARSE_OPTION
  274. @REM Argument parser called for each argument
  275. @REM %1 - Valid option list
  276. @REM %2 - Variable name for parser state; must be unset when parsing finished
  277. @REM %3 - Current argument value
  278. @REM PARSER_FAIL will be set on an error
  279. @REM Note: Must avoid delayed expansion since filenames may contain ! character
  280. setlocal disableDelayedExpansion
  281. IF "%PARSER_FAIL%" NEQ "" GOTO :EOF
  282. CALL SET LAST_ARG=%%%2%%
  283. IF "%LAST_ARG%" EQU "" (
  284. CALL :PARSE_OPTION_NAME %1 %~2 %~3 1
  285. SET ARG_TYPE=NAME
  286. ) ELSE (
  287. SET PS_SET_COMMAND=SET PS_%LAST_ARG%=%~3
  288. SET ARG_TYPE=LAST_ARG
  289. SET %~2=
  290. )
  291. CALL SET LAST_ARG=%%%2%%
  292. IF "%LAST_ARG%%ARG_TYPE%" EQU "NAME" SET PARSER_FAIL=%~3
  293. (
  294. endlocal
  295. SET PARSER_FAIL=%PARSER_FAIL%
  296. SET %~2=%LAST_ARG%
  297. %PS_SET_COMMAND%
  298. )
  299. GOTO :EOF
  300. :PARSE_OPTION_VALUE
  301. setlocal disableDelayedExpansion
  302. @REM Parses value and verifies it is within the supplied list
  303. @REM %1 - Valid option list
  304. @REM %2 - In/out variable name; unset on error
  305. CALL SET NAME=%~2
  306. CALL SET SAVED_VALUE=%%%NAME%%%
  307. CALL :PARSE_OPTION_NAME %1 %NAME% -%SAVED_VALUE%
  308. CALL SET NEW_VALUE=%%%NAME%%%
  309. IF "%NEW_VALUE%" EQU "" (
  310. @ECHO ERROR: Invalid parameter: %NAME:~3%=%SAVED_VALUE% 1>&2
  311. )
  312. endlocal & SET %NAME%=%NEW_VALUE%
  313. GOTO :EOF
  314. :PARSE_OPTION_NAME
  315. @REM Parses an option name
  316. @REM %1 - Valid option list
  317. @REM %2 - Out variable name; unset on error
  318. @REM %3 - Current argument value
  319. @REM %4 - Boolean indicating single character switches are valid
  320. @REM Note: Delayed expansion safe because ! character is invalid in option name
  321. setlocal enableDelayedExpansion
  322. IF "%4" NEQ "" FOR %%I IN (%~1) DO @(
  323. SET SHORT_NAME=%%~I
  324. SET SHORT_ARG_!SHORT_NAME:~0,1!=%%~I
  325. )
  326. @SET OPTION_NAME=%~3
  327. @(echo %OPTION_NAME%)| findstr /R /C:"[-/]..*">nul || GOTO :PARSE_OPTION_NAME_FAIL
  328. @SET OPTION_NAME=%OPTION_NAME:~1%
  329. IF "%4" NEQ "" (
  330. IF "%OPTION_NAME%" EQU "%OPTION_NAME:~0,1%" (
  331. IF "!SHORT_ARG_%OPTION_NAME:~0,1%!" NEQ "" SET OPTION_NAME=!SHORT_ARG_%OPTION_NAME:~0,1%!
  332. )
  333. )
  334. @(echo %OPTION_NAME%)| findstr /R /C:".[ ][ ]*.">nul && GOTO :PARSE_OPTION_NAME_FAIL
  335. @(echo %~1 )| findstr /I /C:" %OPTION_NAME% ">nul || GOTO :PARSE_OPTION_NAME_FAIL
  336. FOR %%I IN (%~1) DO SET OPTION_NAME=!OPTION_NAME:%%~I=%%~I!
  337. endlocal & SET %~2=%OPTION_NAME%
  338. GOTO :EOF
  339. :PARSE_OPTION_NAME_FAIL
  340. endlocal & SET %~2=
  341. GOTO :EOF
  342. :MAKE_OR_CLEAN_DIRECTORY
  343. @REM Create directory if it doesn't exist or clean it if it does
  344. @REM %1 - Directory path to clean or create
  345. @REM %* - Optional list of files/dirs to keep (in the base directory only)
  346. setlocal disableDelayedExpansion
  347. IF NOT EXIST "%~1" (
  348. @ECHO Creating %~1
  349. mkdir "%~1" && (
  350. endlocal
  351. GOTO :EOF
  352. )
  353. )
  354. @ECHO Cleaning %~1 ...
  355. SET KEEP_LIST=
  356. :MAKE_OR_CLEAN_DIRECTORY_ARG_LOOP
  357. IF "%~2" NEQ "" (
  358. SET KEEP_LIST=%KEEP_LIST% "%~2"
  359. SHIFT /2
  360. GOTO :MAKE_OR_CLEAN_DIRECTORY_ARG_LOOP
  361. )
  362. for /F "usebackq delims=" %%I in (`dir /a /b "%~1"`) do (
  363. (echo %KEEP_LIST%)| findstr /I /L /C:"\"%%I\"">nul || (
  364. rmdir /s /q "%~1\%%I" 2>nul ) || del /q /f "%~1\%%I"
  365. )
  366. endlocal
  367. GOTO :EOF
  368. :TOLOWER
  369. @REM Converts supplied environment variable to lowercase
  370. @REM %1 - Input/output variable name
  371. @REM Note: This is slow on very long strings, but is used only on very short ones
  372. setlocal disableDelayedExpansion
  373. @FOR %%b IN (a b c d e f g h i j k l m n o p q r s t u v w x y z) DO @CALL set %~1=%%%1:%%b=%%b%%
  374. @CALL SET OUTPUT=%%%~1%%
  375. endlocal & SET %~1=%OUTPUT%
  376. GOTO :EOF
  377. :CANONICALIZE_PATH
  378. @REM Canonicalizes the path in the supplied variable
  379. @REM %1 - Input/output variable containing path to canonicalize
  380. @REM %2 - Optional base directory
  381. setlocal
  382. CALL :CANONICALIZE_PATH_INNER %1 %%%~1%% %2
  383. endlocal & SET %~1=%OUTPUT%
  384. GOTO :EOF
  385. :CANONICALIZE_PATH_INNER
  386. if "%~3" NEQ "" (pushd %3 || GOTO :EOF)
  387. SET OUTPUT=%~f2
  388. if "%~3" NEQ "" popd
  389. GOTO :EOF
  390. :DIFF_TIME
  391. @REM Calculates elapsed time between two timestamps (TIME environment variable format)
  392. @REM %1 - Output variable
  393. @REM %2 - Start time
  394. @REM %3 - End time
  395. setlocal EnableDelayedExpansion
  396. set START_ARG=%2
  397. set END_ARG=%3
  398. set END=!END_ARG:%TIME:~8,1%=%%100)*100+1!
  399. set START=!START_ARG:%TIME:~8,1%=%%100)*100+1!
  400. 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
  401. set /A CC=DIFF%%100+100,DIFF/=100,SS=DIFF%%60+100,DIFF/=60,MM=DIFF%%60+100,HH=DIFF/60+100
  402. @endlocal & set %1=%HH:~1%%TIME:~2,1%%MM:~1%%TIME:~2,1%%SS:~1%%TIME:~8,1%%CC:~1%
  403. @GOTO :EOF
  404. :WRITE_CUSTOM_SCRIPT_SKELETON
  405. @REM Writes the following text to the supplied file
  406. @REM %1 - Output filename
  407. setlocal
  408. @(
  409. ECHO @ECHO.
  410. ECHO @ECHO ********************************************************************************
  411. ECHO @ECHO ** This is a custom run script skeleton.
  412. ECHO @ECHO ********************************************************************************
  413. ECHO @ECHO.
  414. ECHO @ECHO ********************************************************************************
  415. ECHO @ECHO ** The working directory is:
  416. ECHO @ECHO ********************************************************************************
  417. ECHO dir
  418. ECHO @ECHO.
  419. ECHO @ECHO ********************************************************************************
  420. ECHO @ECHO ** The environment is:
  421. ECHO @ECHO ********************************************************************************
  422. ECHO set
  423. ECHO @ECHO.
  424. ECHO @ECHO ********************************************************************************
  425. ECHO @ECHO ** Edit or replace this script to run custom steps after a successful build:
  426. ECHO @ECHO ** %~1
  427. ECHO @ECHO ********************************************************************************
  428. ECHO @ECHO.
  429. ) > "%~1"
  430. endlocal
  431. GOTO :EOF