Skip to content

Commit 8dc1fa7

Browse files
authored
Add colors to CLI reporting (cppcheck-opensource#3304)
1 parent 7e70a91 commit 8dc1fa7

27 files changed

Lines changed: 282 additions & 156 deletions

.github/workflows/CI-windows.yml

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -90,18 +90,27 @@ jobs:
9090
windeployqt Build\gui || exit /b !errorlevel!
9191
del Build\gui\cppcheck-gui.ilk || exit /b !errorlevel!
9292
del Build\gui\cppcheck-gui.pdb || exit /b !errorlevel!
93-
94-
- name: Build CLI debug configuration using MSBuild
93+
94+
- name: Configure MSBuild
9595
run: |
9696
call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Auxiliary\Build\vcvarsall.bat" ${{ matrix.arch }} || exit /b !errorlevel!
9797
set ARCH=${{ matrix.arch }}
9898
if "${{ matrix.arch }}" == "x86" (
9999
set ARCH=Win32
100100
)
101-
msbuild -m cppcheck.sln /p:Configuration=Debug-PCRE;Platform=%ARCH% -maxcpucount || exit /b !errorlevel!
101+
rm -rf build
102+
mkdir build
103+
cd build
104+
cmake -DBUILD_TESTS=On ..
102105
103-
- name: Run Debug test
104-
run: .\bin\debug\testrunner.exe || exit /b !errorlevel!
106+
- name: Build CLI debug configuration using MSBuild
107+
run: |
108+
call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Auxiliary\Build\vcvarsall.bat" ${{ matrix.arch }} || exit /b !errorlevel!
109+
set ARCH=${{ matrix.arch }}
110+
if "${{ matrix.arch }}" == "x86" (
111+
set ARCH=Win32
112+
)
113+
cmake --build build --target check --config Debug
105114
106115
- name: Build CLI release configuration using MSBuild
107116
run: |
@@ -110,16 +119,12 @@ jobs:
110119
if "${{ matrix.arch }}" == "x86" (
111120
set ARCH=Win32
112121
)
113-
msbuild -m cppcheck.sln /p:Configuration=Release-PCRE;Platform=%ARCH% -maxcpucount || exit /b !errorlevel!
114-
115-
- name: Run Release test
116-
run: .\bin\testrunner.exe || exit /b !errorlevel!
122+
cmake --build build --target check --config Release
117123
118124
- name: Run test/cli
119125
run: |
120126
:: since FILESDIR is not set copy the binary to the root so the addons are found
121-
copy .\bin\cppcheck.exe .\cppcheck.exe || exit /b !errorlevel!
122-
copy .\bin\cppcheck-core.dll .\cppcheck-core.dll || exit /b !errorlevel!
127+
copy .\build\bin\Release\cppcheck.exe .\cppcheck.exe || exit /b !errorlevel!
123128
cd test/cli || exit /b !errorlevel!
124129
python -m pytest --suppress-no-test-exit-code test-clang-import.py || exit /b !errorlevel!
125130
python -m pytest test-helloworld.py || exit /b !errorlevel!

Makefile

Lines changed: 96 additions & 92 deletions
Large diffs are not rendered by default.

appveyor.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,11 @@ build_script:
4141
- ECHO Building %configuration% %platform% with MSVC %VisualStudioVersion% using %PlatformToolset% PlatformToolset
4242
- 'CALL "C:\Program Files (x86)\Microsoft Visual Studio %VisualStudioVersion%\VC\vcvarsall.bat" %vcvarsall_platform%'
4343
# Visual studio project..
44-
- msbuild "cppcheck.sln" /consoleloggerparameters:Verbosity=minimal /target:Build /property:Configuration="%configuration%";Platform=%platform% /p:PlatformToolset=%PlatformToolset% /maxcpucount /logger:"C:\Program Files\AppVeyor\BuildAgent\Appveyor.MSBuildLogger.dll"
44+
- mkdir vsbuild
45+
- cd vsbuild
46+
- cmake -DBUILD_TESTS=ON -DCTEST_TIMEOUT=240 ..
47+
- cmake --build . --target check --config %configuration%
48+
- cd ..
4549
# the following builds are Debug ones so do not perform them in Release jobs
4650
- 'IF "%configuration%" == "Release" exit /b 0'
4751
# use all available processes for nmake

cli/cmdlineparser.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -840,8 +840,8 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[])
840840
}
841841

842842
if (mSettings->templateFormat == "gcc") {
843-
mSettings->templateFormat = "{file}:{line}:{column}: warning: {message} [{id}]\\n{code}";
844-
mSettings->templateLocation = "{file}:{line}:{column}: note: {info}\\n{code}";
843+
mSettings->templateFormat = "{bold}{file}:{line}:{column}: {magenta}warning:{default} {message} [{id}]{reset}\\n{code}";
844+
mSettings->templateLocation = "{bold}{file}:{line}:{column}: {dim}note:{reset} {info}\\n{code}";
845845
} else if (mSettings->templateFormat == "daca2") {
846846
mSettings->daca = true;
847847
mSettings->templateFormat = "{file}:{line}:{column}: {severity}:{inconclusive:inconclusive:} {message} [{id}]";
@@ -922,9 +922,9 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[])
922922

923923
// Default template format..
924924
if (mSettings->templateFormat.empty()) {
925-
mSettings->templateFormat = "{file}:{line}:{column}: {severity}:{inconclusive:inconclusive:} {message} [{id}]\\n{code}";
925+
mSettings->templateFormat = "{bold}{file}:{line}:{column}: {red}{inconclusive:{magenta}}{severity}:{inconclusive: inconclusive:}{default} {message} [{id}]{reset}\\n{code}";
926926
if (mSettings->templateLocation.empty())
927-
mSettings->templateLocation = "{file}:{line}:{column}: note: {info}\\n{code}";
927+
mSettings->templateLocation = "{bold}{file}:{line}:{column}: {dim}note:{reset} {info}\\n{code}";
928928
}
929929

930930
mSettings->project.ignorePaths(mIgnoredPaths);

cli/cppcheckexecutor.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
#include "analyzerinfo.h"
2222
#include "cmdlineparser.h"
23+
#include "color.h"
2324
#include "config.h"
2425
#include "cppcheck.h"
2526
#include "filelister.h"
@@ -1046,9 +1047,9 @@ void CppCheckExecutor::reportErr(const std::string &errmsg)
10461047
}
10471048
}
10481049

1049-
void CppCheckExecutor::reportOut(const std::string &outmsg)
1050+
void CppCheckExecutor::reportOut(const std::string &outmsg, Color c)
10501051
{
1051-
std::cout << ansiToOEM(outmsg, true) << std::endl;
1052+
std::cout << c << ansiToOEM(outmsg, true) << Color::Reset << std::endl;
10521053
}
10531054

10541055
void CppCheckExecutor::reportProgress(const std::string &filename, const char stage[], const std::size_t value)
@@ -1087,7 +1088,7 @@ void CppCheckExecutor::reportStatus(std::size_t fileindex, std::size_t filecount
10871088
oss << fileindex << '/' << filecount
10881089
<< " files checked " << percentDone
10891090
<< "% done";
1090-
std::cout << oss.str() << std::endl;
1091+
std::cout << Color::FgBlue << oss.str() << Color::Reset << std::endl;
10911092
}
10921093
}
10931094

cli/cppcheckexecutor.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#ifndef CPPCHECKEXECUTOR_H
2020
#define CPPCHECKEXECUTOR_H
2121

22+
#include "color.h"
2223
#include "errorlogger.h"
2324

2425
#include <cstdio>
@@ -69,7 +70,7 @@ class CppCheckExecutor : public ErrorLogger {
6970
*
7071
* @param outmsg Progress message e.g. "Checking main.cpp..."
7172
*/
72-
void reportOut(const std::string &outmsg) OVERRIDE;
73+
void reportOut(const std::string &outmsg, Color c = Color::Reset) OVERRIDE;
7374

7475
/** xml output of errors */
7576
void reportErr(const ErrorMessage &msg) OVERRIDE;

cli/threadexecutor.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
#include "threadexecutor.h"
2020

21+
#include "color.h"
2122
#include "config.h"
2223
#include "cppcheck.h"
2324
#include "cppcheckexecutor.h"
@@ -340,9 +341,9 @@ void ThreadExecutor::writeToPipe(PipeSignal type, const std::string &data)
340341
delete [] out;
341342
}
342343

343-
void ThreadExecutor::reportOut(const std::string &outmsg)
344+
void ThreadExecutor::reportOut(const std::string &outmsg, Color c)
344345
{
345-
writeToPipe(REPORT_OUT, outmsg);
346+
writeToPipe(REPORT_OUT, ::toString(c) + outmsg + ::toString(Color::Reset));
346347
}
347348

348349
void ThreadExecutor::reportErr(const ErrorMessage &msg)
@@ -504,11 +505,11 @@ unsigned int __stdcall ThreadExecutor::threadProc(void *args)
504505
return result;
505506
}
506507

507-
void ThreadExecutor::reportOut(const std::string &outmsg)
508+
void ThreadExecutor::reportOut(const std::string &outmsg, Color c)
508509
{
509510
EnterCriticalSection(&mReportSync);
510511

511-
mErrorLogger.reportOut(outmsg);
512+
mErrorLogger.reportOut(outmsg, c);
512513

513514
LeaveCriticalSection(&mReportSync);
514515
}
@@ -571,7 +572,7 @@ unsigned int ThreadExecutor::check()
571572
return 0;
572573
}
573574

574-
void ThreadExecutor::reportOut(const std::string &/*outmsg*/)
575+
void ThreadExecutor::reportOut(const std::string &/*outmsg*/, Color)
575576
{
576577

577578
}

cli/threadexecutor.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#ifndef THREADEXECUTOR_H
2020
#define THREADEXECUTOR_H
2121

22+
#include "color.h"
2223
#include "config.h"
2324
#include "errorlogger.h"
2425

@@ -53,7 +54,7 @@ class ThreadExecutor : public ErrorLogger {
5354
void operator=(const ThreadExecutor &) = delete;
5455
unsigned int check();
5556

56-
void reportOut(const std::string &outmsg) OVERRIDE;
57+
void reportOut(const std::string &outmsg, Color c) OVERRIDE;
5758
void reportErr(const ErrorMessage &msg) OVERRIDE;
5859
void reportInfo(const ErrorMessage &msg) OVERRIDE;
5960
void bughuntingReport(const std::string &str) OVERRIDE;

gui/newsuppressiondialog.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "newsuppressiondialog.h"
22
#include "ui_newsuppressiondialog.h"
33
#include "cppcheck.h"
4+
#include "color.h"
45
#include "errorlogger.h"
56
#include "suppressions.h"
67

@@ -12,7 +13,7 @@ NewSuppressionDialog::NewSuppressionDialog(QWidget *parent) :
1213

1314
class QErrorLogger : public ErrorLogger {
1415
public:
15-
void reportOut(const std::string &/*outmsg*/) override {}
16+
void reportOut(const std::string &/*outmsg*/, Color) override {}
1617
void reportErr(const ErrorMessage &msg) override {
1718
errorIds << QString::fromStdString(msg.id);
1819
}

gui/threadresult.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ ThreadResult::~ThreadResult()
3333
//dtor
3434
}
3535

36-
void ThreadResult::reportOut(const std::string &outmsg)
36+
void ThreadResult::reportOut(const std::string &outmsg, Color)
3737
{
3838
emit log(QString::fromStdString(outmsg));
3939
}

0 commit comments

Comments
 (0)