Skip to content
Merged
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
218 changes: 109 additions & 109 deletions Makefile

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion cli/cmdlineparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1073,7 +1073,7 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[])
mPathNames = project.guiProject.pathNames;

if (!project.fileSettings.empty())
mSettings.fileSettings = project.fileSettings;
mFileSettings = project.fileSettings;

// Use paths _pathnames if no base paths for relative path output are given
if (mSettings.basePaths.empty() && mSettings.relativePaths)
Expand Down
10 changes: 10 additions & 0 deletions cli/cmdlineparser.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@
#define CMDLINE_PARSER_H

#include <cstddef>
#include <list>
#include <string>
#include <vector>

#include "cmdlinelogger.h"
#include "filesettings.h"
#include "utils.h"

class Settings;
Expand Down Expand Up @@ -80,6 +82,13 @@ class CmdLineParser {
return mPathNames;
}

/**
* Return the file settings read from command line.
*/
const std::list<FileSettings>& getFileSettings() const {
return mFileSettings;
}

/**
* Return if we should exit after printing version, help etc.
*/
Expand Down Expand Up @@ -124,6 +133,7 @@ class CmdLineParser {
CmdLineLogger &mLogger;

std::vector<std::string> mPathNames;
std::list<FileSettings> mFileSettings;
std::vector<std::string> mIgnoredPaths;
Settings &mSettings;
Suppressions &mSuppressions;
Expand Down
39 changes: 20 additions & 19 deletions cli/cppcheckexecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,26 +187,27 @@ bool CppCheckExecutor::parseFromArgs(Settings &settings, int argc, const char* c
}

const std::vector<std::string>& pathnames = parser.getPathNames();
const std::list<FileSettings>& fileSettings = parser.getFileSettings();

#if defined(_WIN32)
// For Windows we want case-insensitive path matching
const bool caseSensitive = false;
#else
const bool caseSensitive = true;
#endif
if (!settings.fileSettings.empty() && !settings.fileFilters.empty()) {
// filter only for the selected filenames from all project files
std::list<FileSettings> newList;

const std::list<FileSettings>& fileSettings = settings.fileSettings;
std::copy_if(fileSettings.cbegin(), fileSettings.cend(), std::back_inserter(newList), [&](const FileSettings& fs) {
return matchglobs(settings.fileFilters, fs.filename);
});
if (!newList.empty())
settings.fileSettings = newList;
if (!fileSettings.empty()) {
if (!settings.fileFilters.empty()) {
// filter only for the selected filenames from all project files
std::copy_if(fileSettings.cbegin(), fileSettings.cend(), std::back_inserter(mFileSettings), [&](const FileSettings &fs) {
return matchglobs(settings.fileFilters, fs.filename);
});
if (mFileSettings.empty()) {
logger.printError("could not find any files matching the filter.");
return false;
}
}
else {
logger.printError("could not find any files matching the filter.");
return false;
mFileSettings = fileSettings;
}
} else if (!pathnames.empty()) {
// Execute recursiveAddFiles() to each given file parameter
Expand All @@ -220,13 +221,13 @@ bool CppCheckExecutor::parseFromArgs(Settings &settings, int argc, const char* c
}
}

if (mFiles.empty() && settings.fileSettings.empty()) {
if (mFiles.empty() && fileSettings.empty()) {
logger.printError("could not find or open any of the paths given.");
if (!ignored.empty())
logger.printMessage("Maybe all paths were ignored?");
return false;
}
if (!settings.fileFilters.empty() && settings.fileSettings.empty()) {
if (!settings.fileFilters.empty() && fileSettings.empty()) {
std::map<std::string, std::size_t> newMap;
for (std::map<std::string, std::size_t>::const_iterator i = mFiles.cbegin(); i != mFiles.cend(); ++i)
if (matchglobs(settings.fileFilters, i->first)) {
Expand Down Expand Up @@ -319,7 +320,7 @@ int CppCheckExecutor::check_internal(CppCheck& cppcheck)
std::list<std::string> fileNames;
for (std::map<std::string, std::size_t>::const_iterator i = mFiles.cbegin(); i != mFiles.cend(); ++i)
fileNames.emplace_back(i->first);
AnalyzerInformation::writeFilesTxt(settings.buildDir, fileNames, settings.userDefines, settings.fileSettings);
AnalyzerInformation::writeFilesTxt(settings.buildDir, fileNames, settings.userDefines, mFileSettings);
}

if (!settings.checkersReportFilename.empty())
Expand All @@ -328,18 +329,18 @@ int CppCheckExecutor::check_internal(CppCheck& cppcheck)
unsigned int returnValue = 0;
if (settings.useSingleJob()) {
// Single process
SingleExecutor executor(cppcheck, mFiles, settings, settings.nomsg, *this);
SingleExecutor executor(cppcheck, mFiles, mFileSettings, settings, settings.nomsg, *this);
returnValue = executor.check();
} else {
#if defined(THREADING_MODEL_THREAD)
ThreadExecutor executor(mFiles, settings, settings.nomsg, *this, CppCheckExecutor::executeCommand);
ThreadExecutor executor(mFiles, mFileSettings, settings, settings.nomsg, *this, CppCheckExecutor::executeCommand);
#elif defined(THREADING_MODEL_FORK)
ProcessExecutor executor(mFiles, settings, settings.nomsg, *this, CppCheckExecutor::executeCommand);
ProcessExecutor executor(mFiles, mFileSettings, settings, settings.nomsg, *this, CppCheckExecutor::executeCommand);
#endif
returnValue = executor.check();
}

cppcheck.analyseWholeProgram(settings.buildDir, mFiles);
cppcheck.analyseWholeProgram(settings.buildDir, mFiles, mFileSettings);

if (settings.severity.isEnabled(Severity::information) || settings.checkConfiguration) {
const bool err = reportSuppressions(settings, cppcheck.isUnusedFunctionCheckEnabled(), mFiles, *this);
Expand Down
4 changes: 4 additions & 0 deletions cli/cppcheckexecutor.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@
#include "color.h"
#include "config.h"
#include "errorlogger.h"
#include "filesettings.h"

#include <cstdio>
#include <ctime>
#include <iosfwd>
#include <list>
#include <map>
#include <set>
#include <string>
Expand Down Expand Up @@ -181,6 +183,8 @@ class CppCheckExecutor : public ErrorLogger {
*/
std::map<std::string, std::size_t> mFiles;

std::list<FileSettings> mFileSettings;

/**
* Report progress time
*/
Expand Down
6 changes: 4 additions & 2 deletions cli/executor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@
#include <sstream> // IWYU pragma: keep
#include <utility>

Executor::Executor(const std::map<std::string, std::size_t> &files, const Settings &settings, Suppressions &suppressions, ErrorLogger &errorLogger)
: mFiles(files), mSettings(settings), mSuppressions(suppressions), mErrorLogger(errorLogger)
struct FileSettings;

Executor::Executor(const std::map<std::string, std::size_t> &files, const std::list<FileSettings>& fileSettings, const Settings &settings, Suppressions &suppressions, ErrorLogger &errorLogger)
: mFiles(files), mFileSettings(fileSettings), mSettings(settings), mSuppressions(suppressions), mErrorLogger(errorLogger)
{}

bool Executor::hasToLog(const ErrorMessage &msg)
Expand Down
4 changes: 3 additions & 1 deletion cli/executor.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class Settings;
class ErrorLogger;
class ErrorMessage;
class Suppressions;
struct FileSettings;

/// @addtogroup CLI
/// @{
Expand All @@ -39,7 +40,7 @@ class Suppressions;
*/
class Executor {
public:
Executor(const std::map<std::string, std::size_t> &files, const Settings &settings, Suppressions &suppressions, ErrorLogger &errorLogger);
Executor(const std::map<std::string, std::size_t> &files, const std::list<FileSettings>& fileSettings, const Settings &settings, Suppressions &suppressions, ErrorLogger &errorLogger);
virtual ~Executor() = default;

Executor(const Executor &) = delete;
Expand All @@ -66,6 +67,7 @@ class Executor {
bool hasToLog(const ErrorMessage &msg);

const std::map<std::string, std::size_t> &mFiles;
const std::list<FileSettings>& mFileSettings;
const Settings &mSettings;
Suppressions &mSuppressions;
ErrorLogger &mErrorLogger;
Expand Down
16 changes: 8 additions & 8 deletions cli/processexecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ enum class Color;
using std::memset;


ProcessExecutor::ProcessExecutor(const std::map<std::string, std::size_t> &files, const Settings &settings, Suppressions &suppressions, ErrorLogger &errorLogger, CppCheck::ExecuteCmdFn executeCommand)
: Executor(files, settings, suppressions, errorLogger)
ProcessExecutor::ProcessExecutor(const std::map<std::string, std::size_t> &files, const std::list<FileSettings>& fileSettings, const Settings &settings, Suppressions &suppressions, ErrorLogger &errorLogger, CppCheck::ExecuteCmdFn executeCommand)
: Executor(files, fileSettings, settings, suppressions, errorLogger)
, mExecuteCommand(std::move(executeCommand))
{
assert(mSettings.jobs > 1);
Expand Down Expand Up @@ -237,11 +237,11 @@ unsigned int ProcessExecutor::check()
std::map<int, std::string> pipeFile;
std::size_t processedsize = 0;
std::map<std::string, std::size_t>::const_iterator iFile = mFiles.cbegin();
std::list<FileSettings>::const_iterator iFileSettings = mSettings.fileSettings.cbegin();
std::list<FileSettings>::const_iterator iFileSettings = mFileSettings.cbegin();
for (;;) {
// Start a new child
const size_t nchildren = childFile.size();
if ((iFile != mFiles.cend() || iFileSettings != mSettings.fileSettings.cend()) && nchildren < mSettings.jobs && checkLoadAverage(nchildren)) {
if ((iFile != mFiles.cend() || iFileSettings != mFileSettings.cend()) && nchildren < mSettings.jobs && checkLoadAverage(nchildren)) {
int pipes[2];
if (pipe(pipes) == -1) {
std::cerr << "#### ThreadExecutor::check, pipe() failed: "<< std::strerror(errno) << std::endl;
Expand Down Expand Up @@ -275,7 +275,7 @@ unsigned int ProcessExecutor::check()
fileChecker.settings() = mSettings;
unsigned int resultOfCheck = 0;

if (iFileSettings != mSettings.fileSettings.end()) {
if (iFileSettings != mFileSettings.end()) {
resultOfCheck = fileChecker.check(*iFileSettings);
if (fileChecker.settings().clangTidy)
fileChecker.analyseClangTidy(*iFileSettings);
Expand All @@ -291,7 +291,7 @@ unsigned int ProcessExecutor::check()

close(pipes[1]);
rpipes.push_back(pipes[0]);
if (iFileSettings != mSettings.fileSettings.end()) {
if (iFileSettings != mFileSettings.end()) {
childFile[pid] = iFileSettings->filename + ' ' + iFileSettings->cfg;
pipeFile[pipes[0]] = iFileSettings->filename + ' ' + iFileSettings->cfg;
++iFileSettings;
Expand Down Expand Up @@ -334,7 +334,7 @@ unsigned int ProcessExecutor::check()
fileCount++;
processedsize += size;
if (!mSettings.quiet)
Executor::reportStatus(fileCount, mFiles.size() + mSettings.fileSettings.size(), processedsize, totalfilesize);
Executor::reportStatus(fileCount, mFiles.size() + mFileSettings.size(), processedsize, totalfilesize);

close(*rp);
rp = rpipes.erase(rp);
Expand Down Expand Up @@ -370,7 +370,7 @@ unsigned int ProcessExecutor::check()
}
}
}
if (iFile == mFiles.end() && iFileSettings == mSettings.fileSettings.end() && rpipes.empty() && childFile.empty()) {
if (iFile == mFiles.end() && iFileSettings == mFileSettings.end() && rpipes.empty() && childFile.empty()) {
// All done
break;
}
Expand Down
4 changes: 3 additions & 1 deletion cli/processexecutor.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,14 @@
#include "executor.h"

#include <cstddef>
#include <list>
#include <map>
#include <string>

class Settings;
class ErrorLogger;
class Suppressions;
struct FileSettings;

/// @addtogroup CLI
/// @{
Expand All @@ -39,7 +41,7 @@ class Suppressions;
*/
class ProcessExecutor : public Executor {
public:
ProcessExecutor(const std::map<std::string, std::size_t> &files, const Settings &settings, Suppressions &suppressions, ErrorLogger &errorLogger, CppCheck::ExecuteCmdFn executeCommand);
ProcessExecutor(const std::map<std::string, std::size_t> &files, const std::list<FileSettings>& fileSettings, const Settings &settings, Suppressions &suppressions, ErrorLogger &errorLogger, CppCheck::ExecuteCmdFn executeCommand);
ProcessExecutor(const ProcessExecutor &) = delete;
void operator=(const ProcessExecutor &) = delete;

Expand Down
16 changes: 8 additions & 8 deletions cli/singleexecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@

class ErrorLogger;

SingleExecutor::SingleExecutor(CppCheck &cppcheck, const std::map<std::string, std::size_t> &files, const Settings &settings, Suppressions &suppressions, ErrorLogger &errorLogger)
: Executor(files, settings, suppressions, errorLogger)
SingleExecutor::SingleExecutor(CppCheck &cppcheck, const std::map<std::string, std::size_t> &files, const std::list<FileSettings>& fileSettings, const Settings &settings, Suppressions &suppressions, ErrorLogger &errorLogger)
: Executor(files, fileSettings, settings, suppressions, errorLogger)
, mCppcheck(cppcheck)
{
assert(mSettings.jobs == 1);
Expand All @@ -51,7 +51,7 @@ unsigned int SingleExecutor::check()
unsigned int c = 0;
// TODO: processes either mSettings.project.fileSettings or mFiles - process/thread implementations process both
// TODO: thread/process implementations process fileSettings first
if (mSettings.fileSettings.empty()) {
if (mFileSettings.empty()) {
for (std::map<std::string, std::size_t>::const_iterator i = mFiles.cbegin(); i != mFiles.cend(); ++i) {
if (!mSettings.library.markupFile(i->first)
|| !mSettings.library.processMarkupAfterCode(i->first)) {
Expand All @@ -66,13 +66,13 @@ unsigned int SingleExecutor::check()
} else {
// filesettings
// check all files of the project
for (const FileSettings &fs : mSettings.fileSettings) {
for (const FileSettings &fs : mFileSettings) {
if (!mSettings.library.markupFile(fs.filename)
|| !mSettings.library.processMarkupAfterCode(fs.filename)) {
result += mCppcheck.check(fs);
++c;
if (!mSettings.quiet)
reportStatus(c, mSettings.fileSettings.size(), c, mSettings.fileSettings.size());
reportStatus(c, mFileSettings.size(), c, mFileSettings.size());
if (mSettings.clangTidy)
mCppcheck.analyseClangTidy(fs);
}
Expand All @@ -82,7 +82,7 @@ unsigned int SingleExecutor::check()
// second loop to parse all markup files which may not work until all
// c/cpp files have been parsed and checked
// TODO: get rid of duplicated code
if (mSettings.fileSettings.empty()) {
if (mFileSettings.empty()) {
for (std::map<std::string, std::size_t>::const_iterator i = mFiles.cbegin(); i != mFiles.cend(); ++i) {
if (mSettings.library.markupFile(i->first)
&& mSettings.library.processMarkupAfterCode(i->first)) {
Expand All @@ -96,13 +96,13 @@ unsigned int SingleExecutor::check()
}
}
else {
for (const FileSettings &fs : mSettings.fileSettings) {
for (const FileSettings &fs : mFileSettings) {
if (mSettings.library.markupFile(fs.filename)
&& mSettings.library.processMarkupAfterCode(fs.filename)) {
result += mCppcheck.check(fs);
++c;
if (!mSettings.quiet)
reportStatus(c, mSettings.fileSettings.size(), c, mSettings.fileSettings.size());
reportStatus(c, mFileSettings.size(), c, mFileSettings.size());
if (mSettings.clangTidy)
mCppcheck.analyseClangTidy(fs);
}
Expand Down
4 changes: 3 additions & 1 deletion cli/singleexecutor.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,20 @@
#include "executor.h"

#include <cstddef>
#include <list>
#include <map>
#include <string>

class ErrorLogger;
class Settings;
class CppCheck;
class Suppressions;
struct FileSettings;

class SingleExecutor : public Executor
{
public:
SingleExecutor(CppCheck &cppcheck, const std::map<std::string, std::size_t> &files, const Settings &settings, Suppressions &suppressions, ErrorLogger &errorLogger);
SingleExecutor(CppCheck &cppcheck, const std::map<std::string, std::size_t> &files, const std::list<FileSettings>& fileSettings, const Settings &settings, Suppressions &suppressions, ErrorLogger &errorLogger);
SingleExecutor(const SingleExecutor &) = delete;
void operator=(const SingleExecutor &) = delete;

Expand Down
6 changes: 3 additions & 3 deletions cli/threadexecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@

enum class Color;

ThreadExecutor::ThreadExecutor(const std::map<std::string, std::size_t> &files, const Settings &settings, Suppressions &suppressions, ErrorLogger &errorLogger, CppCheck::ExecuteCmdFn executeCommand)
: Executor(files, settings, suppressions, errorLogger)
ThreadExecutor::ThreadExecutor(const std::map<std::string, std::size_t> &files, const std::list<FileSettings>& fileSettings, const Settings &settings, Suppressions &suppressions, ErrorLogger &errorLogger, CppCheck::ExecuteCmdFn executeCommand)
: Executor(files, fileSettings, settings, suppressions, errorLogger)
, mExecuteCommand(std::move(executeCommand))
{
assert(mSettings.jobs > 1);
Expand Down Expand Up @@ -180,7 +180,7 @@ unsigned int ThreadExecutor::check()
std::vector<std::future<unsigned int>> threadFutures;
threadFutures.reserve(mSettings.jobs);

ThreadData data(*this, mErrorLogger, mSettings, mFiles, mSettings.fileSettings, mExecuteCommand);
ThreadData data(*this, mErrorLogger, mSettings, mFiles, mFileSettings, mExecuteCommand);

for (unsigned int i = 0; i < mSettings.jobs; ++i) {
try {
Expand Down
Loading