Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 5 additions & 28 deletions .github/workflows/CI-unixish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -630,33 +630,10 @@ jobs:
make -C cmake.output autogen
make -C cmake.output gui-build-deps triage-build-ui-deps

- name: Check Config
run: |
./selfcheck.sh "--check-config"

- name: Self check
run: |
selfcheck_options="-q -j$(nproc) --std=c++11 --template=selfcheck --showtime=file-total -D__GNUC__ --error-exitcode=1 --inline-suppr --suppressions-list=.selfcheck_suppressions --library=gnu --inconclusive --enable=style,performance,portability,warning,missingInclude,information --exception-handling --debug-warnings --check-level=exhaustive"
cppcheck_options="-D__CPPCHECK__ -DCHECK_INTERNAL -DHAVE_RULES --library=cppcheck-lib -Ilib -Iexternals/simplecpp/ -Iexternals/tinyxml2"
gui_options="-DQT_VERSION=0x060000 -DQ_MOC_OUTPUT_REVISION=68 -DQT_CHARTS_LIB -DQT_MOC_HAS_STRINGDATA --library=qt"
ec=0

# TODO: add --check-config

# early exit
if [ $ec -eq 1 ]; then
exit $ec
fi

# self check externals
./cppcheck $selfcheck_options externals || ec=1
# self check lib/cli
mkdir b1
./cppcheck $selfcheck_options $cppcheck_options --cppcheck-build-dir=b1 --addon=naming.json frontend || ec=1
./cppcheck $selfcheck_options $cppcheck_options --cppcheck-build-dir=b1 --addon=naming.json -Ifrontend cli || ec=1
./cppcheck $selfcheck_options $cppcheck_options --cppcheck-build-dir=b1 --addon=naming.json --enable=internal lib || ec=1
# check gui with qt settings
mkdir b2
./cppcheck $selfcheck_options $cppcheck_options $gui_options --cppcheck-build-dir=b2 --addon=naming.json --suppress=simplifyUsing:*/moc_*.cpp -Icmake.output/gui -Ifrontend -Igui gui/*.cpp cmake.output/gui || ec=1
# self check test and tools
./cppcheck $selfcheck_options $cppcheck_options -Ifrontend -Icli test/*.cpp || ec=1
./cppcheck $selfcheck_options $cppcheck_options -Icli tools/dmake/*.cpp || ec=1
# triage
./cppcheck $selfcheck_options $cppcheck_options $gui_options -Icmake.output/tools/triage -Igui tools/triage/*.cpp cmake.output/tools/triage || ec=1
exit $ec
./selfcheck.sh
37 changes: 35 additions & 2 deletions lib/cppcheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1043,11 +1043,22 @@ unsigned int CppCheck::checkInternal(const FileWithDetails& file, const std::str
}

if (mSettings.checkConfiguration) {
for (const std::string &config : configurations)
std::string fixedpath = Path::toNativeSeparators(file.spath());
int checkConfig = 0;
// TODO: this logic differs from the actual one during analysis
// TODO: print invalid configurations
for (const std::string &config : configurations) {
if (!mSettings.quiet && (!config.empty() && configurations.size() > 1)) {
mErrorLogger.reportOut("Checking " + fixedpath + ": " + config + "...", Color::FgGreen);
}
(void)preprocessor.getcode(config, files, false);
if (++checkConfig > maxConfigs) {
skippedConfigurationMessage(fixedpath, config);
}
}

if (configurations.size() > maxConfigs)
tooManyConfigsError(Path::toNativeSeparators(file.spath()), configurations.size());
tooManyConfigsError(fixedpath, configurations.size());

if (analyzerInformation)
mLogger->setAnalyzerInfo(nullptr);
Expand Down Expand Up @@ -1187,6 +1198,7 @@ unsigned int CppCheck::checkInternal(const FileWithDetails& file, const std::str
if (!tokenizer.tokens())
continue;

// TODO: unreachable
// skip rest of iteration if just checking configuration
if (mSettings.checkConfiguration)
continue;
Expand Down Expand Up @@ -1687,6 +1699,26 @@ void CppCheck::purgedConfigurationMessage(const std::string &file, const std::st
mErrorLogger.reportErr(errmsg);
}

void CppCheck::skippedConfigurationMessage(const std::string &file, const std::string& configuration)
{
if (mSettings.severity.isEnabled(Severity::information) && file.empty())
return;

std::list<ErrorMessage::FileLocation> loclist;
if (!file.empty()) {
loclist.emplace_back(file, 0, 0);
}

ErrorMessage errmsg(std::move(loclist),
"",
Severity::information,
"The configuration '" + configuration + "' was not checked because it exceeded the threshold for maximum configuration to be checked.",
"skippedConfiguration",
Certainty::normal);

mErrorLogger.reportErr(errmsg);
}

//---------------------------------------------------------------------------

void CppCheck::getErrorMessages(ErrorLogger &errorlogger)
Expand All @@ -1697,6 +1729,7 @@ void CppCheck::getErrorMessages(ErrorLogger &errorlogger)

CppCheck cppcheck(settings, supprs, errorlogger, true, nullptr);
cppcheck.purgedConfigurationMessage("","");
cppcheck.skippedConfigurationMessage("","");
cppcheck.tooManyConfigsError("",0U);
// TODO: add functions to get remaining error messages

Expand Down
1 change: 1 addition & 0 deletions lib/cppcheck.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ class CPPCHECKLIB CppCheck {

private:
void purgedConfigurationMessage(const std::string &file, const std::string& configuration);
void skippedConfigurationMessage(const std::string &file, const std::string& configuration);

bool isPremiumCodingStandardId(const std::string& id) const;

Expand Down
31 changes: 31 additions & 0 deletions selfcheck.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/sh

selfcheck_options="-q -j$(nproc) --std=c++11 --template=selfcheck --showtime=file-total -D__GNUC__ --error-exitcode=1 --inline-suppr --suppressions-list=.selfcheck_suppressions --library=gnu --inconclusive --enable=style,performance,portability,warning,missingInclude,information --exception-handling --debug-warnings --check-level=exhaustive"
cppcheck_options="-D__CPPCHECK__ -DCHECK_INTERNAL -DHAVE_RULES --library=cppcheck-lib -Ilib -Iexternals/simplecpp/ -Iexternals/tinyxml2"
gui_options="-DQT_VERSION=0x060000 -DQ_MOC_OUTPUT_REVISION=68 -DQT_CHARTS_LIB -DQT_MOC_HAS_STRINGDATA --library=qt"
ec=0

if [ -n "$1" ]; then
selfcheck_options="$selfcheck_options $1"
fi

# self check externals
./cppcheck $selfcheck_options externals || ec=1
# self check lib/cli
mkdir b1
./cppcheck $selfcheck_options $cppcheck_options --cppcheck-build-dir=b1 --addon=naming.json frontend || ec=1
./cppcheck $selfcheck_options $cppcheck_options --cppcheck-build-dir=b1 --addon=naming.json -Ifrontend cli || ec=1
./cppcheck $selfcheck_options $cppcheck_options --cppcheck-build-dir=b1 --addon=naming.json --enable=internal lib || ec=1
# check gui with qt settings
mkdir b2
./cppcheck $selfcheck_options $cppcheck_options $gui_options --cppcheck-build-dir=b2 --addon=naming.json --suppress=simplifyUsing:*/moc_*.cpp -Icmake.output/gui -Ifrontend -Igui gui/*.cpp cmake.output/gui || ec=1
# self check test and tools
./cppcheck $selfcheck_options $cppcheck_options -Ifrontend -Icli test/*.cpp || ec=1
./cppcheck $selfcheck_options $cppcheck_options -Icli tools/dmake/*.cpp || ec=1
# triage
./cppcheck $selfcheck_options $cppcheck_options $gui_options -Icmake.output/tools/triage -Igui tools/triage/*.cpp cmake.output/tools/triage || ec=1

rm -rf b2
rm -rf b1

exit $ec