layers: Add handling for NULL in core post call
[platform/upstream/Vulkan-LoaderAndValidationLayers.git] / update_external_sources.bat
1 @echo off
2 REM Update source for glslang
3
4 REM Determine the appropriate CMake strings for the current version of Visual Studio
5 echo Determining VS version
6 python .\scripts\determine_vs_version.py > vsversion.tmp
7 set /p VS_VERSION=< vsversion.tmp
8 echo Detected Visual Studio Version as %VS_VERSION%
9
10 REM Cleanup the file we used to collect the VS version output since it's no longer needed.
11 del /Q /F vsversion.tmp
12
13 setlocal EnableDelayedExpansion
14 set errorCode=0
15 set BUILD_DIR=%~dp0
16 set BASE_DIR="%BUILD_DIR%external"
17 set REVISION_DIR="%BUILD_DIR%external_revisions"
18 set GLSLANG_DIR=%BASE_DIR%\glslang
19 set do_32=0
20 set do_64=0
21 set do_debug=0
22 set do_release=0
23
24 git submodule update --init --recursive
25
26 REM // ======== Parameter parsing ======== //
27
28    set arg-use-implicit-component-list=1
29    set arg-do-glslang=0
30    set arg-no-sync=0
31    set arg-no-build=0
32    set arg-32=0
33    set arg-64=0
34    set arg-debug=0
35    set arg-release=0
36
37    :parameterLoop
38
39       if "%1"=="" goto:parameterContinue
40
41       if "%1" == "--glslang" (
42          set arg-do-glslang=1
43          set arg-use-implicit-component-list=0
44          echo Building glslang ^(%1^)
45          shift
46          goto:parameterLoop
47       )
48
49       if "%1" == "-g" (
50          set arg-do-glslang=1
51          set arg-use-implicit-component-list=0
52          echo Building glslang ^(%1^)
53          shift
54          goto:parameterLoop
55       )
56
57       if "%1" == "--no-sync" (
58          set arg-no-sync=1
59          echo Skipping sync ^(%1^)
60          shift
61          goto:parameterLoop
62       )
63
64       if "%1" == "--no-build" (
65          set arg-no-build=1
66          echo Skipping build ^(%1^)
67          shift
68          goto:parameterLoop
69       )
70
71       if "%1" == "--32" (
72          set arg-32=1
73          echo 32-bit build requested
74          shift
75          goto:parameterLoop
76       )
77
78       if "%1" == "--64" (
79          set arg-64=1
80          echo 64-bit build requested
81          shift
82          goto:parameterLoop
83       )
84
85       if "%1" == "--debug" (
86          set arg-debug=1
87          echo debug build requested
88          shift
89          goto:parameterLoop
90       )
91
92       if "%1" == "--release" (
93          set arg-release=1
94          echo release build requested
95          shift
96          goto:parameterLoop
97       )
98
99       if "%1" == "--spirv-tools" (
100          echo --spirv-tools argument has been deprecated and is no longer necessary
101          shift
102          goto:parameterLoop
103       )
104
105       if "%1" == "-s" (
106          echo --s argument has been deprecated and is no longer necessary
107          shift
108          goto:parameterLoop
109       )
110
111       if "%1" == "--all" (
112          echo --all argument has been deprecated and is no longer necessary
113          set arg-do-glslang=1
114          set arg-use-implicit-component-list=0
115          echo Building glslang ^(%1^)
116          shift
117          goto:parameterLoop
118       )
119
120       echo.
121       echo Unrecognized option "%1"
122       echo.
123       echo usage: update_external_sources.bat [options]
124       echo.
125       echo   Available options:
126       echo     -g ^| --glslang      enable glslang component
127       echo     --all               enable all components
128       echo     --no-sync           skip sync from git
129       echo     --no-build          skip build
130       echo     --32                build for 32-bit
131       echo     --64                build for 64-bit
132       echo     --debug             build for debug
133       echo     --release           build for release
134       echo.
135       echo   If any component enables are provided, only those components are enabled.
136       echo   If no component enables are provided, all components are enabled.
137       echo.
138       echo   Sync uses git to pull a specific revision.
139       echo   Build configures CMake, builds Release and Debug.
140       echo.
141       echo   --32 without --64 builds only 32-bit, and vice-versa.
142       echo   --debug without --release builds only debug, and vice-versa.
143       echo   Specifying neither or both --32 and --64 builds both.
144       echo   Specifying neither or both --debug and --release builds both.
145       echo   So specifying none of these 4 options (default) builds all 4.
146
147
148       goto:error
149
150    :parameterContinue
151
152    if %arg-use-implicit-component-list% equ 1 (
153       echo Building glslang
154       set arg-do-glslang=1
155    )
156
157    set sync-glslang=0
158    set build-glslang=0
159    set check-glslang-build-dependencies=0
160
161    if %arg-do-glslang% equ 1 (
162       if %arg-no-sync% equ 0 (
163          set sync-glslang=1
164       )
165       if %arg-no-build% equ 0 (
166          set check-glslang-build-dependencies=1
167          set build-glslang=1
168       )
169    )
170
171    if %arg-32% equ 1 (
172        set do_32=1
173    )
174    if %arg-64% equ 1 (
175        set do_64=1
176    )
177    if %arg-32% equ 0 (
178       if %arg-64% equ 0 (
179           set do_32=1
180           set do_64=1
181       )
182    )
183
184    if %arg-debug% equ 1 (
185        set do_debug=1
186    )
187    if %arg-release% equ 1 (
188        set do_release=1
189    )
190    if %arg-debug% equ 0 (
191       if %arg-release% equ 0 (
192           set do_debug=1
193           set do_release=1
194       )
195    )
196
197    REM this is a debugging aid that can be enabled while debugging command-line parsing
198    if 0 equ 1 (
199       set arg
200       set sync-glslang
201       set build-glslang
202       set check-glslang-build-dependencies
203       goto:error
204    )
205
206 REM // ======== end Parameter parsing ======== //
207
208
209 REM // ======== Dependency checking ======== //
210    REM git is required for all paths
211    for %%X in (git.exe) do (set FOUND=%%~$PATH:X)
212    if not defined FOUND (
213       echo Dependency check failed:
214       echo   git.exe not found
215       echo   Git for Windows can be downloaded here:  https://git-scm.com/download/win
216       echo   Install and ensure git.exe makes it into your PATH
217       set errorCode=1
218    )
219
220    if %check-glslang-build-dependencies% equ 1 (
221       for %%X in (cmake.exe) do (set FOUND=%%~$PATH:X)
222       if not defined FOUND (
223          echo Dependency check failed:
224          echo   cmake.exe not found
225          echo   Get CMake for Windows here:  http://www.cmake.org/cmake/resources/software.html
226          echo   Install and ensure each makes it into your PATH, default is "C:\Program Files (x86)\CMake\bin"
227          set errorCode=1
228       )
229    )
230
231
232    REM goto:main
233
234 REM // ======== end Dependency checking ======== //
235
236 :main
237
238 if %errorCode% neq 0 (goto:error)
239
240 REM Read the target versions from external file, which is shared with Linux script
241
242 if not exist %REVISION_DIR%\glslang_giturl (
243    echo.
244    echo Missing glslang_giturl file!  Place it in %REVISION_DIR% with git repo URL in it.
245    set errorCode=1
246    goto:error
247 )
248
249 if not exist %REVISION_DIR%\glslang_revision (
250    echo.
251    echo Missing glslang_revision file!  Place it in %REVISION_DIR% with target version in it.
252    set errorCode=1
253    goto:error
254 )
255
256 set /p GLSLANG_GITURL= < %REVISION_DIR%\glslang_giturl
257 set /p GLSLANG_REVISION= < %REVISION_DIR%\glslang_revision
258
259 echo GLSLANG_GITURL=%GLSLANG_GITURL%
260 echo GLSLANG_REVISION=%GLSLANG_REVISION%
261
262
263 echo Creating and/or updating glslang in %BASE_DIR%
264
265 if %sync-glslang% equ 1 (
266    if not exist %GLSLANG_DIR% (
267       call:create_glslang
268    )
269    if %errorCode% neq 0 (goto:error)
270    call:update_glslang
271    if %errorCode% neq 0 (goto:error)
272 )
273
274 if %build-glslang% equ 1 (
275    call:build_glslang
276    if %errorCode% neq 0 (goto:error)
277 )
278
279 echo.
280 echo Exiting
281 goto:finish
282
283 :error
284 echo.
285 echo Halting due to error
286 set errorCode=1
287 goto:finish
288
289 :finish
290 if not "%cd%\" == "%BUILD_DIR%" ( cd %BUILD_DIR% )
291 exit /b %errorCode%
292
293
294 REM // ======== Functions ======== //
295
296 :create_glslang
297    echo.
298    echo Creating local glslang repository %GLSLANG_DIR%)
299    mkdir %GLSLANG_DIR%
300    cd %GLSLANG_DIR%
301    git clone %GLSLANG_GITURL% .
302    git checkout %GLSLANG_REVISION%
303    python.exe .\update_glslang_sources.py
304    if not exist %GLSLANG_DIR%\SPIRV (
305        echo glslang source download failed!
306        set errorCode=1
307    )
308 goto:eof
309
310 :update_glslang
311    echo.
312    echo Updating %GLSLANG_DIR%
313    cd %GLSLANG_DIR%
314    git fetch --all
315    git checkout %GLSLANG_REVISION%
316    python.exe .\update_glslang_sources.py
317 goto:eof
318
319 :build_glslang
320    echo.
321    echo Building %GLSLANG_DIR%
322    cd  %GLSLANG_DIR%
323
324    if not exist build32 (
325        mkdir build32
326    )
327    if not exist build (
328        mkdir build
329    )
330
331    set GLSLANG_BUILD_DIR=%GLSLANG_DIR%\build32
332    if %do_32% equ 1 (
333       echo Making 32-bit glslang
334       echo *************************
335       cd %GLSLANG_BUILD_DIR%
336
337       echo Generating 32-bit Glslang CMake files for Visual Studio %VS_VERSION% -DCMAKE_INSTALL_PREFIX=install ..
338       cmake -G "Visual Studio %VS_VERSION%" -DCMAKE_INSTALL_PREFIX=install ..
339
340       if %do_debug% equ 1 (
341          echo Building 32-bit Glslang: MSBuild INSTALL.vcxproj /p:Platform=x86 /p:Configuration=Debug
342          msbuild INSTALL.vcxproj /p:Platform=x86 /p:Configuration=Debug /verbosity:quiet
343
344          REM Check for existence of one lib, even though we should check for all results
345          if not exist %GLSLANG_BUILD_DIR%\glslang\Debug\glslangd.lib (
346             echo.
347             echo glslang 32-bit Debug build failed!
348             set errorCode=1
349          )
350       )
351       if %do_release% equ 1 (
352          echo Building Glslang: MSBuild INSTALL.vcxproj /p:Platform=x86 /p:Configuration=Release
353          msbuild INSTALL.vcxproj /p:Platform=x86 /p:Configuration=Release /verbosity:quiet
354
355          REM Check for existence of one lib, even though we should check for all results
356          if not exist %GLSLANG_BUILD_DIR%\glslang\Release\glslang.lib (
357             echo.
358             echo glslang 32-bit Release build failed!
359             set errorCode=1
360          )
361       )
362       cd ..
363    )
364
365    set GLSLANG_BUILD_DIR=%GLSLANG_DIR%\build
366    if %do_64% equ 1 (
367       echo Making 64-bit glslang
368       echo *************************
369       cd %GLSLANG_BUILD_DIR%
370
371       echo Generating 64-bit Glslang CMake files for Visual Studio %VS_VERSION% -DCMAKE_INSTALL_PREFIX=install ..
372       cmake -G "Visual Studio %VS_VERSION% Win64" -DCMAKE_INSTALL_PREFIX=install ..
373
374       if %do_debug% equ 1 (
375          echo Building 64-bit Glslang: MSBuild INSTALL.vcxproj /p:Platform=x64 /p:Configuration=Debug
376          msbuild INSTALL.vcxproj /p:Platform=x64 /p:Configuration=Debug /verbosity:quiet
377
378          REM Check for existence of one lib, even though we should check for all results
379          if not exist %GLSLANG_BUILD_DIR%\glslang\Debug\glslangd.lib (
380             echo.
381             echo glslang 64-bit Debug build failed!
382             set errorCode=1
383          )
384       )
385       if %do_release% equ 1 (
386          echo Building Glslang: MSBuild INSTALL.vcxproj /p:Platform=x64 /p:Configuration=Release
387          msbuild INSTALL.vcxproj /p:Platform=x64 /p:Configuration=Release /verbosity:quiet
388
389          REM Check for existence of one lib, even though we should check for all results
390          if not exist %GLSLANG_BUILD_DIR%\glslang\Release\glslang.lib (
391             echo.
392             echo glslang 64-bit Release build failed!
393             set errorCode=1
394          )
395       )
396       cd ..
397    )
398
399 goto:eof