@@ -11,13 +11,16 @@ rem Debug, dbg, chk .. to build Debug rather than the default release fl
1111rem amd64, x64, 64 .. to build only 64-bit driver
1212rem x86, 32 .. to build only 32-bit driver
1313rem /Option .. build command to pass to VS, for example /Rebuild
14- rem Win10 .. target OS version
14+ rem Win10, Win11 .. target OS version
1515rem
1616rem By default the script performs an incremental build of both 32-bit and 64-bit
1717rem release drivers for all supported target OSes.
1818rem
19- rem To do a Static Driver Verifier build, append _SDV to the target OS version, for
20- rem example Win10_SDV.
19+ rem To do a Static Driver Verifier build, append the _SDV tag to the target OS version,
20+ rem for example Win10_SDV. Where SDV is deprecated, we rely on CodeQL, defaulting to
21+ rem the WHCP_24H2 configuration. To use an earlier configuration specify WHCP_LEGACY.
22+ rem We also continue to run Code Analysis (CA) and Driver Verifier Log (DVL) builds
23+ rem for use with HCK / WHCP.
2124rem ================================================================================
2225
2326rem This is a list of supported build target specifications A_B where A is the
@@ -36,8 +39,13 @@ set BUILD_FLAVOR=Release
3639set BUILD_COMMAND = /Build
3740set BUILD_SPEC =
3841set BUILD_ARCH =
42+ set BUILD_INFO =
3943set BUILD_FAILED =
4044
45+ rem Analysis Build specific variables
46+ set CODEQL_FAILED =
47+ set SDV_FAILED =
48+
4149rem Parse arguments
4250:argloop
4351shift /2
@@ -60,21 +68,27 @@ rem Assume that this is target OS version and split off the tag
6068call :split_target_tag " %ARG% "
6169
6270rem Verify that this target OS is supported and valid
63- for %%N in (%SUPPORTED_BUILD_SPECS% ) do (
71+ for %%N in (%SUPPORTED_BUILD_SPECS% ) do @ (
6472 set T = %%N
6573 set CANDIDATE_SPEC =
6674 set FOUND_MATCH =
6775
68- for %%A in (" !T:_ =" " ! " ) do (
69- if /I %%A == " %TARGET% " set CANDIDATE_SPEC = !T!!TAG!
70- for %%B in (%BUILD_TARGETS% ) do (
71- if /I %%B == %%~A !TAG! set FOUND_MATCH = 1
76+ for %%A in (" !T:_ =" " ! " ) do @ (
77+ if /I %%A == " %TARGET% " (
78+ set CANDIDATE_SPEC = !T!!TAG!
79+ )
80+ for %%B in (%BUILD_TARGETS% ) do @ (
81+ if /I %%B == %%~A !TAG! (
82+ set FOUND_MATCH = 1
83+ )
7284 )
7385 )
7486
75- if not " !FOUND_MATCH! " == " " if not " !CANDIDATE_SPEC! " == " " (
76- set BUILD_SPEC = !CANDIDATE_SPEC!
77- goto :argloop
87+ if not " !FOUND_MATCH! " == " " (
88+ if not " !CANDIDATE_SPEC! " == " " (
89+ set BUILD_SPEC = !CANDIDATE_SPEC!
90+ goto :argloop
91+ )
7892 )
7993)
8094
@@ -93,17 +107,18 @@ goto :eof
93107rem Figure out which targets we're building
94108:argend
95109if " %BUILD_SPEC% " == " " (
96- for %%B in (%BUILD_TARGETS% ) do (
110+ for %%B in (%BUILD_TARGETS% ) do @ (
97111 call :split_target_tag " %%B "
98- for %%N in (%SUPPORTED_BUILD_SPECS% ) do (
112+ for %%N in (%SUPPORTED_BUILD_SPECS% ) do @ (
99113 set T = %%N
100114 set BUILD_SPEC =
101- for %%A in (" !T:_ =" " ! " ) do (
102- if /I %%A == " !TARGET! " set BUILD_SPEC = !T!!TAG!
115+ for %%A in (" !T:_ =" " ! " ) do @ (
116+ if /I %%A == " !TARGET! " (
117+ set BUILD_SPEC = !T!!TAG!
118+ )
103119 )
104120 if not " !BUILD_SPEC! " == " " (
105121 call :build_target !BUILD_SPEC!
106- if not " !BUILD_FAILED! " == " " goto :fail
107122 )
108123 )
109124 )
@@ -116,163 +131,220 @@ rem Figure out which archs we're building
116131:build_target
117132if " %BUILD_ARCH% " == " " (
118133 call :build_arch %1 x86
119- if not " !BUILD_FAILED! " == " " goto :eof
120134 call :build_arch %1 amd64
121135) else (
122136 call :build_arch %1 %BUILD_ARCH%
123137)
124138goto :eof
125139
126- rem Invoke Visual Studio
140+ rem Invoke Visual Studio and CodeQL as needed...
127141:build_arch
128142setlocal
143+ set BUILD_INFO = %1
129144set BUILD_ARCH = %2
130145set TAG =
131- for /f " tokens=1 delims=_" %%T in (" %1 " ) do (
132- set TARGET_PROJ_CONFIG = %%T
133- )
134- for /f " tokens=2 delims=_" %%T in (" %1 " ) do (
135- set TARGET_PLATFORM = %%T
136- )
137- for /f " tokens=3 delims=_" %%T in (" %1 " ) do (
138- set TAG = %%T
146+ for /f " tokens=1,2,3 delims=_" %%i in (" %BUILD_INFO% " ) do @ (
147+ set TARGET_PROJ_CONFIG = %%i
148+ set TARGET_PLATFORM = %%j
149+ set TAG = %%k
139150)
140151
141152if /I " !TAG! " == " SDV" (
142153 rem There is no 32-bit SDV build
143- if %BUILD_ARCH% == x86 goto :eof
154+ if %BUILD_ARCH% == x86 (
155+ goto :build_arch_skip
156+ )
144157 rem Check the SDV build suppression variable
145158 if not " %_BUILD_DISABLE_SDV% " == " " (
146159 echo Skipping %TARGET_PROJ_CONFIG% SDV build because _BUILD_DISABLE_SDV is set
147- goto :eof
160+ goto :build_arch_skip
148161 )
149162)
150163
151164rem Compose build log file name
152- if %BUILD_FLAVOR% == " Debug" (
165+ if " %BUILD_FLAVOR% " == " Debug" (
153166 set BUILD_LOG_FILE = buildchk
154167) else (
155168 set BUILD_LOG_FILE = buildfre
156169)
157170set BUILD_LOG_FILE = %BUILD_LOG_FILE% _%TARGET_PLATFORM% _%BUILD_ARCH% .log
158171
159- if %BUILD_ARCH% == amd64 set BUILD_ARCH = x64
172+ if %BUILD_ARCH% == amd64 (
173+ set BUILD_ARCH = x64
174+ )
160175set TARGET_VS_CONFIG = " %TARGET_PROJ_CONFIG% %BUILD_FLAVOR% |%BUILD_ARCH% "
161176
177+ rem We set up the Build Environment and get started...
178+ echo .
162179pushd %BUILD_DIR%
163- call " %~dp0 \SetVsEnv .bat" %TARGET_PROJ_CONFIG%
180+ call " %~dp0 SetVsEnv .bat" %TARGET_PROJ_CONFIG%
164181
182+ rem Split builds between Code Analysis and No-Analyis...
165183if /I " !TAG! " == " SDV" (
166- echo Running SDV for %BUILD_FILE% , configuration %TARGET_VS_CONFIG%
167- call :runsdv " %TARGET_PROJ_CONFIG% %BUILD_FLAVOR% " %BUILD_ARCH%
184+ echo .
185+ rem SDV is deprecated from Windows 11 24H2, both in the EWDK and WHCP. Making some allowances...
186+ rem We only do SDV for Win10 targets.
187+ if " %TARGET% " == " Win10" (
188+ echo Running SDV for %BUILD_FILE% , configuration %TARGET_VS_CONFIG%
189+ call :run_sdv " %TARGET_PROJ_CONFIG% %BUILD_FLAVOR% " %BUILD_ARCH%
190+ if " %BUILD_FAILED% " EQU " 1" (
191+ echo Static Driver Verifier BUILD FAILED - Resolve problem and try again.
192+ goto :build_arch_done
193+ )
194+ echo Static Driver Verifier build for %BUILD_FILE% succeeded.
195+ ) else (
196+ echo Skipping SDV for %BUILD_FILE% , configuration %TARGET_VS_CONFIG% . SDV is for WHCP_LEGACY targets ONLY.
197+ echo .
198+ )
168199 if exist " %CODEQL_BIN% " (
169200 echo Running CodeQL for %BUILD_FILE% , configuration %TARGET_VS_CONFIG%
170- call :runql " %TARGET_PROJ_CONFIG% %BUILD_FLAVOR% " %BUILD_ARCH%
201+ call :run_ql " %TARGET_PROJ_CONFIG% %BUILD_FLAVOR% " %BUILD_ARCH%
202+ if " !CODEQL_FAILED! " EQU " 1" (
203+ set BUILD_FAILED = 1
204+ echo CodeQL - BUILD FAILED - Resolve problem and try again.
205+ goto :build_arch_done
206+ )
207+ echo CodeQL build for %BUILD_FILE% succeeded.
171208 ) else (
172209 echo CodeQL binary is missing!
210+ @ echo .
211+ )
212+ call :run_ca " %TARGET_PROJ_CONFIG% %BUILD_FLAVOR% " %BUILD_ARCH%
213+ if " !BUILD_FAILED! " EQU " 1" (
214+ echo Code Analysis BUILD FAILED.
215+ goto :build_arch_done
216+ )
217+ echo Code Analysis build for %BUILD_FILE% succeeded.
218+ echo .
219+ call :run_dvl " %TARGET_PROJ_CONFIG% %BUILD_FLAVOR% " %BUILD_ARCH%
220+ if " !BUILD_FAILED! " EQU " 1" (
221+ echo Driver Verifier Log BUILD FAILED.
222+ goto :build_arch_done
173223 )
174- call : runca " %TARGET_PROJ_CONFIG% %BUILD_FLAVOR% " %BUILD_ARCH%
175- call : rundvl " %TARGET_PROJ_CONFIG% %BUILD_FLAVOR% " %BUILD_ARCH%
224+ echo Driver Verifier Log build for %BUILD_FILE% succeeded.
225+ echo .
176226) else (
227+ rem Do a build without analysis.
177228 echo Building %BUILD_FILE% , configuration %TARGET_VS_CONFIG% , command %BUILD_COMMAND%
178- call :runbuild " %TARGET_PROJ_CONFIG% %BUILD_FLAVOR% " %BUILD_ARCH%
229+ call :run_build " %TARGET_PROJ_CONFIG% %BUILD_FLAVOR% " %BUILD_ARCH%
230+ if " !BUILD_FAILED! " EQU " 1" (
231+ echo NO-ANALYSIS BUILD FAILED.
232+ goto :build_arch_done
233+ )
234+ echo No-Analysis build for %BUILD_FILE% succeeded.
235+ echo .
179236)
237+ :build_arch_done
180238popd
181- endlocal
182-
183- IF ERRORLEVEL 1 (
184- set BUILD_FAILED = 1
239+ :build_arch_skip
240+ if not " !BUILD_FAILED! " == " " (
241+ goto :fail
185242)
243+ endlocal
186244goto :eof
187245
188- :runbuild:
246+ :run_build
189247:: %1 - configuration (as "Win10 Release")
190248:: %2 - platform (as x64)
191249:: %3 - build command (as "/Build")
192250set __TARGET__ = %BUILD_COMMAND:/ =%
193251:: (n)ormal(d)etailed,(disg)nostic
194252set __VERBOSITY__ = n
195- msbuild.exe -maxCpuCount %BUILD_FILE% /t:%__TARGET__% /p:Configuration=" %~1 " /P:Platform=%2 -fileLoggerParameters:Verbosity=%__VERBOSITY__% ;LogFile=%BUILD_LOG_FILE%
196- goto :eof
197-
198- :runsdv
199- echo " Removing previously created SDV artifacts"
200- rmdir /s/q sdv
201-
202- msbuild.exe -maxCpuCount %BUILD_FILE% /t:clean /p:Configuration=" %~1 " /P:Platform=%2
203-
204- IF ERRORLEVEL 1 (
253+ msbuild.exe -maxCpuCount %~dp1 %BUILD_FILE% /t:%__TARGET__% /p:Configuration=" %~1 " /P:Platform=%2 -fileLoggerParameters:Verbosity=%__VERBOSITY__% ;LogFile=%~dp1 %BUILD_LOG_FILE%
254+ if ERRORLEVEL 1 (
205255 set BUILD_FAILED = 1
206256)
257+ echo .
258+ goto :eof
207259
208- msbuild.exe -maxCpuCount %BUILD_FILE% /t:sdv /p:inputs=" /clean" /p:Configuration=" %~1 " /P:platform=%2
209-
210- IF ERRORLEVEL 1 (
211- set BUILD_FAILED = 1
260+ :run_sdv
261+ if exist sdv (
262+ echo " Removing previously created SDV artifacts"
263+ rmdir /s /q sdv
264+ echo .
212265)
213266
214- msbuild.exe -maxCpuCount %BUILD_FILE% /t:sdv /p:inputs=" /check /devenv" /p:Configuration=" %~1 " /P:platform=%2
215-
216- IF ERRORLEVEL 1 (
267+ if " !SDV_FAILED! " NEQ " 1" (
268+ echo Build - Cleaning for %BUILD_FILE% ...
269+ msbuild.exe -maxCpuCount %~dp1 %BUILD_FILE% /t:clean /p:Configuration=" %~1 " /P:Platform=%2
270+ if ERRORLEVEL 1 (
271+ set SDV_FAILED = 1
272+ )
273+ echo .
274+ )
275+ if " !SDV_FAILED! " NEQ " 1" (
276+ echo Build - Cleaning SDV for %BUILD_FILE% ...
277+ msbuild.exe -maxCpuCount %~dp1 %BUILD_FILE% /t:sdv /p:inputs=" /clean" /p:Configuration=" %~1 " /P:platform=%2
278+ if ERRORLEVEL 1 (
279+ set SDV_FAILED = 1
280+ )
281+ echo .
282+ )
283+ if " !SDV_FAILED! " NEQ " 1" (
284+ echo Build - Performing SDV checks for %BUILD_FILE% ...
285+ msbuild.exe -maxCpuCount %~dp1 %BUILD_FILE% /t:sdv /p:inputs=" /check /devenv" /p:Configuration=" %~1 " /P:platform=%2
286+ if ERRORLEVEL 1 (
287+ set SDV_FAILED = 1
288+ )
289+ echo .
290+ )
291+ if " !SDV_FAILED! " EQU " 1" (
217292 set BUILD_FAILED = 1
218293)
219-
220294goto :eof
221295
222- :runql
223-
224- echo " Removing previously created rules database"
225- rmdir /s/q codeql_db
296+ :run_ql
226297
227- echo call " %~dp0 \SetVsEnv.bat" %~1 > %~dp1 \codeql.build.bat
228- echo msbuild.exe -maxCpuCount %~dp1 \%BUILD_FILE% /t:rebuild /p:Configuration=" %~1 " /P:Platform=%2 >> %~dp1 \codeql.build.bat
298+ if exist %~dp1 codeql_db (
299+ echo CodeQL ^ : Removing previously created rules database...
300+ rmdir /s /q %~dp1 codeql_db
301+ )
229302
230- call %CODEQL_BIN% database create -l=cpp -s=%~dp1 -c " %~dp1 \codeql.build.bat" %~dp1 \codeql_db -j 0
303+ rem Prepare CodeQL build...
304+ echo call " %~dp0 SetVsEnv.bat" %~1 > %~dp1 codeql.build.bat
305+ echo msbuild.exe -maxCpuCount %~dp1 %BUILD_FILE% /t:rebuild /p:Configuration=" %~1 " /P:Platform=%2 >> %~dp1 codeql.build.bat
231306
232- IF ERRORLEVEL 1 (
307+ rem Create the CodeQL database...
308+ call %CODEQL_BIN% database create -l=cpp -s=%~dp1 -c " %~dp1 codeql.build.bat" %~dp1 codeql_db -j 0
309+ if ERRORLEVEL 1 (
233310 set CODEQL_FAILED = 1
234- set BUILD_FAILED = 1
235311)
236312
237313IF " %CODEQL_FAILED% " NEQ " 1" (
238- call %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-
241- IF ERRORLEVEL 1 (
242- set BUILD_FAILED = 1
314+ call %CODEQL_BIN% database analyze %~dp1 codeql_db %CODEQL_DRIVER_SUITES% \windows_driver_recommended.qls --format=sarifv2.1.0 --output=%~dp1 %BUILD_NAME% .sarif -j 0
315+ if ERRORLEVEL 1 (
316+ set CODEQL_FAILED = 1
317+ )
243318)
244-
245319goto :eof
246320
247- :runca
248- msbuild.exe -maxCpuCount %BUILD_FILE% /p:Configuration= " %~1 " /P:Platform= %2 /P:RunCodeAnalysisOnce=True -fileLoggerParameters:LogFile= %~dp1 \ %BUILD_NAME% .CodeAnalysis.log
249-
250- IF ERRORLEVEL 1 (
321+ :run_ca
322+ echo Performing Code Analysis build of %BUILD_FILE% .
323+ msbuild.exe -maxCpuCount %~dp1 %BUILD_FILE% /p:Configuration= " %~1 " /P:Platform= %2 /P:RunCodeAnalysisOnce=True -fileLoggerParameters:LogFile= %~dp1 %BUILD_NAME% .CodeAnalysis.log
324+ if ERRORLEVEL 1 (
251325 set BUILD_FAILED = 1
252326)
253-
254327goto :eof
255328
256- :rundvl
257- msbuild.exe -maxCpuCount %BUILD_FILE% /t:dvl /p:Configuration= " %~1 " /P:platform= %2
258-
329+ :run_dvl
330+ Performing Driver Verfier Log build of %BUILD_FILE% .
331+ msbuild.exe -maxCpuCount %~dp1 %BUILD_FILE% /t:dvl /p:Configuration= " %~1 " /P:platform= %2
259332IF ERRORLEVEL 1 (
260333 set BUILD_FAILED = 1
261334)
262-
263335goto :eof
264336
265337:split_target_tag
338+ set BUILD_INFO = %1
266339set TARGET =
267340set TAG =
268- for /f " tokens=1 delims=_" %%T in (%1 ) do (
269- set TARGET = %%T
270- )
271- for /f " tokens=2 delims=_ " %%T in ( %1 ) do (
272- set TAG = _ %%T
341+ for /f " tokens=1,2 delims=_" %%i in (%BUILD_INFO% ) do @ (
342+ set TARGET = %%i
343+ if not " %%j " == " " (
344+ set TAG = _ %%j
345+ )
273346)
274347goto :eof
275348
276349:fail
277-
278350exit /B 1
0 commit comments