-
Notifications
You must be signed in to change notification settings - Fork 313
Expand file tree
/
Copy pathbuild.cmd
More file actions
122 lines (103 loc) · 4.78 KB
/
build.cmd
File metadata and controls
122 lines (103 loc) · 4.78 KB
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
@echo off
if "%1"=="/?" goto :usage
if "%1"=="-?" goto :usage
setlocal enabledelayedexpansion enableextensions
set BUILDCMDSTARTTIME=%time%
set platform=%1
set configuration=%2
set sample_filter=%3\
if "%platform%"=="" set platform=x64
if "%configuration%"=="" set configuration=Release
call :EnsureDeveloperCommandPrompt
if "%VSINSTALLDIR%"=="" (
echo Visual Studio Developer Command Prompt not detected and automatic initialization failed.
goto :usage
)
if not exist ".\.nuget" mkdir ".\.nuget"
if not exist ".\.nuget\nuget.exe" powershell -Command "Invoke-WebRequest https://dist.nuget.org/win-x86-commandline/latest/nuget.exe -OutFile .\.nuget\nuget.exe"
set NUGET_RESTORE_MSBUILD_ARGS=/p:PublishReadyToRun=true
for /f "delims=" %%D in ('dir /s/b samples\%sample_filter%*.sln') do (
call .nuget\nuget.exe restore "%%D" -configfile Samples\nuget.config -PackagesDirectory %~dp0packages
call msbuild /warnaserror /p:platform=%platform% /p:configuration=%configuration% /p:NugetPackageDirectory=%~dp0packages /bl:"%%~nD.binlog" "%%D"
if ERRORLEVEL 1 goto :eof
)
:showDurationAndExit
set BUILDCMDENDTIME=%time%
:: Note: The '1's in this line are to convert a value like "08" to "108", since numbers which
:: begin with '0' are interpreted as octal, which makes "08" and "09" invalid. Adding the
:: '1's effectively adds 100 to both sides of the subtraction, avoiding this issue.
:: Hours has a leading space instead of 0, so the '1's trick isn't used on that one.
set /a BUILDDURATION_HRS= %BUILDCMDENDTIME:~0,2%- %BUILDCMDSTARTTIME:~0,2%
set /a BUILDDURATION_MIN=1%BUILDCMDENDTIME:~3,2%-1%BUILDCMDSTARTTIME:~3,2%
set /a BUILDDURATION_SEC=1%BUILDCMDENDTIME:~6,2%-1%BUILDCMDSTARTTIME:~6,2%
set /a BUILDDURATION_HSC=1%BUILDCMDENDTIME:~9,2%-1%BUILDCMDSTARTTIME:~9,2%
if %BUILDDURATION_HSC% lss 0 (
set /a BUILDDURATION_HSC=!BUILDDURATION_HSC!+100
set /a BUILDDURATION_SEC=!BUILDDURATION_SEC!-1
)
if %BUILDDURATION_SEC% lss 0 (
set /a BUILDDURATION_SEC=!BUILDDURATION_SEC!+60
set /a BUILDDURATION_MIN=!BUILDDURATION_MIN!-1
)
if %BUILDDURATION_MIN% lss 0 (
set /a BUILDDURATION_MIN=!BUILDDURATION_MIN!+60
set /a BUILDDURATION_HRS=!BUILDDURATION_HRS!-1
)
if %BUILDDURATION_HRS% lss 0 (
set /a BUILDDURATION_HRS=!BUILDDURATION_HRS!+24
)
:: Add a '0' at the start to ensure at least two digits. The output will then just
:: show the last two digits for each.
set BUILDDURATION_HRS=0%BUILDDURATION_HRS%
set BUILDDURATION_MIN=0%BUILDDURATION_MIN%
set BUILDDURATION_SEC=0%BUILDDURATION_SEC%
set BUILDDURATION_HSC=0%BUILDDURATION_HSC%
echo ---
echo Start time: %BUILDCMDSTARTTIME%. End time: %BUILDCMDENDTIME%
echo Elapsed: %BUILDDURATION_HRS:~-2%:%BUILDDURATION_MIN:~-2%:%BUILDDURATION_SEC:~-2%.%BUILDDURATION_HSC:~-2%
endlocal
goto :eof
:EnsureDeveloperCommandPrompt
if not "%VSINSTALLDIR%"=="" goto :eof
echo Visual Studio Developer Command Prompt not detected. Attempting to initialize automatically...
set "VS_INSTALL_PATH="
for %%P in ("%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" "%ProgramFiles%\Microsoft Visual Studio\Installer\vswhere.exe") do (
if exist %%~P (
for /f "usebackq tokens=*" %%I in (`"%%~P" -latest -requires Microsoft.Component.MSBuild -property installationPath`) do (
if not defined VS_INSTALL_PATH (
set "VS_INSTALL_PATH=%%~I"
)
)
if defined VS_INSTALL_PATH goto :VsInstallFound
)
)
goto :EnsureDeveloperCommandPromptEnd
:VsInstallFound
if exist "%VS_INSTALL_PATH%\Common7\Tools\VsDevCmd.bat" (
set "VSDEVCMD_ARGS=-no_logo"
if /i "%platform%"=="x86" set "VSDEVCMD_ARGS=!VSDEVCMD_ARGS! -arch=x86"
if /i "%platform%"=="win32" set "VSDEVCMD_ARGS=!VSDEVCMD_ARGS! -arch=x86"
if /i "%platform%"=="x64" set "VSDEVCMD_ARGS=!VSDEVCMD_ARGS! -arch=x64"
if /i "%platform%"=="arm" set "VSDEVCMD_ARGS=!VSDEVCMD_ARGS! -arch=arm"
if /i "%platform%"=="arm64" set "VSDEVCMD_ARGS=!VSDEVCMD_ARGS! -arch=arm64"
call "%VS_INSTALL_PATH%\Common7\Tools\VsDevCmd.bat" !VSDEVCMD_ARGS!
)
:EnsureDeveloperCommandPromptEnd
if "%VSINSTALLDIR%"=="" (
echo Failed to automatically configure the Visual Studio environment.
echo Please manually run it from a Developer Command Prompt instead.
)
goto :eof
:usage
echo Usage:
echo This script tries to initialize a Visual Studio Developer Command Prompt.
echo If that fails, please manually run it from a Developer Command Prompt instead.
echo.
echo build.cmd [Platform] [Configuration] [Sample]
echo.
echo [Platform] Either x86, x64, or arm64. Default is x64.
echo [Configuration] Either Debug or Release. Default is Release.
echo [Sample] The sample folder under Samples to build. If none specified, all samples are built.
echo.
echo If no parameters are specified, all samples are built for x64 Release.
exit /b /1