|
| 1 | +SETLOCAL EnableDelayedExpansion |
| 2 | + |
1 | 3 | :: Use Python 2 up to Node 12 |
2 | 4 | if %NODEJS_MAJOR_VERSION% leq 12 set "PATH=C:\Python27\;C:\Python27\Scripts;%PATH%" |
3 | 5 |
|
@@ -35,15 +37,59 @@ if "%nodes:~-6%" == "-arm64" ( |
35 | 37 | :: thus failing the build after timing out (1-2% runs). |
36 | 38 | :: Downloading it from here and updating it weekly should |
37 | 39 | :: decrease, if not remove, these types of CI failures. |
38 | | - :: Download and cache x64 node.exe. |
39 | | - mkdir C:\node_exe_cache |
40 | | - forfiles /p "C:\node_exe_cache" /m "node.exe" /d -7 /c "cmd /c del @path" |
41 | | - if not exist C:\node_exe_cache\node.exe ( |
42 | | - curl -L https://nodejs.org/dist/latest/win-x64/node.exe -o C:\node_exe_cache\node.exe |
| 40 | + :: 1. Make node_exe_cache directory if it doesn't exist. |
| 41 | + if not exist C:\node_exe_cache ( |
| 42 | + mkdir C:\node_exe_cache |
| 43 | + ) |
| 44 | + :: 2. Check if node.exe exists and if it's older then 7 days. |
| 45 | + set NODE_CACHED=False |
| 46 | + set CACHE_INVALID=False |
| 47 | + if exist C:\node_exe_cache\node.exe ( |
| 48 | + set NODE_CACHED=True |
| 49 | + forfiles /p "C:\node_exe_cache" /m "node.exe" /d -7 && set CACHE_INVALID=True |
| 50 | + ) |
| 51 | + :: 3. If node.exe didn't exist, or was older then 7 days, download the new one and check it's validity. |
| 52 | + set SHOULD_DOWNLOAD=False |
| 53 | + if !NODE_CACHED! == False set SHOULD_DOWNLOAD=True |
| 54 | + if !CACHE_INVALID! == True set SHOULD_DOWNLOAD=True |
| 55 | + set VALID_SHASUM= |
| 56 | + set DOWNLOAD_SHASUM= |
| 57 | + if !SHOULD_DOWNLOAD! == True ( |
| 58 | + :: 3.1. Download SHASUMS and find value for "win-x64/node.exe". |
| 59 | + ver > nul |
| 60 | + curl -L https://nodejs.org/dist/latest/SHASUMS256.txt -o C:\node_exe_cache\SHASUMS256.txt |
| 61 | + if not !errorlevel! == 0 goto download_cleanup |
| 62 | + for /f %%a in ('findstr win-x64/node.exe C:\node_exe_cache\SHASUMS256.txt') do set VALID_SHASUM=%%a |
| 63 | + if [!VALID_SHASUM!] == [] goto download_cleanup |
| 64 | + :: 3.2. Download win-x64/node.exe and calculate its SHASUM. |
| 65 | + ver > nul |
| 66 | + curl -L https://nodejs.org/dist/latest/win-x64/node.exe -o C:\node_exe_cache\node_new.exe |
| 67 | + if not !errorlevel! == 0 goto download_cleanup |
| 68 | + for /f %%a in ('certutil -hashfile C:\node_exe_cache\node_new.exe SHA256 ^| find /v ":"') do set DOWNLOAD_SHASUM=%%a |
| 69 | + if [!DOWNLOAD_SHASUM!] == [] goto download_cleanup |
| 70 | + :: 3.3. Check if downloaded file is valid. If yes, delete old one. If not, delete new one. |
| 71 | + if !VALID_SHASUM! == !DOWNLOAD_SHASUM! ( |
| 72 | + if exist C:\node_exe_cache\node.exe ( |
| 73 | + del C:\node_exe_cache\node.exe |
| 74 | + ) |
| 75 | + ren C:\node_exe_cache\node_new.exe node.exe |
| 76 | + ) |
| 77 | + :: 3.4. Clean up all of the temporary files. |
| 78 | +:download_cleanup |
| 79 | + if exist C:\node_exe_cache\SHASUMS256.txt ( |
| 80 | + del C:\node_exe_cache\SHASUMS256.txt |
| 81 | + ) |
| 82 | + if exist C:\node_exe_cache\node_new.exe ( |
| 83 | + del C:\node_exe_cache\node_new.exe |
| 84 | + ) |
| 85 | + ) |
| 86 | + :: 4. Copy the latest valid node, if any, to where vcbuild expects it to be |
| 87 | + if exist C:\node_exe_cache\node.exe ( |
| 88 | + if not exist temp-vcbuild ( |
| 89 | + mkdir temp-vcbuild |
| 90 | + ) |
| 91 | + copy C:\node_exe_cache\node.exe temp-vcbuild\node-x64-cross-compiling.exe |
43 | 92 | ) |
44 | | - :: Copy it to where vcbuild expects. |
45 | | - mkdir temp-vcbuild |
46 | | - copy C:\node_exe_cache\node.exe temp-vcbuild\node-x64-cross-compiling.exe |
47 | 93 | ) |
48 | 94 | ) else if "%nodes:~-4%" == "-x86" ( |
49 | 95 | set "VCBUILD_EXTRA_ARGS=x86 %VCBUILD_EXTRA_ARGS%" |
|
0 commit comments