diff --git a/build/build.bat b/build/build.bat index 35471a84e..2dc0be4c9 100644 --- a/build/build.bat +++ b/build/build.bat @@ -11,13 +11,16 @@ rem Debug, dbg, chk .. to build Debug rather than the default release fl rem amd64, x64, 64 .. to build only 64-bit driver rem x86, 32 .. to build only 32-bit driver rem /Option .. build command to pass to VS, for example /Rebuild -rem Win10 .. target OS version +rem Win10, Win11 .. target OS version rem rem By default the script performs an incremental build of both 32-bit and 64-bit rem release drivers for all supported target OSes. rem -rem To do a Static Driver Verifier build, append _SDV to the target OS version, for -rem example Win10_SDV. +rem To do a Static Driver Verifier build, append the _SDV tag to the target OS version, +rem for example Win10_SDV. Where SDV is deprecated, we rely on CodeQL, defaulting to +rem the WHCP_24H2 configuration. To use an earlier configuration specify WHCP_LEGACY. +rem We also continue to run Code Analysis (CA) and Driver Verifier Log (DVL) builds +rem for use with HCK / WHCP. rem ================================================================================ rem This is a list of supported build target specifications A_B where A is the @@ -36,8 +39,13 @@ set BUILD_FLAVOR=Release set BUILD_COMMAND=/Build set BUILD_SPEC= set BUILD_ARCH= +set BUILD_INFO= set BUILD_FAILED= +rem Analysis Build specific variables +set CODEQL_FAILED= +set SDV_FAILED= + rem Parse arguments :argloop shift /2 @@ -60,21 +68,27 @@ rem Assume that this is target OS version and split off the tag call :split_target_tag "%ARG%" rem Verify that this target OS is supported and valid -for %%N in (%SUPPORTED_BUILD_SPECS%) do ( +for %%N in (%SUPPORTED_BUILD_SPECS%) do @( set T=%%N set CANDIDATE_SPEC= set FOUND_MATCH= - for %%A in ("!T:_=" "!") do ( - if /I %%A=="%TARGET%" set CANDIDATE_SPEC=!T!!TAG! - for %%B in (%BUILD_TARGETS%) do ( - if /I %%B==%%~A!TAG! set FOUND_MATCH=1 + for %%A in ("!T:_=" "!") do @( + if /I %%A=="%TARGET%" ( + set CANDIDATE_SPEC=!T!!TAG! + ) + for %%B in (%BUILD_TARGETS%) do @( + if /I %%B==%%~A!TAG! ( + set FOUND_MATCH=1 + ) ) ) - if not "!FOUND_MATCH!"=="" if not "!CANDIDATE_SPEC!"=="" ( - set BUILD_SPEC=!CANDIDATE_SPEC! - goto :argloop + if not "!FOUND_MATCH!"=="" ( + if not "!CANDIDATE_SPEC!"=="" ( + set BUILD_SPEC=!CANDIDATE_SPEC! + goto :argloop + ) ) ) @@ -93,17 +107,18 @@ goto :eof rem Figure out which targets we're building :argend if "%BUILD_SPEC%"=="" ( - for %%B in (%BUILD_TARGETS%) do ( + for %%B in (%BUILD_TARGETS%) do @( call :split_target_tag "%%B" - for %%N in (%SUPPORTED_BUILD_SPECS%) do ( + for %%N in (%SUPPORTED_BUILD_SPECS%) do @( set T=%%N set BUILD_SPEC= - for %%A in ("!T:_=" "!") do ( - if /I %%A=="!TARGET!" set BUILD_SPEC=!T!!TAG! + for %%A in ("!T:_=" "!") do @( + if /I %%A=="!TARGET!" ( + set BUILD_SPEC=!T!!TAG! + ) ) if not "!BUILD_SPEC!"=="" ( call :build_target !BUILD_SPEC! - if not "!BUILD_FAILED!"=="" goto :fail ) ) ) @@ -116,163 +131,220 @@ rem Figure out which archs we're building :build_target if "%BUILD_ARCH%"=="" ( call :build_arch %1 x86 - if not "!BUILD_FAILED!"=="" goto :eof call :build_arch %1 amd64 ) else ( call :build_arch %1 %BUILD_ARCH% ) goto :eof -rem Invoke Visual Studio +rem Invoke Visual Studio and CodeQL as needed... :build_arch setlocal +set BUILD_INFO=%1 set BUILD_ARCH=%2 set TAG= -for /f "tokens=1 delims=_" %%T in ("%1") do ( - set TARGET_PROJ_CONFIG=%%T -) -for /f "tokens=2 delims=_" %%T in ("%1") do ( - set TARGET_PLATFORM=%%T -) -for /f "tokens=3 delims=_" %%T in ("%1") do ( - set TAG=%%T +for /f "tokens=1,2,3 delims=_" %%i in ("%BUILD_INFO%") do @( + set TARGET_PROJ_CONFIG=%%i + set TARGET_PLATFORM=%%j + set TAG=%%k ) if /I "!TAG!"=="SDV" ( rem There is no 32-bit SDV build - if %BUILD_ARCH%==x86 goto :eof + if %BUILD_ARCH%==x86 ( + goto :build_arch_skip + ) rem Check the SDV build suppression variable if not "%_BUILD_DISABLE_SDV%"=="" ( echo Skipping %TARGET_PROJ_CONFIG% SDV build because _BUILD_DISABLE_SDV is set - goto :eof + goto :build_arch_skip ) ) rem Compose build log file name -if %BUILD_FLAVOR%=="Debug" ( +if "%BUILD_FLAVOR%"=="Debug" ( set BUILD_LOG_FILE=buildchk ) else ( set BUILD_LOG_FILE=buildfre ) set BUILD_LOG_FILE=%BUILD_LOG_FILE%_%TARGET_PLATFORM%_%BUILD_ARCH%.log -if %BUILD_ARCH%==amd64 set BUILD_ARCH=x64 +if %BUILD_ARCH%==amd64 ( + set BUILD_ARCH=x64 +) set TARGET_VS_CONFIG="%TARGET_PROJ_CONFIG% %BUILD_FLAVOR%|%BUILD_ARCH%" +rem We set up the Build Environment and get started... +echo. pushd %BUILD_DIR% -call "%~dp0\SetVsEnv.bat" %TARGET_PROJ_CONFIG% +call "%~dp0SetVsEnv.bat" %TARGET_PROJ_CONFIG% +rem Split builds between Code Analysis and No-Analyis... if /I "!TAG!"=="SDV" ( - echo Running SDV for %BUILD_FILE%, configuration %TARGET_VS_CONFIG% - call :runsdv "%TARGET_PROJ_CONFIG% %BUILD_FLAVOR%" %BUILD_ARCH% + echo. + rem SDV is deprecated from Windows 11 24H2, both in the EWDK and WHCP. Making some allowances... + rem We only do SDV for Win10 targets. + if "%TARGET%"=="Win10" ( + echo Running SDV for %BUILD_FILE%, configuration %TARGET_VS_CONFIG% + call :run_sdv "%TARGET_PROJ_CONFIG% %BUILD_FLAVOR%" %BUILD_ARCH% + if "%BUILD_FAILED%" EQU "1" ( + echo Static Driver Verifier BUILD FAILED - Resolve problem and try again. + goto :build_arch_done + ) + echo Static Driver Verifier build for %BUILD_FILE% succeeded. + ) else ( + echo Skipping SDV for %BUILD_FILE%, configuration %TARGET_VS_CONFIG%. SDV is for WHCP_LEGACY targets ONLY. + echo. + ) if exist "%CODEQL_BIN%" ( echo Running CodeQL for %BUILD_FILE%, configuration %TARGET_VS_CONFIG% - call :runql "%TARGET_PROJ_CONFIG% %BUILD_FLAVOR%" %BUILD_ARCH% + call :run_ql "%TARGET_PROJ_CONFIG% %BUILD_FLAVOR%" %BUILD_ARCH% + if "!CODEQL_FAILED!" EQU "1" ( + set BUILD_FAILED=1 + echo CodeQL - BUILD FAILED - Resolve problem and try again. + goto :build_arch_done + ) + echo CodeQL build for %BUILD_FILE% succeeded. ) else ( echo CodeQL binary is missing! + @echo. + ) + call :run_ca "%TARGET_PROJ_CONFIG% %BUILD_FLAVOR%" %BUILD_ARCH% + if "!BUILD_FAILED!" EQU "1" ( + echo Code Analysis BUILD FAILED. + goto :build_arch_done + ) + echo Code Analysis build for %BUILD_FILE% succeeded. + echo. + call :run_dvl "%TARGET_PROJ_CONFIG% %BUILD_FLAVOR%" %BUILD_ARCH% + if "!BUILD_FAILED!" EQU "1" ( + echo Driver Verifier Log BUILD FAILED. + goto :build_arch_done ) - call :runca "%TARGET_PROJ_CONFIG% %BUILD_FLAVOR%" %BUILD_ARCH% - call :rundvl "%TARGET_PROJ_CONFIG% %BUILD_FLAVOR%" %BUILD_ARCH% + echo Driver Verifier Log build for %BUILD_FILE% succeeded. + echo. ) else ( + rem Do a build without analysis. echo Building %BUILD_FILE%, configuration %TARGET_VS_CONFIG%, command %BUILD_COMMAND% - call :runbuild "%TARGET_PROJ_CONFIG% %BUILD_FLAVOR%" %BUILD_ARCH% + call :run_build "%TARGET_PROJ_CONFIG% %BUILD_FLAVOR%" %BUILD_ARCH% + if "!BUILD_FAILED!" EQU "1" ( + echo NO-ANALYSIS BUILD FAILED. + goto :build_arch_done + ) + echo No-Analysis build for %BUILD_FILE% succeeded. + echo. ) +:build_arch_done popd -endlocal - -IF ERRORLEVEL 1 ( - set BUILD_FAILED=1 +:build_arch_skip +if not "!BUILD_FAILED!"=="" ( + goto :fail ) +endlocal goto :eof -:runbuild: +:run_build :: %1 - configuration (as "Win10 Release") :: %2 - platform (as x64) :: %3 - build command (as "/Build") set __TARGET__=%BUILD_COMMAND:/=% ::(n)ormal(d)etailed,(disg)nostic set __VERBOSITY__=n -msbuild.exe -maxCpuCount %BUILD_FILE% /t:%__TARGET__% /p:Configuration="%~1" /P:Platform=%2 -fileLoggerParameters:Verbosity=%__VERBOSITY__%;LogFile=%BUILD_LOG_FILE% -goto :eof - -:runsdv -echo "Removing previously created SDV artifacts" -rmdir /s/q sdv - -msbuild.exe -maxCpuCount %BUILD_FILE% /t:clean /p:Configuration="%~1" /P:Platform=%2 - -IF ERRORLEVEL 1 ( +msbuild.exe -maxCpuCount %~dp1%BUILD_FILE% /t:%__TARGET__% /p:Configuration="%~1" /P:Platform=%2 -fileLoggerParameters:Verbosity=%__VERBOSITY__%;LogFile=%~dp1%BUILD_LOG_FILE% +if ERRORLEVEL 1 ( set BUILD_FAILED=1 ) +echo. +goto :eof -msbuild.exe -maxCpuCount %BUILD_FILE% /t:sdv /p:inputs="/clean" /p:Configuration="%~1" /P:platform=%2 - -IF ERRORLEVEL 1 ( - set BUILD_FAILED=1 +:run_sdv +if exist sdv ( + echo "Removing previously created SDV artifacts" + rmdir /s /q sdv + echo. ) -msbuild.exe -maxCpuCount %BUILD_FILE% /t:sdv /p:inputs="/check /devenv" /p:Configuration="%~1" /P:platform=%2 - -IF ERRORLEVEL 1 ( +if "!SDV_FAILED!" NEQ "1" ( + echo Build - Cleaning for %BUILD_FILE%... + msbuild.exe -maxCpuCount %~dp1%BUILD_FILE% /t:clean /p:Configuration="%~1" /P:Platform=%2 + if ERRORLEVEL 1 ( + set SDV_FAILED=1 + ) + echo. +) +if "!SDV_FAILED!" NEQ "1" ( + echo Build - Cleaning SDV for %BUILD_FILE%... + msbuild.exe -maxCpuCount %~dp1%BUILD_FILE% /t:sdv /p:inputs="/clean" /p:Configuration="%~1" /P:platform=%2 + if ERRORLEVEL 1 ( + set SDV_FAILED=1 + ) + echo. +) +if "!SDV_FAILED!" NEQ "1" ( + echo Build - Performing SDV checks for %BUILD_FILE%... + msbuild.exe -maxCpuCount %~dp1%BUILD_FILE% /t:sdv /p:inputs="/check /devenv" /p:Configuration="%~1" /P:platform=%2 + if ERRORLEVEL 1 ( + set SDV_FAILED=1 + ) + echo. +) +if "!SDV_FAILED!" EQU "1" ( set BUILD_FAILED=1 ) - goto :eof -:runql - -echo "Removing previously created rules database" -rmdir /s/q codeql_db +:run_ql -echo call "%~dp0\SetVsEnv.bat" %~1 > %~dp1\codeql.build.bat -echo msbuild.exe -maxCpuCount %~dp1\%BUILD_FILE% /t:rebuild /p:Configuration="%~1" /P:Platform=%2 >> %~dp1\codeql.build.bat +if exist %~dp1codeql_db ( + echo CodeQL ^: Removing previously created rules database... + rmdir /s /q %~dp1codeql_db +) -call %CODEQL_BIN% database create -l=cpp -s=%~dp1 -c "%~dp1\codeql.build.bat" %~dp1\codeql_db -j 0 +rem Prepare CodeQL build... +echo call "%~dp0SetVsEnv.bat" %~1 > %~dp1codeql.build.bat +echo msbuild.exe -maxCpuCount %~dp1%BUILD_FILE% /t:rebuild /p:Configuration="%~1" /P:Platform=%2 >> %~dp1codeql.build.bat -IF ERRORLEVEL 1 ( +rem Create the CodeQL database... +call %CODEQL_BIN% database create -l=cpp -s=%~dp1 -c "%~dp1codeql.build.bat" %~dp1codeql_db -j 0 +if ERRORLEVEL 1 ( set CODEQL_FAILED=1 - set BUILD_FAILED=1 ) IF "%CODEQL_FAILED%" NEQ "1" ( - 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 -) - -IF ERRORLEVEL 1 ( - set BUILD_FAILED=1 + 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 + if ERRORLEVEL 1 ( + set CODEQL_FAILED=1 + ) ) - goto :eof -:runca -msbuild.exe -maxCpuCount %BUILD_FILE% /p:Configuration="%~1" /P:Platform=%2 /P:RunCodeAnalysisOnce=True -fileLoggerParameters:LogFile=%~dp1\%BUILD_NAME%.CodeAnalysis.log - -IF ERRORLEVEL 1 ( +:run_ca +echo Performing Code Analysis build of %BUILD_FILE%. +msbuild.exe -maxCpuCount %~dp1%BUILD_FILE% /p:Configuration="%~1" /P:Platform=%2 /P:RunCodeAnalysisOnce=True -fileLoggerParameters:LogFile=%~dp1%BUILD_NAME%.CodeAnalysis.log +if ERRORLEVEL 1 ( set BUILD_FAILED=1 ) - goto :eof -:rundvl -msbuild.exe -maxCpuCount %BUILD_FILE% /t:dvl /p:Configuration="%~1" /P:platform=%2 - +:run_dvl +Performing Driver Verfier Log build of %BUILD_FILE%. +msbuild.exe -maxCpuCount %~dp1%BUILD_FILE% /t:dvl /p:Configuration="%~1" /P:platform=%2 IF ERRORLEVEL 1 ( set BUILD_FAILED=1 ) - goto :eof :split_target_tag +set BUILD_INFO=%1 set TARGET= set TAG= -for /f "tokens=1 delims=_" %%T in (%1) do ( - set TARGET=%%T -) -for /f "tokens=2 delims=_" %%T in (%1) do ( - set TAG=_%%T +for /f "tokens=1,2 delims=_" %%i in (%BUILD_INFO%) do @( + set TARGET=%%i + if not "%%j"=="" ( + set TAG=_%%j + ) ) goto :eof :fail - exit /B 1 diff --git a/buildAll.bat b/buildAll.bat index ad4f5b44f..26396be1c 100755 --- a/buildAll.bat +++ b/buildAll.bat @@ -43,7 +43,7 @@ if errorlevel 1 goto :fail :nosdv2022 path %path%;C:\Program Files (x86)\Windows Kits\10\bin\x86\ -for %%D in (pciserial fwcfg packaging Q35) do ( +for %%D in (pciserial fwcfg Q35) do @( echo building also %%D pushd %%D call buildAll.bat @@ -51,15 +51,33 @@ for %%D in (pciserial fwcfg packaging Q35) do ( popd ) -for /R %%f in (*.dvl.xml) do call :process_xml %%f +echo. +echo Processing DVL files to create Windows 10 COMPAT ^(WIN10_RS1 ^/ 1607^) version... +for /R %%f in (*.dvl.xml) do @call :process_xml %%f +if "%found_dvl_xml%"=="" ( + echo WARNING ^: No DVL files were found. +) else ( + echo Processing of DVL files is complete. +) -exit /B 0 +:bld_success +echo. +echo BUILD COMPLETED SUCCESSFULLY. +call :leave 0 +goto :eof :fail - -exit /B 1 +echo BUILD FAILED. +set BUILD_FAILED= +call :leave 1 +goto :eof :process_xml -echo creating "%~dpn1-compat%~x1" +set found_dvl_xml=Yes +echo Creating %~dpn1-compat%~x1... findstr /v /c:"General.Checksum" "%~1" | findstr /v /c:".Semmle." > "%~dpn1-compat%~x1" goto :eof + +:leave +exit /B %1 +goto :eof :: never hit