summaryrefslogtreecommitdiff
path: root/build-android/update_external_sources_android.bat
blob: 2c771d7d923263b9291db38d110d3c6709b36d34 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
@echo off
REM Update source for glslang, spirv-tools, and shaderc

REM
REM Copyright 2016 The Android Open Source Project
REM Copyright (C) 2015 Valve Corporation
REM
REM Licensed under the Apache License, Version 2.0 (the "License");
REM you may not use this file except in compliance with the License.
REM You may obtain a copy of the License at
REM
REM      http://www.apache.org/licenses/LICENSE-2.0
REM
REM Unless required by applicable law or agreed to in writing, software
REM distributed under the License is distributed on an "AS IS" BASIS,
REM WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
REM See the License for the specific language governing permissions and
REM limitations under the License.
REM

setlocal EnableDelayedExpansion
set errorCode=0
set ANDROID_BUILD_DIR=%~dp0
set BUILD_DIR=%ANDROID_BUILD_DIR%
set BASE_DIR=%BUILD_DIR%\external
set GLSLANG_DIR=%BASE_DIR%\glslang
set SPIRV_TOOLS_DIR=%BASE_DIR%\spirv-tools
set SPIRV_HEADERS_DIR=%BASE_DIR%\spirv-tools\external\spirv-headers
set SHADERC_DIR=%BASE_DIR%\shaderc

for %%X in (where.exe) do (set FOUND=%%~$PATH:X)
if not defined FOUND (
   echo Dependency check failed:
   echo   where.exe not found
   echo   This script requires Windows Vista or later, which includes where.exe.
   set errorCode=1
)

where /q git.exe
if %ERRORLEVEL% equ 1 (
   echo Dependency check failed:
   echo   git.exe not found
   echo   Git for Windows can be downloaded here:  https://git-scm.com/download/win
   echo   Install and ensure git.exe makes it into your PATH
   set errorCode=1
)

where /q ndk-build.cmd
if %ERRORLEVEL% equ 1 (
   echo Dependency check failed:
   echo   ndk-build.cmd not found
   echo   Android NDK can be downloaded here:  http://developer.android.com/ndk/guides/setup.html
   echo   Install and ensure ndk-build.cmd makes it into your PATH
   set errorCode=1
)

REM ensure where is working with below false test
REM where /q foo
REM if %ERRORLEVEL% equ 1 (
REM echo foo
REM )

:main

if %errorCode% neq 0 (goto:error)

REM Read the target versions from external file, which is shared with Linux script

if not exist %ANDROID_BUILD_DIR%\glslang_revision_android (
   echo.
   echo Missing glslang_revision_android file. Place it in %ANDROID_BUILD_DIR%
   goto:error
)

if not exist %ANDROID_BUILD_DIR%\spirv-tools_revision_android (
   echo.
   echo Missing spirv-tools_revision_android file. Place it in %ANDROID_BUILD_DIR%
   set errorCode=1
   goto:error
)

if not exist %ANDROID_BUILD_DIR%\spirv-headers_revision_android (
   echo.
   echo Missing spirv-headers_revision_android file. Place it in %ANDROID_BUILD_DIR%
   set errorCode=1
   goto:error
)

if not exist %ANDROID_BUILD_DIR%\shaderc_revision_android (
   echo.
   echo Missing shaderc_revision_android file. Place it in %ANDROID_BUILD_DIR%
   set errorCode=1
   goto:error
)

set /p GLSLANG_REVISION= < glslang_revision_android
set /p SPIRV_TOOLS_REVISION= < spirv-tools_revision_android
set /p SPIRV_HEADERS_REVISION= < spirv-headers_revision_android
set /p SHADERC_REVISION= < shaderc_revision_android
echo GLSLANG_REVISION=%GLSLANG_REVISION%
echo SPIRV_TOOLS_REVISION=%SPIRV_TOOLS_REVISION%
echo SPIRV_HEADERS_REVISION=%SPIRV_HEADERS_REVISION%
echo SHADERC_REVISION=%SHADERC_REVISION%


echo Creating and/or updating glslang, spirv-tools, spirv-headers, shaderc in %BASE_DIR%

set sync-glslang=1
set sync-spirv-tools=1
set sync-spirv-headers=1
set sync-shaderc=1
set build-shaderc=1

if %sync-glslang% equ 1 (
   if exist %GLSLANG_DIR% (
      rd /S /Q %GLSLANG_DIR%
   )
   if not exist %GLSLANG_DIR% (
      call:create_glslang
   )
   if %errorCode% neq 0 (goto:error)
   call:update_glslang
   if %errorCode% neq 0 (goto:error)
)

if %sync-spirv-tools% equ 1 (
   if exist %SPIRV_TOOLS_DIR% (
      rd /S /Q %SPIRV_TOOLS_DIR%
   )
   if %ERRORLEVEL% neq 0 (goto:error)
   if not exist %SPIRV_TOOLS_DIR% (
      call:create_spirv-tools
   )
   if %errorCode% neq 0 (goto:error)
   call:update_spirv-tools
   if %errorCode% neq 0 (goto:error)
)

if %sync-spirv-headers% equ 1 (
   if exist %SPIRV_HEADERS_DIR% (
      rd /S /Q %SPIRV_HEADERS_DIR%
   )
   if %ERRORLEVEL% neq 0 (goto:error)
   if not exist %SPIRV_HEADERS_DIR% (
      call:create_spirv-headers
   )
   if %errorCode% neq 0 (goto:error)
   call:update_spirv-headers
   if %errorCode% neq 0 (goto:error)
)

if %sync-shaderc% equ 1 (
   if exist %SHADERC_DIR% (
      rd /S /Q %SHADERC_DIR%
   )
   if not exist %SHADERC_DIR% (
      call:create_shaderc
   )
   if %errorCode% neq 0 (goto:error)
   call:update_shaderc
   if %errorCode% neq 0 (goto:error)
)

if %build-shaderc% equ 1 (
   call:build_shaderc
   if %errorCode% neq 0 (goto:error)
)

echo.
echo Exiting
goto:finish

:error
echo.
echo Halting due to error
goto:finish

:finish
if not "%cd%\" == "%BUILD_DIR%" ( cd %BUILD_DIR% )
endlocal
REM This needs a fix to return error, something like exit %errorCode%
REM Right now it is returning 0
goto:eof



REM // ======== Functions ======== //

:create_glslang
   echo.
   echo Creating local glslang repository %GLSLANG_DIR%
   mkdir %GLSLANG_DIR%
   cd %GLSLANG_DIR%
   git clone https://android.googlesource.com/platform/external/shaderc/glslang .
   git checkout %GLSLANG_REVISION%
   if not exist %GLSLANG_DIR%\SPIRV (
      echo glslang source download failed!
      set errorCode=1
   )
goto:eof

:update_glslang
   echo.
   echo Updating %GLSLANG_DIR%
   cd %GLSLANG_DIR%
   git fetch --all
   git checkout %GLSLANG_REVISION%
   if not exist %GLSLANG_DIR%\SPIRV (
      echo glslang source update failed!
      set errorCode=1
   )
goto:eof

:create_spirv-tools
   echo.
   echo Creating local spirv-tools repository %SPIRV_TOOLS_DIR%
   mkdir %SPIRV_TOOLS_DIR%
   cd %SPIRV_TOOLS_DIR%
   git clone https://android.googlesource.com/platform/external/shaderc/spirv-tools .
   git checkout %SPIRV_TOOLS_REVISION%
   if not exist %SPIRV_TOOLS_DIR%\source (
      echo spirv-tools source download failed!
      set errorCode=1
   )
goto:eof

:update_spirv-tools
   echo.
   echo Updating %SPIRV_TOOLS_DIR%
   cd %SPIRV_TOOLS_DIR%
   git fetch --all
   git checkout %SPIRV_TOOLS_REVISION%
   if not exist %SPIRV_TOOLS_DIR%\source (
      echo spirv-tools source update failed!
      set errorCode=1
   )
goto:eof

:create_spirv-headers
   echo.
   echo Creating local spirv-headers repository %SPIRV_HEADERS_DIR%
   mkdir %SPIRV_HEADERS_DIR%
   cd %SPIRV_HEADERS_DIR%
   git clone https://android.googlesource.com/platform/external/shaderc/spirv-headers .
   git checkout %SPIRV_HEADERS_REVISION%
   if not exist %SPIRV_HEADERS_DIR%\include (
      echo spirv-headers source download failed!
      set errorCode=1
   )
goto:eof

:update_spirv-headers
   echo.
   echo Updating %SPIRV_HEADERS_DIR%
   cd %SPIRV_HEADERS_DIR%
   git fetch --all
   git checkout %SPIRV_HEADERS_REVISION%
   if not exist %SPIRV_HEADERS_DIR%\include (
      echo spirv-headers source update failed!
      set errorCode=1
   )
goto:eof

:create_shaderc
   echo.
   echo Creating local shaderc repository %SHADERC_DIR%
   mkdir %SHADERC_DIR%
   cd %SHADERC_DIR%
   git clone https://android.googlesource.com/platform/external/shaderc/shaderc .
   git checkout %SHADERC_REVISION%
   if not exist %SHADERC_DIR%\libshaderc (
      echo shaderc source download failed!
      set errorCode=1
   )
goto:eof

:update_shaderc
   echo.
   echo Updating %SHADERC_DIR%
   cd %SHADERC_DIR%
   git fetch --all
   git checkout %SHADERC_REVISION%
   if not exist %SHADERC_DIR%\libshaderc (
      echo shaderc source update failed!
      set errorCode=1
   )
goto:eof

:build_shaderc
   echo.
   echo Building %SHADERC_DIR%
   cd %SHADERC_DIR%\android_test
   echo Building shaderc with Android NDK
   call ndk-build THIRD_PARTY_PATH=../.. -j 4
   REM Check for existence of one lib, even though we should check for all results
   if not exist %SHADERC_DIR%\android_test\obj\local\x86\libshaderc.a (
      echo.
      echo shaderc build failed!
      set errorCode=1
   )
goto:eof