kvm-guest-drivers-windows
278 строк · 7.7 Кб
1@echo off
2setlocal enabledelayedexpansion
3
4rem ================================================================================
5rem Virtio-win master build script
6rem
7rem Usage: build.bat <project_or_solution_file_path> <target_os_versions> [<args>]
8rem
9rem where args can be one or more of
10rem Debug, dbg, chk .. to build Debug rather than the default release flavor
11rem amd64, x64, 64 .. to build only 64-bit driver
12rem x86, 32 .. to build only 32-bit driver
13rem /Option .. build command to pass to VS, for example /Rebuild
14rem Win10 .. target OS version
15rem
16rem By default the script performs an incremental build of both 32-bit and 64-bit
17rem release drivers for all supported target OSes.
18rem
19rem To do a Static Driver Verifier build, append _SDV to the target OS version, for
20rem example Win10_SDV.
21rem ================================================================================
22
23rem This is a list of supported build target specifications A_B where A is the
24rem VS project configuration name and B is the corresponding platform identifier
25rem used in log file names and intermediate directory names. Either of the two can
26rem be used in the <target_os_version> command line argument.
27set SUPPORTED_BUILD_SPECS=Win10_win10 Win11_win11
28
29set BUILD_TARGETS=%~2
30set BUILD_DIR=%~dp1
31set BUILD_FILE=%~nx1
32set BUILD_NAME=%~n1
33
34rem We do an incremental Release build for all specs and all archs by default
35set BUILD_FLAVOR=Release
36set BUILD_COMMAND=/Build
37set BUILD_SPEC=
38set BUILD_ARCH=
39set BUILD_FAILED=
40
41rem Parse arguments
42:argloop
43shift /2
44if "%2"=="" goto argend
45set ARG=%2
46if "%ARG:~0,1%"=="/" set BUILD_COMMAND=%ARG%& goto :argloop
47
48if /I "%ARG%"=="Debug" set BUILD_FLAVOR=Debug& goto :argloop
49if /I "%ARG%"=="dbg" set BUILD_FLAVOR=Debug& goto :argloop
50if /I "%ARG%"=="chk" set BUILD_FLAVOR=Debug& goto :argloop
51
52if /I "%ARG%"=="amd64" set BUILD_ARCH=amd64& goto :argloop
53if /I "%ARG%"=="64" set BUILD_ARCH=amd64& goto :argloop
54if /I "%ARG%"=="x64" set BUILD_ARCH=amd64& goto :argloop
55if /I "%ARG%"=="32" set BUILD_ARCH=x86& goto :argloop
56if /I "%ARG%"=="x86" set BUILD_ARCH=x86& goto :argloop
57if /I "%ARG%"=="ARM64" set BUILD_ARCH=ARM64& goto :argloop
58
59rem Assume that this is target OS version and split off the tag
60call :split_target_tag "%ARG%"
61
62rem Verify that this target OS is supported and valid
63for %%N in (%SUPPORTED_BUILD_SPECS%) do (
64set T=%%N
65set CANDIDATE_SPEC=
66set FOUND_MATCH=
67
68for %%A in ("!T:_=" "!") do (
69if /I %%A=="%TARGET%" set CANDIDATE_SPEC=!T!!TAG!
70for %%B in (%BUILD_TARGETS%) do (
71if /I %%B==%%~A!TAG! set FOUND_MATCH=1
72)
73)
74
75if not "!FOUND_MATCH!"=="" if not "!CANDIDATE_SPEC!"=="" (
76set BUILD_SPEC=!CANDIDATE_SPEC!
77goto :argloop
78)
79)
80
81rem Silently exit if the build target could not be matched
82rem
83rem The reason for ignoring build target mismatch are projects
84rem like NetKVM, viostor, and vioscsi, which build different
85rem sln/vcxproj for different targets. Higher level script
86rem does not have information about specific sln/vcproj and
87rem platform bindings, therefore it invokes this script once
88rem for each sln/vcproj to make it decide when the actual build
89rem should be invoked.
90
91goto :eof
92
93rem Figure out which targets we're building
94:argend
95if "%BUILD_SPEC%"=="" (
96for %%B in (%BUILD_TARGETS%) do (
97call :split_target_tag "%%B"
98for %%N in (%SUPPORTED_BUILD_SPECS%) do (
99set T=%%N
100set BUILD_SPEC=
101for %%A in ("!T:_=" "!") do (
102if /I %%A=="!TARGET!" set BUILD_SPEC=!T!!TAG!
103)
104if not "!BUILD_SPEC!"=="" (
105call :build_target !BUILD_SPEC!
106if not "!BUILD_FAILED!"=="" goto :fail
107)
108)
109)
110) else (
111call :build_target %BUILD_SPEC%
112)
113goto :eof
114
115rem Figure out which archs we're building
116:build_target
117if "%BUILD_ARCH%"=="" (
118call :build_arch %1 x86
119if not "!BUILD_FAILED!"=="" goto :eof
120call :build_arch %1 amd64
121) else (
122call :build_arch %1 %BUILD_ARCH%
123)
124goto :eof
125
126rem Invoke Visual Studio
127:build_arch
128setlocal
129set BUILD_ARCH=%2
130set TAG=
131for /f "tokens=1 delims=_" %%T in ("%1") do (
132set TARGET_PROJ_CONFIG=%%T
133)
134for /f "tokens=2 delims=_" %%T in ("%1") do (
135set TARGET_PLATFORM=%%T
136)
137for /f "tokens=3 delims=_" %%T in ("%1") do (
138set TAG=%%T
139)
140
141if /I "!TAG!"=="SDV" (
142rem There is no 32-bit SDV build
143if %BUILD_ARCH%==x86 goto :eof
144rem Check the SDV build suppression variable
145if not "%_BUILD_DISABLE_SDV%"=="" (
146echo Skipping %TARGET_PROJ_CONFIG% SDV build because _BUILD_DISABLE_SDV is set
147goto :eof
148)
149)
150
151rem Compose build log file name
152if %BUILD_FLAVOR%=="Debug" (
153set BUILD_LOG_FILE=buildchk
154) else (
155set BUILD_LOG_FILE=buildfre
156)
157set BUILD_LOG_FILE=%BUILD_LOG_FILE%_%TARGET_PLATFORM%_%BUILD_ARCH%.log
158
159if %BUILD_ARCH%==amd64 set BUILD_ARCH=x64
160set TARGET_VS_CONFIG="%TARGET_PROJ_CONFIG% %BUILD_FLAVOR%|%BUILD_ARCH%"
161
162pushd %BUILD_DIR%
163call "%~dp0\SetVsEnv.bat" %TARGET_PROJ_CONFIG%
164
165if /I "!TAG!"=="SDV" (
166echo Running SDV for %BUILD_FILE%, configuration %TARGET_VS_CONFIG%
167call :runsdv "%TARGET_PROJ_CONFIG% %BUILD_FLAVOR%" %BUILD_ARCH%
168if exist "%CODEQL_BIN%" (
169echo Running CodeQL for %BUILD_FILE%, configuration %TARGET_VS_CONFIG%
170call :runql "%TARGET_PROJ_CONFIG% %BUILD_FLAVOR%" %BUILD_ARCH%
171) else (
172echo CodeQL binary is missing!
173)
174call :runca "%TARGET_PROJ_CONFIG% %BUILD_FLAVOR%" %BUILD_ARCH%
175call :rundvl "%TARGET_PROJ_CONFIG% %BUILD_FLAVOR%" %BUILD_ARCH%
176) else (
177echo Building %BUILD_FILE%, configuration %TARGET_VS_CONFIG%, command %BUILD_COMMAND%
178call :runbuild "%TARGET_PROJ_CONFIG% %BUILD_FLAVOR%" %BUILD_ARCH%
179)
180popd
181endlocal
182
183IF ERRORLEVEL 1 (
184set BUILD_FAILED=1
185)
186goto :eof
187
188:runbuild:
189:: %1 - configuration (as "Win10 Release")
190:: %2 - platform (as x64)
191:: %3 - build command (as "/Build")
192set __TARGET__=%BUILD_COMMAND:/=%
193::(n)ormal(d)etailed,(disg)nostic
194set __VERBOSITY__=n
195msbuild.exe -maxCpuCount %BUILD_FILE% /t:%__TARGET__% /p:Configuration="%~1" /P:Platform=%2 -fileLoggerParameters:Verbosity=%__VERBOSITY__%;LogFile=%BUILD_LOG_FILE%
196goto :eof
197
198:runsdv
199echo "Removing previously created SDV artifacts"
200rmdir /s/q sdv
201
202msbuild.exe -maxCpuCount %BUILD_FILE% /t:clean /p:Configuration="%~1" /P:Platform=%2
203
204IF ERRORLEVEL 1 (
205set BUILD_FAILED=1
206)
207
208msbuild.exe -maxCpuCount %BUILD_FILE% /t:sdv /p:inputs="/clean" /p:Configuration="%~1" /P:platform=%2
209
210IF ERRORLEVEL 1 (
211set BUILD_FAILED=1
212)
213
214msbuild.exe -maxCpuCount %BUILD_FILE% /t:sdv /p:inputs="/check /devenv" /p:Configuration="%~1" /P:platform=%2
215
216IF ERRORLEVEL 1 (
217set BUILD_FAILED=1
218)
219
220goto :eof
221
222:runql
223
224echo "Removing previously created rules database"
225rmdir /s/q codeql_db
226
227echo call "%~dp0\SetVsEnv.bat" %~1 > %~dp1\codeql.build.bat
228echo msbuild.exe -maxCpuCount %~dp1\%BUILD_FILE% /t:rebuild /p:Configuration="%~1" /P:Platform=%2 >> %~dp1\codeql.build.bat
229
230call %CODEQL_BIN% database create -l=cpp -s=%~dp1 -c "%~dp1\codeql.build.bat" %~dp1\codeql_db -j 0
231
232IF ERRORLEVEL 1 (
233set CODEQL_FAILED=1
234set BUILD_FAILED=1
235)
236
237IF "%CODEQL_FAILED%" NEQ "1" (
238call %CODEQL_BIN% database analyze %~dp1\codeql_db %CODEQL_DRIVER_SUITES%\windows_driver_recommended.qls %CODEQL_DRIVER_SUITES%\windows_driver_mustfix.qls --format=sarifv2.1.0 --output=%~dp1\%BUILD_NAME%.sarif -j 0
239)
240
241IF ERRORLEVEL 1 (
242set BUILD_FAILED=1
243)
244
245goto :eof
246
247:runca
248msbuild.exe -maxCpuCount %BUILD_FILE% /p:Configuration="%~1" /P:Platform=%2 /P:RunCodeAnalysisOnce=True -fileLoggerParameters:LogFile=%~dp1\%BUILD_NAME%.CodeAnalysis.log
249
250IF ERRORLEVEL 1 (
251set BUILD_FAILED=1
252)
253
254goto :eof
255
256:rundvl
257msbuild.exe -maxCpuCount %BUILD_FILE% /t:dvl /p:Configuration="%~1" /P:platform=%2
258
259IF ERRORLEVEL 1 (
260set BUILD_FAILED=1
261)
262
263goto :eof
264
265:split_target_tag
266set TARGET=
267set TAG=
268for /f "tokens=1 delims=_" %%T in (%1) do (
269set TARGET=%%T
270)
271for /f "tokens=2 delims=_" %%T in (%1) do (
272set TAG=_%%T
273)
274goto :eof
275
276:fail
277
278exit /B 1
279