This repository has been archived by the owner on Nov 16, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 63
/
build.cmd
423 lines (377 loc) · 15.6 KB
/
build.cmd
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
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
@if not defined _echo @echo off
setlocal
set /p ProductVersion=<version.txt
:: Store current script directory before %~dp0 gets affected by another process later.
set __currentScriptDir=%~dp0
set DependenciesDir=%__currentScriptDir%dependencies\
if not exist "%DependenciesDir%" (md "%DependenciesDir%")
:: Default configuration if no arguents passed to build.cmd (DbgWinPy3.8)
set __BuildArch=x64
set __VCBuildArch=x86_amd64
set Configuration=DbgWinPy3.8
set DebugBuild=True
set BuildOutputDir=%__currentScriptDir%x64\
set PythonUrl=https://pythonpkgdeps.blob.core.windows.net/python/python-3.8.3-amd64.zip
set PythonRoot=%DependenciesDir%Python3.8
set PythonVersion=3.8
set PythonTag=cp38
set RunTests=False
set InstallPythonPackages=False
set RunExtendedTests=False
set BuildDotNetBridgeOnly=False
set SkipDotNetBridge=False
set AzureBuild=False
set BuildManifestGenerator=False
set UpdateManifest=False
set VerifyManifest=False
:Arg_Loop
if [%1] == [] goto :Build
if /i [%1] == [--configuration] (
shift && goto :Configuration
)
if /i [%1] == [--runTests] (
set RunTests=True
set InstallPythonPackages=True
shift && goto :Arg_Loop
)
if /i [%1] == [--installPythonPackages] (
set InstallPythonPackages=True
shift && goto :Arg_Loop
)
if /i [%1] == [--includeExtendedTests] (
set RunExtendedTests=True
shift && goto :Arg_Loop
)
if /i [%1] == [--buildDotNetBridgeOnly] (
set BuildDotNetBridgeOnly=True
shift && goto :Arg_Loop
)
if /i [%1] == [--skipDotNetBridge] (
set SkipDotNetBridge=True
shift && goto :Arg_Loop
)
if /i [%1] == [--updateManifest] (
set UpdateManifest=True
shift && goto :Arg_Loop
)
if /i [%1] == [--azureBuild] (
set AzureBuild=True
shift && goto :Arg_Loop
) else goto :Usage
:Usage
echo "Usage: build.cmd [--configuration <Configuration>] [--runTests] [--installPythonPackages] [--includeExtendedTests] [--buildDotNetBridgeOnly] [--skipDotNetBridge] [--azureBuild]"
echo ""
echo "Options:"
echo " --configuration <Configuration> Build Configuration (DbgWinPy3.8,DbgWinPy3.7,DbgWinPy3.6,RlsWinPy3.8, RlsWinPy3.7,RlsWinPy3.6)"
echo " --runTests Run tests after build"
echo " --installPythonPackages Install python packages after build"
echo " --includeExtendedTests Include the extended tests if the tests are run"
echo " --buildDotNetBridgeOnly Build only DotNetBridge"
echo " --skipDotNetBridge Build everything except DotNetBridge"
echo " --updateManifest Update manifest.json"
echo " --azureBuild Building in azure devops (adds dotnet CLI to the path)"
goto :Exit_Success
:Configuration
if /i [%1] == [RlsWinPy3.8] (
set DebugBuild=False
set Configuration=RlsWinPy3.8
set PythonUrl=https://pythonpkgdeps.blob.core.windows.net/python/python-3.8.3-amd64.zip
set PythonRoot=%DependenciesDir%Python3.8
set PythonVersion=3.8
set PythonTag=cp38
shift && goto :Arg_Loop
)
if /i [%1] == [RlsWinPy3.7] (
set DebugBuild=False
set Configuration=RlsWinPy3.7
set PythonUrl=https://pythonpkgdeps.blob.core.windows.net/python/python-3.7.3-amd64.zip
set PythonRoot=%DependenciesDir%Python3.7
set PythonVersion=3.7
set PythonTag=cp37
shift && goto :Arg_Loop
)
if /i [%1] == [RlsWinPy3.6] (
set DebugBuild=False
set Configuration=RlsWinPy3.6
set PythonUrl=https://pythonpkgdeps.blob.core.windows.net/python/python-3.6.5-mohoov-amd64.zip
set PythonRoot=%DependenciesDir%Python3.6
set PythonVersion=3.6
set PythonTag=cp36
shift && goto :Arg_Loop
)
if /i [%1] == [DbgWinPy3.8] (
set DebugBuild=True
set Configuration=DbgWinPy3.8
set PythonUrl=https://pythonpkgdeps.blob.core.windows.net/python/python-3.8.3-amd64.zip
set PythonRoot=%DependenciesDir%Python3.8
set PythonVersion=3.8
set PythonTag=cp38
shift && goto :Arg_Loop
)
if /i [%1] == [DbgWinPy3.7] (
set DebugBuild=True
set Configuration=DbgWinPy3.7
set PythonUrl=https://pythonpkgdeps.blob.core.windows.net/python/python-3.7.3-amd64.zip
set PythonRoot=%DependenciesDir%Python3.7
set PythonVersion=3.7
set PythonTag=cp37
shift && goto :Arg_Loop
)
if /i [%1] == [DbgWinPy3.6] (
set DebugBuild=True
set Configuration=DbgWinPy3.6
set PythonUrl=https://pythonpkgdeps.blob.core.windows.net/python/python-3.6.5-mohoov-amd64.zip
set PythonRoot=%DependenciesDir%Python3.6
set PythonVersion=3.6
set PythonTag=cp36
shift && goto :Arg_Loop
)
:Build
:: Install dotnet SDK version, see https://docs.microsoft.com/en-us/dotnet/core/tools/dotnet-install-script
echo Installing dotnet SDK ...
powershell -NoProfile -ExecutionPolicy unrestricted -Command "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; &([scriptblock]::Create((Invoke-WebRequest -useb 'https://dot.net/v1/dotnet-install.ps1'))) -Version 3.1.102 -InstallDir ./cli"
set _dotnetRoot=%__currentScriptDir%cli
if "%AzureBuild%" == "True" (
:: Add dotnet CLI root to the PATH in azure devops agent
echo ##vso[task.prependpath]%_dotnetRoot%
)
:: Build managed code
echo ""
echo "#################################"
echo "Building Managed code ... "
echo "#################################"
set _dotnet=%_dotnetRoot%\dotnet.exe
if "%Configuration:~-5%" == "Py3.6" set VerifyManifest=True
if "%VerifyManifest%" == "True" set BuildManifestGenerator=True
if "%UpdateManifest%" == "True" set BuildManifestGenerator=True
if "%SkipDotNetBridge%" == "False" (
call "%_dotnet%" build -c %Configuration% -o "%BuildOutputDir%%Configuration%" --force "%__currentScriptDir%src\DotNetBridge\DotNetBridge.csproj"
) else (
set VerifyManifest=False
set UpdateManifest=False
set BuildManifestGenerator=False
)
if "%BuildDotNetBridgeOnly%" == "True" (
exit /b %ERRORLEVEL%
)
call "%_dotnet%" build -c %Configuration% --force "%__currentScriptDir%src\Platforms\build.csproj"
call "%_dotnet%" publish "%__currentScriptDir%src\Platforms\build.csproj" --force --self-contained -r win-x64 -c %Configuration%
if "%BuildManifestGenerator%" == "True" (
echo ""
echo "#################################"
echo "Building Manifest Generator... "
echo "#################################"
call "%_dotnet%" build -c %Configuration% -o "%BuildOutputDir%%Configuration%" --force "%__currentScriptDir%src\ManifestGenerator\ManifestGenerator.csproj"
)
if "%UpdateManifest%" == "True" (
echo Updating manifest.json ...
call "%_dotnet%" "%BuildOutputDir%%Configuration%\ManifestGenerator.dll" create %__currentScriptDir%\src\python\tools\manifest.json
echo manifest.json updated.
echo Run entrypoint_compiler.py --generate_api --generate_entrypoints to generate entry points and api files.
goto :Exit_Success
)
if "%VerifyManifest%" == "True" (
echo Verifying manifest.json ...
call "%_dotnet%" "%BuildOutputDir%%Configuration%\ManifestGenerator.dll" verify %__currentScriptDir%\src\python\tools\manifest.json
if errorlevel 1 (
echo manifest.json is invalid.
echo Run build --updateManifest to update manifest.json.
goto :Exit_Error
)
)
echo ""
echo "#################################"
echo "Downloading Dependencies "
echo "#################################"
:: Download & unzip Python
if not exist "%PythonRoot%\.done" (
md "%PythonRoot%"
echo Downloading python zip ...
powershell -command "& {$wc = New-Object System.Net.WebClient; $wc.DownloadFile('%PythonUrl%', '%DependenciesDir%python.zip');}"
echo Extracting python zip ...
powershell.exe -nologo -noprofile -command "& { Add-Type -A 'System.IO.Compression.FileSystem'; [IO.Compression.ZipFile]::ExtractToDirectory('%DependenciesDir%python.zip', '%PythonRoot%'); }"
echo.>"%PythonRoot%\.done"
del %DependenciesDir%python.zip
echo Python executable: %PythonRoot%\python.exe
echo "Installing pybind11 ..."
call "%PythonRoot%\python.exe" -m pip install pybind11
)
echo ""
echo "#################################"
echo "Building Native code ... "
echo "#################################"
:: Setting native code build environment
echo Setting native build environment ...
set _VSWHERE="%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe"
set vswhereOutputFile=vswhereOutput.tmp
if exist %_VSWHERE% (
%_VSWHERE% -version "[15.0,16.0)" -latest -prerelease -property installationPath > %vswhereOutputFile%
for /f "tokens=* delims=" %%i in (%vswhereOutputFile%) do set _VSCOMNTOOLS=%%i\Common7\Tools
del %vswhereOutputFile%
)
if not exist "%_VSCOMNTOOLS%" set _VSCOMNTOOLS=%VS140COMNTOOLS%
if not exist "%_VSCOMNTOOLS%" goto :MissingVersion
set "VSCMD_START_DIR=%__currentScriptDir%"
call "%_VSCOMNTOOLS%\VsDevCmd.bat"
if "%VisualStudioVersion%"=="16.0" (
goto :VS2019
) else if "%VisualStudioVersion%"=="15.0" (
goto :VS2017
) else if "%VisualStudioVersion%"=="14.0" (
goto :VS2015
) else goto :MissingVersion
:MissingVersion
:: Can't find VS 2015 or 2017 or 2019
echo Error: Visual Studio 2015 or 2017 required
echo Please see https://github.com/dotnet/machinelearning/tree/master/Documentation for build instructions.
goto :Exit_Error
:VS2019
:: Setup vars for VS2019
set __PlatformToolset=v142
set __VSVersion=16 2019
if NOT "%__BuildArch%" == "arm64" (
:: Set the environment for the native build
call "%VS150COMNTOOLS%..\..\VC\Auxiliary\Build\vcvarsall.bat" %__VCBuildArch%
)
goto :NativeBridge
:VS2017
:: Setup vars for VS2017
set __PlatformToolset=v141
set __VSVersion=15 2017
if NOT "%__BuildArch%" == "arm64" (
:: Set the environment for the native build
call "%VS150COMNTOOLS%..\..\VC\Auxiliary\Build\vcvarsall.bat" %__VCBuildArch%
)
goto :NativeBridge
:VS2015
:: Setup vars for VS2015build
set __PlatformToolset=v140
set __VSVersion=14 2015
if NOT "%__BuildArch%" == "arm64" (
:: Set the environment for the native build
call "%VS140COMNTOOLS%..\..\VC\vcvarsall.bat" %__VCBuildArch%
)
goto :NativeBridge
:NativeBridge
:: Build NativeBridge.vcxproj
echo Building NativeBridge.vcxproj ...
set __msbuildArgs=/p:Platform=%__BuildArch% /p:PlatformToolset="%__PlatformToolset%"
call msbuild "%__currentScriptDir%src\NativeBridge\NativeBridge.vcxproj" /p:Configuration=%Configuration% %__msbuildArgs%
if %errorlevel% neq 0 goto :Exit_Error
:: Build nimbusml wheel
echo ""
echo "#################################"
echo "Building nimbusml wheel package ... "
echo "#################################"
echo Building nimbusml wheel package ...
set PythonExe=%PythonRoot%\python.exe
echo Python executable: %PythonExe%
:: Clean out build, dist, and libs from previous builds
set build="%__currentScriptDir%src\python\build"
set dist="%__currentScriptDir%src\python\dist"
set libs="%__currentScriptDir%src\python\nimbusml\internal\libs"
if exist %build% rd %build% /S /Q
if exist %dist% rd %dist% /S /Q
if exist %libs% rd %libs% /S /Q
md %libs%
echo.>"%__currentScriptDir%src\python\nimbusml\internal\libs\__init__.py"
if "%VerifyManifest%" == "True" (
:: Running the check in one python is enough.
echo Generating low-level Python API from mainifest.json ...
call "%PythonExe%" -m pip install --upgrade autopep8 autoflake isort jinja2
cd "%__currentScriptDir%src\python"
call "%PythonExe%" tools\entrypoint_compiler.py --check_manual_changes
if errorlevel 1 (
echo Codegen check failed. Try running tools/entrypoint_compiler.py --check_manual_changes to find the problem.
goto :Exit_Error
)
cd "%__currentScriptDir%"
)
echo Placing binaries in libs dir for wheel packaging
copy "%BuildOutputDir%%Configuration%\DotNetBridge.dll" "%__currentScriptDir%src\python\nimbusml\internal\libs\"
copy "%BuildOutputDir%%Configuration%\pybridge.pyd" "%__currentScriptDir%src\python\nimbusml\internal\libs\"
for /F "tokens=*" %%A in (build/libs_win.txt) do copy "%BuildOutputDir%%Configuration%\Platform\win-x64\publish\%%A" "%__currentScriptDir%src\python\nimbusml\internal\libs\"
xcopy /S /E /I "%BuildOutputDir%%Configuration%\Platform\win-x64\publish\Data" "%__currentScriptDir%src\python\nimbusml\internal\libs\Data"
if "%DebugBuild%" == "True" (
copy "%BuildOutputDir%%Configuration%\DotNetBridge.pdb" "%__currentScriptDir%src\python\nimbusml\internal\libs\"
copy "%BuildOutputDir%%Configuration%\pybridge.pdb" "%__currentScriptDir%src\python\nimbusml\internal\libs\"
)
call "%PythonExe%" -m pip install --upgrade "wheel>=0.31.0"
cd "%__currentScriptDir%src\python"
call "%PythonExe%" setup.py bdist_wheel --python-tag %PythonTag% --plat-name win_amd64
cd "%__currentScriptDir%"
set WheelFile=nimbusml-%ProductVersion%-%PythonTag%-none-win_amd64.whl
if not exist "%__currentScriptDir%src\python\dist\%WheelFile%" (
echo setup.py did not produce expected %WheelFile%
goto :Exit_Error
)
md "%__currentScriptDir%target"
copy "%__currentScriptDir%src\python\dist\%WheelFile%" "%__currentScriptDir%target\%WheelFile%"
echo Python package successfully created: %__currentScriptDir%target\%WheelFile%
if "%InstallPythonPackages%" == "True" (
echo ""
echo "#################################"
echo "Installing python packages ... "
echo "#################################"
call "%PythonExe%" -m pip install --upgrade "pip==19.3.1"
call "%PythonExe%" -m pip install --upgrade nose pytest pytest-xdist graphviz imageio "jupyter_client>=4.4.0" "nbconvert>=4.2.0"
call "%PythonExe%" -m pip install --upgrade "azureml-dataprep>=1.1.33"
call "%PythonExe%" -m pip install --upgrade onnxruntime
call "%PythonExe%" -m pip install --upgrade "%__currentScriptDir%target\%WheelFile%"
call "%PythonExe%" -m pip install "scikit-learn==0.19.2"
)
if "%RunTests%" == "False" (
goto :Exit_Success
)
echo ""
echo "#################################"
echo "Running tests ... "
echo "#################################"
set PackagePath=%PythonRoot%\Lib\site-packages\nimbusml
set TestsPath1=%PackagePath%\tests
set TestsPath2=%__currentScriptDir%src\python\tests
set TestsPath3=%__currentScriptDir%src\python\tests_extended
set NumConcurrentTests=%NUMBER_OF_PROCESSORS%
call "%PythonExe%" -m pytest -n %NumConcurrentTests% --verbose --maxfail=1000 --capture=sys "%TestsPath2%" "%TestsPath1%"
if errorlevel 1 (
:: Rerun any failed tests to give them one more
:: chance in case the errors were intermittent.
call "%PythonExe%" -m pytest -n %NumConcurrentTests% --last-failed --verbose --maxfail=1000 --capture=sys "%TestsPath2%" "%TestsPath1%"
if errorlevel 1 (
goto :Exit_Error
)
)
if "%RunExtendedTests%" == "True" (
call "%PythonExe%" -m pytest -n %NumConcurrentTests% --verbose --maxfail=1000 --capture=sys "%TestsPath3%"
if errorlevel 1 (
:: Rerun any failed tests to give them one more
:: chance in case the errors were intermittent.
call "%PythonExe%" -m pytest -n %NumConcurrentTests% --last-failed --verbose --maxfail=1000 --capture=sys "%TestsPath3%"
if errorlevel 1 (
goto :Exit_Error
)
)
)
:Exit_Success
call :CleanUpDotnet
endlocal
exit /b %ERRORLEVEL%
:Exit_Error
call :CleanUpDotnet
endlocal
echo Failed with error %ERRORLEVEL%
exit /b %ERRORLEVEL%
:CleanUpDotnet
:: Save the error level so it can be
:: restored when exiting the function
set PrevErrorLevel=%ERRORLEVEL%
:: Shutdown all dotnet persistent servers so that the
:: dotnet executable is not left open in the background.
:: As of dotnet 2.1.3 three servers are left running in
:: the background. This will shutdown them all down.
:: See here for more info: https://github.com/dotnet/cli/issues/9458
:: This fixes an issue when re-running the build script because
:: the build script was trying to replace the existing dotnet
:: binaries which were sometimes still in use.
call "%_dotnet%" build-server shutdown
exit /b %PrevErrorLevel%