Skip to content

Commit 360fc60

Browse files
benyamin-codezYanVugenfirer
authored andcommitted
[build] Basic fixes and extentions to build scripting
1. Fixed various syntax issues, including an unquoted variable in conditional test (Debug or Release log file name), superfluous backslashes, spaces between errorlevel tests and tested functions, MSBuild syntax consolidaiton, prefixing FOR do commands with @, etc. 2. Unwrapped nested IF statements to ensure no jumping out of loops or other unexpected behaviours. 3. Updated usage, including Win11 target and explanation regarding analysis builds (build.bat only). 4. Added analysis build specific variables CODEQL_FAILED and SDV_FAILED to init area (build.bat only). 5. Refactored fail code, removing return failure detection in favour of in-line failure detection. 6. Updated labels to use snake style notation. 7. Refactored end of build_arch function to avoide "goto :eof" and instead use ":build_arch_done" to ensure POPD occurs and ":build_arch_skip" to check for success before ending the local environment (build.bat only). 8. Do conditional (if exists) removal of sdv and codeql_db folders (build.bat only). 9. Additional commenting and stdout output (logging). 10. Remove superfluous newline spacing. 11. Removed packaging folder from build per PRs #1209 and #1224 (buildAll.bat only). 12. Consolidated exiting function (whether success or fail) to :leave (buildAll.bat only). Split from PR #1212. Signed-off-by: benyamin-codez <115509179+benyamin-codez@users.noreply.github.com>
1 parent 6808416 commit 360fc60

2 files changed

Lines changed: 186 additions & 96 deletions

File tree

build/build.bat

Lines changed: 162 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,16 @@ rem Debug, dbg, chk .. to build Debug rather than the default release fl
1111
rem amd64, x64, 64 .. to build only 64-bit driver
1212
rem x86, 32 .. to build only 32-bit driver
1313
rem /Option .. build command to pass to VS, for example /Rebuild
14-
rem Win10 .. target OS version
14+
rem Win10, Win11 .. target OS version
1515
rem
1616
rem By default the script performs an incremental build of both 32-bit and 64-bit
1717
rem release drivers for all supported target OSes.
1818
rem
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.
2124
rem ================================================================================
2225

2326
rem This is a list of supported build target specifications A_B where A is the
@@ -36,8 +39,13 @@ set BUILD_FLAVOR=Release
3639
set BUILD_COMMAND=/Build
3740
set BUILD_SPEC=
3841
set BUILD_ARCH=
42+
set BUILD_INFO=
3943
set BUILD_FAILED=
4044

45+
rem Analysis Build specific variables
46+
set CODEQL_FAILED=
47+
set SDV_FAILED=
48+
4149
rem Parse arguments
4250
:argloop
4351
shift /2
@@ -60,21 +68,27 @@ rem Assume that this is target OS version and split off the tag
6068
call :split_target_tag "%ARG%"
6169

6270
rem 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
93107
rem Figure out which targets we're building
94108
:argend
95109
if "%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
117132
if "%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
)
124138
goto :eof
125139

126-
rem Invoke Visual Studio
140+
rem Invoke Visual Studio and CodeQL as needed...
127141
:build_arch
128142
setlocal
143+
set BUILD_INFO=%1
129144
set BUILD_ARCH=%2
130145
set 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

141152
if /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

151164
rem 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
)
157170
set 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+
)
160175
set TARGET_VS_CONFIG="%TARGET_PROJ_CONFIG% %BUILD_FLAVOR%|%BUILD_ARCH%"
161176

177+
rem We set up the Build Environment and get started...
178+
echo.
162179
pushd %BUILD_DIR%
163-
call "%~dp0\SetVsEnv.bat" %TARGET_PROJ_CONFIG%
180+
call "%~dp0SetVsEnv.bat" %TARGET_PROJ_CONFIG%
164181

182+
rem Split builds between Code Analysis and No-Analyis...
165183
if /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
180238
popd
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
186244
goto :eof
187245

188-
:runbuild:
246+
:run_build
189247
:: %1 - configuration (as "Win10 Release")
190248
:: %2 - platform (as x64)
191249
:: %3 - build command (as "/Build")
192250
set __TARGET__=%BUILD_COMMAND:/=%
193251
::(n)ormal(d)etailed,(disg)nostic
194252
set __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-
220294
goto :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 %~dp1codeql_db (
299+
echo CodeQL ^: Removing previously created rules database...
300+
rmdir /s /q %~dp1codeql_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 "%~dp0SetVsEnv.bat" %~1 > %~dp1codeql.build.bat
305+
echo msbuild.exe -maxCpuCount %~dp1%BUILD_FILE% /t:rebuild /p:Configuration="%~1" /P:Platform=%2 >> %~dp1codeql.build.bat
231306

232-
IF ERRORLEVEL 1 (
307+
rem Create the CodeQL database...
308+
call %CODEQL_BIN% database create -l=cpp -s=%~dp1 -c "%~dp1codeql.build.bat" %~dp1codeql_db -j 0
309+
if ERRORLEVEL 1 (
233310
set CODEQL_FAILED=1
234-
set BUILD_FAILED=1
235311
)
236312

237313
IF "%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 %~dp1codeql_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-
245319
goto :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-
254327
goto :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
259332
IF ERRORLEVEL 1 (
260333
set BUILD_FAILED=1
261334
)
262-
263335
goto :eof
264336

265337
:split_target_tag
338+
set BUILD_INFO=%1
266339
set TARGET=
267340
set 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
)
274347
goto :eof
275348

276349
:fail
277-
278350
exit /B 1

0 commit comments

Comments
 (0)