appveyor_helper.bat 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. @echo off
  2. REM Copyright (C) 1994-2017 Altair Engineering, Inc.
  3. REM For more information, contact Altair at www.altair.com.
  4. REM
  5. REM This file is part of the PBS Professional ("PBS Pro") software.
  6. REM
  7. REM Open Source License Information:
  8. REM
  9. REM PBS Pro is free software. You can redistribute it and/or modify it under the
  10. REM terms of the GNU Affero General Public License as published by the Free
  11. REM Software Foundation, either version 3 of the License, or (at your option) any
  12. REM later version.
  13. REM
  14. REM PBS Pro is distributed in the hope that it will be useful, but WITHOUT ANY
  15. REM WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
  16. REM PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
  17. REM
  18. REM You should have received a copy of the GNU Affero General Public License along
  19. REM with this program. If not, see <http://www.gnu.org/licenses/>.
  20. REM
  21. REM Commercial License Information:
  22. REM
  23. REM The PBS Pro software is licensed under the terms of the GNU Affero General
  24. REM Public License agreement ("AGPL"), except where a separate commercial license
  25. REM agreement for PBS Pro version 14 or later has been executed in writing with Altair.
  26. REM
  27. REM Altairs dual-license business model allows companies, individuals, and
  28. REM organizations to create proprietary derivative works of PBS Pro and distribute
  29. REM them - whether embedded or bundled with other software - under a commercial
  30. REM license agreement.
  31. REM
  32. REM Use of Altairs trademarks, including but not limited to "PBS",
  33. REM "PBS Professional", and "PBS Pro" and Altairs logos is subject to Altair's
  34. REM trademark licensing policies.
  35. REM this script is just helper script to build PBS deps in parallel to reduce
  36. REM time of building all PBS deps.
  37. REM
  38. REM 1. it will list all build_*.bat file in .appveyor directory
  39. REM 2. one by one it will execute each batch file in background while
  40. REM capturing output and error or batchfile in <batch file name>.bat.out
  41. REM file in current directory
  42. REM 3. while executing batch file it will limit number of started background
  43. REM process to number of processors available in system.
  44. REM 4. once it started background process reached limit it goes to wait loop
  45. REM where it will wait for atleast one background process to complete by
  46. REM looking at exclusive lock on <batch file name>.bat.out created by start
  47. REM of process and that lock will be released as soon as process ends
  48. REM 5. as soon as one processor ends it checks for <batch file name>.bat.passed
  49. REM file if it exists that means background process completed successfully
  50. REM else some error occurred. Now in case of error this script will show
  51. REM contents of <batch file name>.bat.out to console and exit with error
  52. REM (which will stop all other background scrips also) else it will just put
  53. REM one line saying \<batch file name>.bat finished.
  54. REM 6. Now since one process if finished we have one room to start new process
  55. REM so it will go back to main loop to start new background process for building
  56. REM next PBS deps and main loop again goes to wait loop and this goes on till
  57. REM end of all batch file in .appveyor directory
  58. setlocal enableDelayedExpansion
  59. cd "%~dp0\.."
  60. set /a "started=0, ended=0"
  61. set hasmore=1
  62. set BUILD_TYPE=Release
  63. if "%~1"=="debug" (
  64. set BUILD_TYPE=Debug
  65. )
  66. if "%~1"=="Debug" (
  67. set BUILD_TYPE=Debug
  68. )
  69. for /f "usebackq" %%A in (`dir /b C:\__withoutspace_*dir_* 2^>nul`) do rd /Q C:\%%A
  70. call "%~dp0set_paths.bat"
  71. 1>nul 2>nul del /Q /F %BINARIESDIR%\*.bat.out %BINARIESDIR%\*.passed
  72. for /f "usebackq" %%A in (`dir /on /b .appveyor ^| findstr /B /R "^build_.*\.bat$"`) do (
  73. if !started! lss %NUMBER_OF_PROCESSORS% (
  74. set /a "started+=1, next=started"
  75. ) else (
  76. call :Wait
  77. )
  78. set out!next!=%%A.out
  79. echo !time! - %%A - %BUILD_TYPE% version: started
  80. start /b "" "cmd /c 1>%BINARIESDIR%\%%A.out 2>&1 .appveyor\%%A %BUILD_TYPE% && echo > %BINARIESDIR%\%%A.passed"
  81. REM Introduce 2 sec delay to get different RANDOM value
  82. 1>nul 2>nul ping /n 2 ::1
  83. )
  84. set hasmore=
  85. :Wait
  86. for /l %%N in (1 1 %started%) do 2>nul (
  87. if not defined ended%%N if exist "%BINARIESDIR%\!out%%N!" 9>>"%BINARIESDIR%\!out%%N!" (
  88. if not exist "%BINARIESDIR%\!out%%N:out=passed!" (
  89. type "%BINARIESDIR%\!out%%N!"
  90. exit 1
  91. ) else (
  92. echo !time! - !out%%N:.out=! - %BUILD_TYPE% version: finished
  93. )
  94. if defined hasmore (
  95. set /a "next=%%N"
  96. exit /b
  97. )
  98. set /a "ended+=1, ended%%N=1"
  99. )
  100. )
  101. if %ended% lss %started% (
  102. 1>nul 2>nul ping /n 5 ::1
  103. goto :Wait
  104. )
  105. 1>nul 2>nul del /Q /F %BINARIESDIR%\*.bat.out %BINARIESDIR%\*.passed