-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.bat
282 lines (243 loc) · 6.52 KB
/
build.bat
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
@ECHO off
SETLOCAL
SET TARGET_ARCH=
:: argument parser
:parse
IF "%~1"=="" (
GOTO endparse
)
IF "%~1"=="-t" (
SET TARGET_ARCH=%~2
)
IF "%~1"=="-cc" (
SET CPP_BUILD=true
)
IF "%~1"=="-py" (
SET PYTHON_BUILD=true
)
IF "%~1"=="-cs" (
SET CSHARP_BUILD=true
)
IF "%~1"=="-jni" (
SET JAVA_BUILD=true
)
IF "%~1"=="-go" (
SET GO_BUILD=true
)
IF "%~1"=="--clean" (
SET CLEAN=true
)
IF "%~1"=="--help" (
CALL :print_usage
EXIT /B 0
)
IF "%~1"=="-h" (
CALL :print_usage
EXIT /B 0
)
SHIFT
GOTO parse
:endparse
:: check TARGET_ARCH value
IF "%TARGET_ARCH%"=="" (
ECHO ERROR: Unspecified target architecture. Please use -t from CLI to specify an architecture.
EXIT /B 1
)
::check if architecture is supported
SET SUPPORTED_TARGETS=msvc-x64;aarch64-linux-android;arm-linux-android
:: easy-to-undestand checking if TARGET_ARCH is in SUPPORTED_TARGETS list
FOR %%A IN (%SUPPORTED_TARGETS%) DO (
IF "%TARGET_ARCH%"=="%%A" (
SET VALID_TARGET_ARCH=1
)
)
IF "%VALID_TARGET_ARCH%"=="" (
ECHO ERROR: target %TARGET_ARCH% is not supported yet. Please use (%SUPPORTED_TARGETS%^).
EXIT /B 1
)
:: check if need to clean
SET BINARY_PATH=%CD%\assets\binaries\%TARGET_ARCH%
IF NOT "%CLEAN%"=="" (
CALL :clean_build %BINARY_PATH%
)
:: artifacts
SET TAG=v0.11.0
SET ARCHIVE_NAME=oneml-bootcamp-%TARGET_ARCH%.tar.gz
SET BASE_URL=https://github.com/sertiscorp/oneML-bootcamp/releases/download/%TAG%/%ARCHIVE_NAME%
IF NOT EXIST "%BINARY_PATH%\%ARCHIVE_NAME%" (
ECHO Downloading artifacts to %BINARY_PATH%...
curl -L %BASE_URL% > %BINARY_PATH%\%ARCHIVE_NAME%
tar xzf %BINARY_PATH%\%ARCHIVE_NAME% -C %BINARY_PATH%\ --strip-components=1
)
:: toolchian
SET EXTRA_FLAGS=
IF "%TARGET_ARCH%"=="aarch64-linux-android" GOTO android
IF "%TARGET_ARCH%"=="arm-linux-android" GOTO android
IF "%TARGET_ARCH%"=="msvc-x64" GOTO end_toolchain
SET EXTRA_FLAGS=-DCMAKE_TOOLCHAIN_FILE=cmake\toolchains\%TARGET_ARCH%.cmake
GOTO end_toolchain
:android
SET ANDROID_BUILD=true
IF "%TARGET_ARCH%"=="arm-linux-android" (
SET ABI=armeabi-v7a
SET EXTRA_FLAGS=-DANDROID_ARM_NEON=ON
) ELSE (
SET ABI=arm64-v8a
)
SET EXTRA_FLAGS=-DCMAKE_TOOLCHAIN_FILE=%ANDROID_NDK_HOME%\build\cmake\android.toolchain.cmake^
-DANDROID_ABI=%ABI%^
-DANDROID_NATIVE_API_LEVEL=23^
-DANDROID_STL=c++_shared^
%EXTRA_FLAGS%
:end_toolchain
:: apps build
IF NOT "%CPP_BUILD%"=="" (
IF NOT EXIST "build" MKDIR build
CD build
cmake -G "Visual Studio 16 2019" -A x64 -DTARGET_ARCH=%TARGET_ARCH% %EXTRA_FLAGS% ..
cmake --build . --config Release
CD ..
COPY %BINARY_PATH%\bin\oneml.dll bin\Release\
)
IF NOT "%PYTHON_BUILD%"=="" (
IF NOT "%CLEAN%"=="" (
GOTO python_build
)
pip list | findstr oneML
IF NOT %ERRORLEVEL%==0 (
GOTO python_build
)
ECHO Using existing oneML installation. Use --clean to reinstall.
GOTO end_python_build
) ELSE (
GOTO end_python_build
)
:python_build
pip3 install -U pip setuptools wheel
CD %BINARY_PATH%\bindings\python
POWERSHELL -command "& .\install_oneml.ps1"
:end_python_build
IF NOT "%CSHARP_BUILD%"=="" (
IF NOT "%CLEAN%"=="" (
GOTO csharp_build
)
IF NOT EXIST "%BINARY_PATH%\bindings\csharp\face\build" (
GOTO java_build
)
IF NOT EXIST "%BINARY_PATH%\bindings\csharp\alpr\build" (
GOTO java_build
)
ECHO Using existing C# binaries. Use --clean to rebuild.
GOTO end_csharp_build
) ELSE (
GOTO end_csharp_build
)
:csharp_build
:: Build Java application
CD %BINARY_PATH%\bindings\csharp\face
POWERSHELL -command "& .\build.ps1"
CD ..\alpr
POWERSHELL -command "& .\build.ps1"
CD ..\..\..\..\..\..\apps\csharp
SET APPS=FaceEmbedderApp FaceIdApp FaceDetectorApp FaceVerificationApp FacePadApp VehicleDetectorApp EKYCApp
FOR %%A IN (%APPS%) DO (
dotnet new console -o %%A
CD %%A
dotnet build
CD ..
)
COPY %BINARY_PATH%\bin\oneml.dll .
COPY %BINARY_PATH%\bindings\csharp\face\build\Release\oneMLfaceCSharp.dll .
COPY %BINARY_PATH%\bindings\csharp\alpr\build\Release\oneMLalprCSharp.dll .
:end_csharp_build
IF NOT "%JAVA_BUILD%"=="" (
IF NOT "%CLEAN%"=="" (
GOTO java_build
)
IF NOT EXIST "%BINARY_PATH%\bindings\java\face\build" (
GOTO java_build
)
IF NOT EXIST "%BINARY_PATH%\bindings\java\alpr\build" (
GOTO java_build
)
ECHO Using existing Java classes for oneML. Use --clean to compile again.
GOTO end_java_build
) ELSE (
GOTO end_java_build
)
:java_build
IF NOT "%ANDROID_BUILD%"=="" (
SET ANDROID_APPS=android-simple;android-camera
FOR %%A IN (%ANDROID_APPS%) DO (
ECHO Build Android app: %%A
CD .\apps\"%%A"
:: Alternative `touch` command for Windows
IF NOT EXIST .\local.properties (
TYPE nul > local.properties
)
IF NOT "%CLEAN%"=="" (
ECHO Clean a project by Gradle wrapper
:: Clean flag is set. Clean a project before building
CALL .\gradlew.bat clean
)
ECHO Build by Gradle wrapper
CALL .\gradlew.bat build
CD ..\..
)
) else (
:: Build Java application
CD %BINARY_PATH%\bindings\java\face
POWERSHELL -command "& .\build.ps1"
CD ..\alpr
POWERSHELL -command "& .\build.ps1"
CD ..\..\..\..\..\..\apps\java
IF NOT EXIST "classes" MKDIR classes
SET CLASSPATH=classes;%BINARY_PATH%\bindings\java\face\oneml\oneml-face-api.jar;%BINARY_PATH%\bindings\java\alpr\oneml\oneml-alpr-api.jar;%CD%
SET APPS=FaceEmbedderApp FaceIdApp FaceDetectorApp FaceVerificationApp FacePadApp VehicleDetectorApp EKYCApp
FOR %%A IN (%APPS%) DO (
javac -cp %CLASSPATH% -d classes %%A.java
)
COPY %BINARY_PATH%\bin\oneml.dll .
COPY %BINARY_PATH%\bindings\java\face\build\Release\oneMLfaceJava.dll .
COPY %BINARY_PATH%\bindings\java\alpr\build\Release\oneMLalprJava.dll .
)
:end_java_build
IF NOT "%GO_BUILD%"=="" (
ECHO implement this
)
EXIT /B %ERRORLEVEL%
:: functions
:print_usage
ECHO Usage: build.bat
ECHO -t target_arch
ECHO [-cc cpp_apps]
ECHO [-py python_apps]
ECHO [-cs csharp_apps]
ECHO [-jni java_apps]
ECHO [-go go_apps]
ECHO [--clean clean_build]
ECHO.
ECHO Example: build.bat
ECHO -t x86_64
ECHO [-cc]
ECHO [-py]
ECHO [-cs]
ECHO [-jni]
ECHO [-go]
ECHO [--clean]
ECHO.
EXIT /B 0
:clean_build
ECHO Cleanup build in progress...
RMDIR /S /Q build bin apps\java\classes 2>NUL
DEL /S /Q *.tar.gz 2>NUL
DEL /S /Q *.zip 2>NUL
DEL /S /Q *.json 2>NUL
DEL /S /Q *.yaml 2>NUL
DEL /S /Q *.dll 2>NUL
RMDIR /S /Q %~1\bin 2>NUL
RMDIR /S /Q %~1\bindings 2>NUL
RMDIR /S /Q %~1\include 2>NUL
RMDIR /S /Q %~1\lib 2>NUL
RMDIR /S /Q %~1\share 2>NUL
EXIT /B 0