Skip to content

Commit 1078100

Browse files
[CI-NO-BUILD] [build] Extend ANSI colour palette to stdout
1. Extended ANSI colour palette to stdout 2. Update echo prints to use ANSI colour palette 3. Includes self-deleting scheduled task to clean build_log.txt of colour palette artefacts Split from PR #1212. Signed-off-by: benyamin-codez <[email protected]>
1 parent 2f49453 commit 1078100

File tree

4 files changed

+110
-35
lines changed

4 files changed

+110
-35
lines changed

build/build.bat

Lines changed: 48 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ if /I "%ARG%"=="32" set BUILD_ARCH=x86& goto :argloop
6464
if /I "%ARG%"=="x86" set BUILD_ARCH=x86& goto :argloop
6565
if /I "%ARG%"=="ARM64" set BUILD_ARCH=ARM64& goto :argloop
6666

67+
rem Enable ANSI palette support
68+
call :prepare_palette
69+
6770
rem Assume that this is target OS version and split off the tag
6871
call :split_target_tag "%ARG%"
6972

@@ -176,6 +179,7 @@ set TARGET_VS_CONFIG="%TARGET_PROJ_CONFIG% %BUILD_FLAVOR%|%BUILD_ARCH%"
176179

177180
rem We set up the Build Environment and get started...
178181
echo.
182+
call :clr_print %_c_Cyn% "Building : %BUILD_FILE%"
179183
pushd %BUILD_DIR%
180184
call "%~dp0SetVsEnv.bat" %TARGET_PROJ_CONFIG%
181185

@@ -192,53 +196,59 @@ if /I "!TAG!"=="SDV" (
192196
rem SDV is deprecated from Windows 11 24H2, both in the EWDK and WHCP. Making some allowances...
193197
rem We only do SDV for Win10 targets.
194198
if "%TARGET%"=="Win10" (
195-
echo Running SDV for %BUILD_FILE%, configuration %TARGET_VS_CONFIG%
199+
call :clr_print %_c_Cyn% "Running Static Driver Verifier build for %BUILD_FILE%."
200+
echo Configuration ^: %TARGET_VS_CONFIG%
196201
call :run_sdv "%TARGET_PROJ_CONFIG% %BUILD_FLAVOR%" %BUILD_ARCH%
197202
if "%BUILD_FAILED%" EQU "1" (
198-
echo Static Driver Verifier BUILD FAILED - Resolve problem and try again.
203+
call :clr_print %_c_Red% "Static Driver Verifier BUILD FAILED - Resolve problem and try again."
199204
goto :build_arch_done
200205
)
201-
echo Static Driver Verifier build for %BUILD_FILE% succeeded.
206+
call :clr_print %_c_Grn% "Static Driver Verifier build for %BUILD_FILE% succeeded."
202207
) else (
203-
echo Skipping SDV for %BUILD_FILE%, configuration %TARGET_VS_CONFIG%. SDV is for WHCP_LEGACY targets ONLY.
208+
call :clr_print %_c_Yel% "Skipping Static Driver Verifier for %BUILD_FILE%. SDV if for WHCP_LEGACY targets ONLY."
209+
echo Configuration ^: %TARGET_VS_CONFIG%
204210
echo.
205211
)
206212
if exist "%CODEQL_BIN%" (
207-
echo Running CodeQL for %BUILD_FILE%, configuration %TARGET_VS_CONFIG%
213+
call :clr_print %_c_Cyn% "CodeQL : Performing CodeQL build for %BUILD_FILE%."
214+
echo CodeQL ^: Configuration ^= %TARGET_VS_CONFIG%
208215
call :run_ql "%TARGET_PROJ_CONFIG% %BUILD_FLAVOR%" %BUILD_ARCH%
209216
if "!CODEQL_FAILED!" EQU "1" (
210217
set BUILD_FAILED=1
211-
echo CodeQL - BUILD FAILED - Resolve problem and try again.
218+
call :clr_print %_c_Red% "CodeQL : BUILD FAILED" %_c_Wht% " - Resolve problem and try again."
212219
goto :build_arch_done
213220
)
214-
echo CodeQL build for %BUILD_FILE% succeeded.
221+
call :clr_print %_c_Grn% "CodeQL build for %BUILD_FILE% succeeded."
215222
) else (
216-
echo CodeQL binary is missing!
223+
call :clr_print %_c_Yel% "CodeQL binary is missing!"
217224
@echo.
218225
)
219226
call :run_ca "%TARGET_PROJ_CONFIG% %BUILD_FLAVOR%" %BUILD_ARCH%
220227
if "!BUILD_FAILED!" EQU "1" (
221-
echo Code Analysis BUILD FAILED.
228+
call :clr_print %_c_Red% "Code Analysis BUILD FAILED."
222229
goto :build_arch_done
223230
)
224-
echo Code Analysis build for %BUILD_FILE% succeeded.
231+
call :clr_print %_c_Grn% "Code Analysis build for %BUILD_FILE% succeeded."
225232
echo.
226233
call :run_dvl "%TARGET_PROJ_CONFIG% %BUILD_FLAVOR%" %BUILD_ARCH%
227234
if "!BUILD_FAILED!" EQU "1" (
228-
echo Driver Verifier Log BUILD FAILED.
235+
call :clr_print %_c_Red% "Driver Verifier Log BUILD FAILED."
229236
goto :build_arch_done
230237
)
231-
echo Driver Verifier Log build for %BUILD_FILE% succeeded.
238+
call :clr_print %_c_Grn% "Driver Verifier Log build for %BUILD_FILE% succeeded."
232239
echo.
233240
) else (
234241
rem Do a build without analysis.
235-
echo Building %BUILD_FILE%, configuration %TARGET_VS_CONFIG%, command %BUILD_COMMAND%
242+
call :clr_print %_c_Cyn% "Performing No-Analysis build for %BUILD_FILE%."
243+
@echo Configuration ^= %TARGET_VS_CONFIG%
244+
@echo Command ^= %BUILD_COMMAND%
245+
@echo.
236246
call :run_build "%TARGET_PROJ_CONFIG% %BUILD_FLAVOR%" %BUILD_ARCH%
237247
if "!BUILD_FAILED!" EQU "1" (
238-
echo NO-ANALYSIS BUILD FAILED.
248+
call :clr_print %_c_Red% "NO-ANALYSIS BUILD FAILED."
239249
goto :build_arch_done
240250
)
241-
echo No-Analysis build for %BUILD_FILE% succeeded.
251+
call :clr_print %_c_Grn% "No-Analysis build for %BUILD_FILE% succeeded."
242252
echo.
243253
)
244254
:build_arch_done
@@ -266,29 +276,29 @@ goto :eof
266276

267277
:run_sdv
268278
if exist sdv (
269-
echo "Removing previously created SDV artifacts"
279+
call :clr_print %_c_Cyn% "Removing previously created SDV artifacts..."
270280
rmdir /s /q sdv
271281
echo.
272282
)
273283

274284
if "!SDV_FAILED!" NEQ "1" (
275-
echo Build - Cleaning for %BUILD_FILE%...
285+
call :clr_print %_c_Cyn% "Build: Cleaning for %BUILD_FILE%..."
276286
msbuild.exe -maxCpuCount %~dp1%BUILD_FILE% /t:clean /p:Configuration="%~1" /P:Platform=%2
277287
if ERRORLEVEL 1 (
278288
set SDV_FAILED=1
279289
)
280290
echo.
281291
)
282292
if "!SDV_FAILED!" NEQ "1" (
283-
echo Build - Cleaning SDV for %BUILD_FILE%...
293+
call :clr_print %_c_Cyn% "Build: Cleaning SDV for %BUILD_FILE%..."
284294
msbuild.exe -maxCpuCount %~dp1%BUILD_FILE% /t:sdv /p:inputs="/clean" /p:Configuration="%~1" /P:platform=%2
285295
if ERRORLEVEL 1 (
286296
set SDV_FAILED=1
287297
)
288298
echo.
289299
)
290300
if "!SDV_FAILED!" NEQ "1" (
291-
echo Build - Performing SDV checks for %BUILD_FILE%...
301+
call :clr_print %_c_Cyn% "Build: Performing SDV checks for %BUILD_FILE%..."
292302
msbuild.exe -maxCpuCount %~dp1%BUILD_FILE% /t:sdv /p:inputs="/check /devenv" /p:Configuration="%~1" /P:platform=%2
293303
if ERRORLEVEL 1 (
294304
set SDV_FAILED=1
@@ -303,7 +313,7 @@ goto :eof
303313
:run_ql
304314

305315
if exist %~dp1codeql_db (
306-
echo CodeQL ^: Removing previously created rules database...
316+
call :clr_print %_c_Cyn% "CodeQL : Removing previously created rules database..."
307317
rmdir /s /q %~dp1codeql_db
308318
)
309319

@@ -326,15 +336,15 @@ IF "%CODEQL_FAILED%" NEQ "1" (
326336
goto :eof
327337

328338
:run_ca
329-
echo Performing Code Analysis build of %BUILD_FILE%.
339+
call :clr_print %_c_Cyn% "Performing Code Analysis build of %BUILD_FILE%."
330340
msbuild.exe -maxCpuCount %~dp1%BUILD_FILE% /p:Configuration="%~1" /P:Platform=%2 /P:RunCodeAnalysisOnce=True -fileLoggerParameters:LogFile=%~dp1%BUILD_NAME%.CodeAnalysis.log
331341
if ERRORLEVEL 1 (
332342
set BUILD_FAILED=1
333343
)
334344
goto :eof
335345

336346
:run_dvl
337-
echo Performing Driver Verfier Log build of %BUILD_FILE%.
347+
call :clr_print %_c_Cyn% "Performing Driver Verfier Log build of %BUILD_FILE%."
338348
msbuild.exe -maxCpuCount %~dp1%BUILD_FILE% /t:dvl /p:Configuration="%~1" /P:platform=%2
339349
IF ERRORLEVEL 1 (
340350
set BUILD_FAILED=1
@@ -353,5 +363,21 @@ for /f "tokens=1,2 delims=_" %%i in (%BUILD_INFO%) do @(
353363
)
354364
goto :eof
355365

366+
:clr_print
367+
@echo %z_esc%[%~1%~2%z_esc%[%~3%~4%z_esc%[%~5%~6%z_esc%[%~7%~8%z_esc%[0m
368+
goto :eof
369+
370+
:prepare_palette
371+
rem Colour mods should work from WIN10_TH2
372+
rem Get the ANSI ESC character [0x27]
373+
for /f "tokens=2 usebackq delims=#" %%i in (`"prompt #$H#$E# & echo on & for %%i in (1) do rem"`) do @set z_esc=%%i
374+
rem Prepare pallette
375+
set "_c_Red="40;91m""
376+
set "_c_Grn="40;92m""
377+
set "_c_Yel="40;93m""
378+
set "_c_Cyn="40;96m""
379+
set "_c_Wht="40;37m""
380+
goto :eof
381+
356382
:fail
357383
exit /B 1

build/clean_build_log.bat

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
@echo off
2+
cd /d %~dp0
3+
cd ..
4+
if not exist ".\build_log.txt" goto :eof
5+
setlocal
6+
Title Clean Build Log
7+
echo Cleaning Build Log...
8+
timeout 3 1> nul 2>&1
9+
for /f "tokens=2 usebackq delims=#" %%i in (`"prompt #$H#$E# & echo on & for %%i in (1) do rem"`) do @set z_esc=%%i
10+
@PowerShell "(GC .\build_log.txt)|%%{$_ -Replace '%z_esc%\[0m',''}|SC .\build_log.txt"
11+
@PowerShell "(GC .\build_log.txt)|%%{$_ -Replace '%z_esc%\[40\;91m',''}|SC .\build_log.txt"
12+
@PowerShell "(GC .\build_log.txt)|%%{$_ -Replace '%z_esc%\[40\;92m',''}|SC .\build_log.txt"
13+
@PowerShell "(GC .\build_log.txt)|%%{$_ -Replace '%z_esc%\[40\;93m',''}|SC .\build_log.txt"
14+
@PowerShell "(GC .\build_log.txt)|%%{$_ -Replace '%z_esc%\[40\;96m',''}|SC .\build_log.txt"
15+
@PowerShell "(GC .\build_log.txt)|%%{$_ -Replace '%z_esc%\[40\;37m',''}|SC .\build_log.txt"
16+
@PowerShell "(GC .\build_log.txt)|%%{$_ -Replace '%z_esc%\[',''}|SC .\build_log.txt"
17+
echo Build Log successfully cleaned.
18+
echo Removing scheduled task...
19+
schtasks /delete /tn build_log_cleanup /f
20+
timeout 5
21+
endlocal

build/prebuild_x86_libs.bat

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ if "%VIOSOCK_PREBUILD_X86_LIBS%" EQU "1" (
3333
rem Check for x86 viosock libraries and build them if needed...
3434
if not exist "%BUILD_DIR%viosock\lib\x86\%TARGET%%BUILD_FLAVOR%\viosocklib.dll" (
3535
echo.
36-
echo ATTENTION ^: Need to build x86 viosock libraries before building for amd64...
36+
call :clr_print %_c_Yel% "ATTENTION : Need to build x86 viosock libraries before building for amd64..."
3737
setlocal
3838
set VIRTIO_WIN_NO_ARM=1
3939
if "%BUILD_FILE%"=="virtio-win.sln" (
@@ -50,11 +50,15 @@ if "%VIOSOCK_PREBUILD_X86_LIBS%" EQU "1" (
5050
if "%BUILD_FAILED%" EQU "1" (
5151
exit /B 1
5252
)
53-
echo Successfully built the x86 viosock libraries.
53+
call :clr_print %_c_Grn% "Successfully built the x86 viosock libraries."
54+
call :clr_print %_c_Cyn% "Continuing with amd64 build..."
5455
echo.
55-
echo Continuing with amd64 build...
5656
endlocal
5757
)
5858
)
5959
)
6060
goto :eof
61+
62+
:clr_print
63+
@echo %z_esc%[%~1%~2%z_esc%[%~3%~4%z_esc%[%~5%~6%z_esc%[%~7%~8%z_esc%[0m
64+
goto :eof

buildAll.bat

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,46 +39,47 @@ if errorlevel 1 goto :fail
3939
call build\build.bat viomem\sys\viomem.vcxproj "Win10_SDV Win11_SDV" %*
4040
if errorlevel 1 goto :fail
4141

42-
4342
:nosdv2022
4443

44+
call :prepare_palette
45+
4546
path %path%;C:\Program Files (x86)\Windows Kits\10\bin\x86\
4647
for %%D in (pciserial fwcfg Q35) do @(
4748
call :bld_inf_drvr %%D
4849
)
4950
echo.
50-
echo Processing DVL files to create Windows 10 COMPAT ^(WIN10_RS1 ^/ 1607^) version...
51+
call :clr_print %_c_Cyn% "Processing DVL files to create Windows 10, version 1607, WIN10_RS1 COMPAT version..."
5152
for /R %%f in (*.dvl.xml) do @(
5253
call :process_xml %%f
5354
)
5455
if "%found_dvl_xml%"=="" (
55-
echo WARNING ^: No DVL files were found.
56+
call :clr_print %_c_Yel% "WARNING : No DVL files were found."
5657
) else (
57-
echo Processing of DVL files is complete.
58+
call :clr_print %_c_Cyn% "Processing of DVL files is complete."
5859
)
5960
:bld_success
6061
echo.
61-
echo BUILD COMPLETED SUCCESSFULLY.
62+
call :clr_print %_c_Grn% "BUILD COMPLETED SUCCESSFULLY."
6263
call :leave 0
6364
goto :eof
6465

6566
:fail
66-
echo BUILD FAILED.
67+
call :clr_print %_c_Red% "BUILD FAILED."
6768
set BUILD_FAILED=
6869
call :leave 1
6970
goto :eof
7071

7172
:bld_inf_drvr
7273
set inf_drv=%~1
7374
echo.
74-
echo Building : %inf_drv%%
75+
call :clr_print %_c_Cyn% "Building : %inf_drv%"
7576
echo.
7677
pushd %inf_drv%
7778
call buildAll.bat
7879
if not errorlevel==0 (
7980
goto :fail
8081
)
81-
echo Build for %inf_drv% succeeded.
82+
call :clr_print %_c_Grn% "Build for %inf_drv% succeeded."
8283
popd
8384
goto :eof
8485

@@ -89,15 +90,38 @@ if not exist "%dvl_file%" (
8990
call :fudge_xml %1
9091
) else (
9192
rem Here we retain the Windows 10 version 1607, WIN10_RS1, build 14393 COMPAT DVL.
92-
echo The file already exists : %dvl_file%
93+
call :clr_print %_c_Grn% "The file already exists : %dvl_file%"
9394
)
9495
goto :eof
9596

9697
:fudge_xml
9798
rem Here we create a Windows 10 version 1607, WIN10_RS1, build 14393 COMPAT DVL.
98-
echo Auto-magically creating : %dvl_file%
99+
call :clr_print %_c_Yel% "Auto-magically creating : %dvl_file%"
99100
findstr /v /c:"General.Checksum" "%~1" | findstr /v /c:".Semmle." > "%dvl_file%"
100101
goto :eof
101102

103+
:clr_print
104+
echo %z_esc%[%~1%~2%z_esc%[%~3%~4%z_esc%[%~5%~6%z_esc%[%~7%~8%z_esc%[0m
105+
goto :eof
106+
107+
:prepare_palette
108+
rem Colour mods should work from WIN10_TH2
109+
rem Get the ANSI ESC character: 0x27
110+
for /f "tokens=2 usebackq delims=#" %%i in (`"prompt #$H#$E# & echo on & for %%i in (1) do rem"`) do @(
111+
set z_esc=%%i
112+
)
113+
rem Prepare pallette
114+
set "_c_Red="40;91m""
115+
set "_c_Grn="40;92m""
116+
set "_c_Yel="40;93m""
117+
set "_c_Cyn="40;96m""
118+
set "_c_Wht="40;37m""
119+
goto :eof
120+
102121
:leave
122+
if exist ".\build_log.txt" (
123+
call schtasks /create /tn build_log_cleanup /tr "%comspec% /c %~dp0build\clean_build_log.bat" /sc ONCE /sd 01/01/1910 /st 00:00 1> nul 2>&1
124+
call schtasks /run /tn build_log_cleanup 1> nul 2>&1
125+
)
126+
endlocal
103127
exit /B %1

0 commit comments

Comments
 (0)