parent
8c63c8ced1
commit
bc174c502a
|
@ -209,8 +209,7 @@ bool CppCheckExecutor::parseFromArgs(Settings &settings, int argc, const char* c
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!pathnames.empty()) {
|
if (!pathnames.empty()) {
|
||||||
// TODO: this should be a vector or list so the order is kept
|
std::list<std::pair<std::string, std::size_t>> files;
|
||||||
std::map<std::string, std::size_t> files;
|
|
||||||
// TODO: this needs to be inlined into PathMatch as it depends on the underlying filesystem
|
// TODO: this needs to be inlined into PathMatch as it depends on the underlying filesystem
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
// For Windows we want case-insensitive path matching
|
// For Windows we want case-insensitive path matching
|
||||||
|
@ -286,7 +285,7 @@ int CppCheckExecutor::check_wrapper(CppCheck& cppcheck)
|
||||||
return check_internal(cppcheck);
|
return check_internal(cppcheck);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CppCheckExecutor::reportSuppressions(const Settings &settings, bool unusedFunctionCheckEnabled, const std::map<std::string, std::size_t> &files, ErrorLogger& errorLogger) {
|
bool CppCheckExecutor::reportSuppressions(const Settings &settings, bool unusedFunctionCheckEnabled, const std::list<std::pair<std::string, std::size_t>> &files, ErrorLogger& errorLogger) {
|
||||||
const auto& suppressions = settings.nomsg.getSuppressions();
|
const auto& suppressions = settings.nomsg.getSuppressions();
|
||||||
if (std::any_of(suppressions.begin(), suppressions.end(), [](const Suppressions::Suppression& s) {
|
if (std::any_of(suppressions.begin(), suppressions.end(), [](const Suppressions::Suppression& s) {
|
||||||
return s.errorId == "unmatchedSuppression" && s.fileName.empty() && s.lineNumber == Suppressions::Suppression::NO_LINE;
|
return s.errorId == "unmatchedSuppression" && s.fileName.empty() && s.lineNumber == Suppressions::Suppression::NO_LINE;
|
||||||
|
@ -295,7 +294,7 @@ bool CppCheckExecutor::reportSuppressions(const Settings &settings, bool unusedF
|
||||||
|
|
||||||
bool err = false;
|
bool err = false;
|
||||||
if (settings.useSingleJob()) {
|
if (settings.useSingleJob()) {
|
||||||
for (std::map<std::string, std::size_t>::const_iterator i = files.cbegin(); i != files.cend(); ++i) {
|
for (std::list<std::pair<std::string, std::size_t>>::const_iterator i = files.cbegin(); i != files.cend(); ++i) {
|
||||||
err |= Suppressions::reportUnmatchedSuppressions(
|
err |= Suppressions::reportUnmatchedSuppressions(
|
||||||
settings.nomsg.getUnmatchedLocalSuppressions(i->first, unusedFunctionCheckEnabled), errorLogger);
|
settings.nomsg.getUnmatchedLocalSuppressions(i->first, unusedFunctionCheckEnabled), errorLogger);
|
||||||
}
|
}
|
||||||
|
@ -326,7 +325,7 @@ int CppCheckExecutor::check_internal(CppCheck& cppcheck)
|
||||||
settings.loadSummaries();
|
settings.loadSummaries();
|
||||||
|
|
||||||
std::list<std::string> fileNames;
|
std::list<std::string> fileNames;
|
||||||
for (std::map<std::string, std::size_t>::const_iterator i = mFiles.cbegin(); i != mFiles.cend(); ++i)
|
for (std::list<std::pair<std::string, std::size_t>>::const_iterator i = mFiles.cbegin(); i != mFiles.cend(); ++i)
|
||||||
fileNames.emplace_back(i->first);
|
fileNames.emplace_back(i->first);
|
||||||
AnalyzerInformation::writeFilesTxt(settings.buildDir, fileNames, settings.userDefines, mFileSettings);
|
AnalyzerInformation::writeFilesTxt(settings.buildDir, fileNames, settings.userDefines, mFileSettings);
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,9 +28,9 @@
|
||||||
#include <ctime>
|
#include <ctime>
|
||||||
#include <iosfwd>
|
#include <iosfwd>
|
||||||
#include <list>
|
#include <list>
|
||||||
#include <map>
|
|
||||||
#include <set>
|
#include <set>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <utility>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
class CppCheck;
|
class CppCheck;
|
||||||
|
@ -129,7 +129,7 @@ private:
|
||||||
*/
|
*/
|
||||||
bool parseFromArgs(Settings &settings, int argc, const char* const argv[]);
|
bool parseFromArgs(Settings &settings, int argc, const char* const argv[]);
|
||||||
|
|
||||||
static bool reportSuppressions(const Settings &settings, bool unusedFunctionCheckEnabled, const std::map<std::string, std::size_t> &files, ErrorLogger& errorLogger);
|
static bool reportSuppressions(const Settings &settings, bool unusedFunctionCheckEnabled, const std::list<std::pair<std::string, std::size_t>> &files, ErrorLogger& errorLogger);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Wrapper around check_internal
|
* Wrapper around check_internal
|
||||||
|
@ -183,7 +183,7 @@ private:
|
||||||
/**
|
/**
|
||||||
* Filename associated with size of file
|
* Filename associated with size of file
|
||||||
*/
|
*/
|
||||||
std::map<std::string, std::size_t> mFiles;
|
std::list<std::pair<std::string, std::size_t>> mFiles;
|
||||||
|
|
||||||
std::list<FileSettings> mFileSettings;
|
std::list<FileSettings> mFileSettings;
|
||||||
|
|
||||||
|
|
|
@ -30,7 +30,7 @@
|
||||||
|
|
||||||
struct FileSettings;
|
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)
|
Executor::Executor(const std::list<std::pair<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)
|
: mFiles(files), mFileSettings(fileSettings), mSettings(settings), mSuppressions(suppressions), mErrorLogger(errorLogger)
|
||||||
{
|
{
|
||||||
// the two inputs may only be used exclusively
|
// the two inputs may only be used exclusively
|
||||||
|
|
|
@ -21,9 +21,9 @@
|
||||||
|
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#include <list>
|
#include <list>
|
||||||
#include <map>
|
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
class Settings;
|
class Settings;
|
||||||
class ErrorLogger;
|
class ErrorLogger;
|
||||||
|
@ -40,7 +40,7 @@ struct FileSettings;
|
||||||
*/
|
*/
|
||||||
class Executor {
|
class Executor {
|
||||||
public:
|
public:
|
||||||
Executor(const std::map<std::string, std::size_t> &files, const std::list<FileSettings>& fileSettings, const Settings &settings, Suppressions &suppressions, ErrorLogger &errorLogger);
|
Executor(const std::list<std::pair<std::string, std::size_t>> &files, const std::list<FileSettings>& fileSettings, const Settings &settings, Suppressions &suppressions, ErrorLogger &errorLogger);
|
||||||
virtual ~Executor() = default;
|
virtual ~Executor() = default;
|
||||||
|
|
||||||
Executor(const Executor &) = delete;
|
Executor(const Executor &) = delete;
|
||||||
|
@ -66,7 +66,7 @@ protected:
|
||||||
*/
|
*/
|
||||||
bool hasToLog(const ErrorMessage &msg);
|
bool hasToLog(const ErrorMessage &msg);
|
||||||
|
|
||||||
const std::map<std::string, std::size_t> &mFiles;
|
const std::list<std::pair<std::string, std::size_t>> &mFiles;
|
||||||
const std::list<FileSettings>& mFileSettings;
|
const std::list<FileSettings>& mFileSettings;
|
||||||
const Settings &mSettings;
|
const Settings &mSettings;
|
||||||
Suppressions &mSuppressions;
|
Suppressions &mSuppressions;
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
|
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
#include <iterator>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
|
@ -39,12 +40,12 @@
|
||||||
// When compiling Unicode targets WinAPI automatically uses *W Unicode versions
|
// When compiling Unicode targets WinAPI automatically uses *W Unicode versions
|
||||||
// of called functions. Thus, we explicitly call *A versions of the functions.
|
// of called functions. Thus, we explicitly call *A versions of the functions.
|
||||||
|
|
||||||
std::string FileLister::recursiveAddFiles(std::map<std::string, std::size_t> &files, const std::string &path, const std::set<std::string> &extra, const PathMatch& ignored)
|
std::string FileLister::recursiveAddFiles(std::list<std::pair<std::string, std::size_t>>&files, const std::string &path, const std::set<std::string> &extra, const PathMatch& ignored)
|
||||||
{
|
{
|
||||||
return addFiles(files, path, extra, true, ignored);
|
return addFiles(files, path, extra, true, ignored);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string FileLister::addFiles(std::map<std::string, std::size_t> &files, const std::string &path, const std::set<std::string> &extra, bool recursive, const PathMatch& ignored)
|
std::string FileLister::addFiles(std::list<std::pair<std::string, std::size_t>>&files, const std::string &path, const std::set<std::string> &extra, bool recursive, const PathMatch& ignored)
|
||||||
{
|
{
|
||||||
if (path.empty())
|
if (path.empty())
|
||||||
return "no path specified";
|
return "no path specified";
|
||||||
|
@ -112,18 +113,27 @@ std::string FileLister::addFiles(std::map<std::string, std::size_t> &files, cons
|
||||||
|
|
||||||
// Limitation: file sizes are assumed to fit in a 'size_t'
|
// Limitation: file sizes are assumed to fit in a 'size_t'
|
||||||
#ifdef _WIN64
|
#ifdef _WIN64
|
||||||
files[nativename] = (static_cast<std::size_t>(ffd.nFileSizeHigh) << 32) | ffd.nFileSizeLow;
|
files.emplace_back(nativename, (static_cast<std::size_t>(ffd.nFileSizeHigh) << 32) | ffd.nFileSizeLow);
|
||||||
#else
|
#else
|
||||||
files[nativename] = ffd.nFileSizeLow;
|
files.emplace_back(nativename, ffd.nFileSizeLow);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Directory
|
// Directory
|
||||||
if (recursive) {
|
if (recursive) {
|
||||||
if (!ignored.match(fname)) {
|
if (!ignored.match(fname)) {
|
||||||
std::string err = FileLister::recursiveAddFiles(files, fname, extra, ignored);
|
std::list<std::pair<std::string, std::size_t>> filesSorted;
|
||||||
|
|
||||||
|
std::string err = FileLister::recursiveAddFiles(filesSorted, fname, extra, ignored);
|
||||||
if (!err.empty())
|
if (!err.empty())
|
||||||
return err;
|
return err;
|
||||||
|
|
||||||
|
// files inside directories need to be sorted as the filesystem doesn't provide a stable order
|
||||||
|
filesSorted.sort([](const decltype(filesSorted)::value_type& a, const decltype(filesSorted)::value_type& b) {
|
||||||
|
return a.first < b.first;
|
||||||
|
});
|
||||||
|
|
||||||
|
files.insert(files.end(), std::make_move_iterator(filesSorted.begin()), std::make_move_iterator(filesSorted.end()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -155,7 +165,7 @@ std::string FileLister::addFiles(std::map<std::string, std::size_t> &files, cons
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <cerrno>
|
#include <cerrno>
|
||||||
|
|
||||||
static std::string addFiles2(std::map<std::string, std::size_t> &files,
|
static std::string addFiles2(std::list<std::pair<std::string, std::size_t>> &files,
|
||||||
const std::string &path,
|
const std::string &path,
|
||||||
const std::set<std::string> &extra,
|
const std::set<std::string> &extra,
|
||||||
bool recursive,
|
bool recursive,
|
||||||
|
@ -178,6 +188,8 @@ static std::string addFiles2(std::map<std::string, std::size_t> &files,
|
||||||
std::string new_path = path;
|
std::string new_path = path;
|
||||||
new_path += '/';
|
new_path += '/';
|
||||||
|
|
||||||
|
std::list<std::pair<std::string, std::size_t>> filesSorted;
|
||||||
|
|
||||||
while (const dirent* dir_result = readdir(dir)) {
|
while (const dirent* dir_result = readdir(dir)) {
|
||||||
if ((std::strcmp(dir_result->d_name, ".") == 0) ||
|
if ((std::strcmp(dir_result->d_name, ".") == 0) ||
|
||||||
(std::strcmp(dir_result->d_name, "..") == 0))
|
(std::strcmp(dir_result->d_name, "..") == 0))
|
||||||
|
@ -193,15 +205,16 @@ static std::string addFiles2(std::map<std::string, std::size_t> &files,
|
||||||
#endif
|
#endif
|
||||||
if (path_is_directory) {
|
if (path_is_directory) {
|
||||||
if (recursive && !ignored.match(new_path)) {
|
if (recursive && !ignored.match(new_path)) {
|
||||||
std::string err = addFiles2(files, new_path, extra, recursive, ignored);
|
std::string err = addFiles2(filesSorted, new_path, extra, recursive, ignored);
|
||||||
if (!err.empty()) {
|
if (!err.empty()) {
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (Path::acceptFile(new_path, extra) && !ignored.match(new_path)) {
|
if (Path::acceptFile(new_path, extra) && !ignored.match(new_path)) {
|
||||||
if (stat(new_path.c_str(), &file_stat) != -1)
|
if (stat(new_path.c_str(), &file_stat) != -1) {
|
||||||
files[new_path] = file_stat.st_size;
|
filesSorted.emplace_back(new_path, file_stat.st_size);
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
const int err = errno;
|
const int err = errno;
|
||||||
return "could not stat file '" + new_path + "' (errno: " + std::to_string(err) + ")";
|
return "could not stat file '" + new_path + "' (errno: " + std::to_string(err) + ")";
|
||||||
|
@ -209,18 +222,25 @@ static std::string addFiles2(std::map<std::string, std::size_t> &files,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// files inside directories need to be sorted as the filesystem doesn't provide a stable order
|
||||||
|
filesSorted.sort([](const decltype(filesSorted)::value_type& a, const decltype(filesSorted)::value_type& b) {
|
||||||
|
return a.first < b.first;
|
||||||
|
});
|
||||||
|
|
||||||
|
files.insert(files.end(), std::make_move_iterator(filesSorted.begin()), std::make_move_iterator(filesSorted.end()));
|
||||||
} else
|
} else
|
||||||
files[path] = file_stat.st_size;
|
files.emplace_back(path, file_stat.st_size);
|
||||||
}
|
}
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string FileLister::recursiveAddFiles(std::map<std::string, std::size_t> &files, const std::string &path, const std::set<std::string> &extra, const PathMatch& ignored)
|
std::string FileLister::recursiveAddFiles(std::list<std::pair<std::string, std::size_t>> &files, const std::string &path, const std::set<std::string> &extra, const PathMatch& ignored)
|
||||||
{
|
{
|
||||||
return addFiles(files, path, extra, true, ignored);
|
return addFiles(files, path, extra, true, ignored);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string FileLister::addFiles(std::map<std::string, std::size_t> &files, const std::string &path, const std::set<std::string> &extra, bool recursive, const PathMatch& ignored)
|
std::string FileLister::addFiles(std::list<std::pair<std::string, std::size_t>> &files, const std::string &path, const std::set<std::string> &extra, bool recursive, const PathMatch& ignored)
|
||||||
{
|
{
|
||||||
if (path.empty())
|
if (path.empty())
|
||||||
return "no path specified";
|
return "no path specified";
|
||||||
|
|
|
@ -20,9 +20,10 @@
|
||||||
#define filelisterH
|
#define filelisterH
|
||||||
|
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#include <map>
|
#include <list>
|
||||||
#include <set>
|
#include <set>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
class PathMatch;
|
class PathMatch;
|
||||||
|
|
||||||
|
@ -37,12 +38,12 @@ public:
|
||||||
* Add source files from given directory and all subdirectries to the
|
* Add source files from given directory and all subdirectries to the
|
||||||
* given map. Only files with accepted extensions
|
* given map. Only files with accepted extensions
|
||||||
* (*.c;*.cpp;*.cxx;*.c++;*.cc;*.txx) are added.
|
* (*.c;*.cpp;*.cxx;*.c++;*.cc;*.txx) are added.
|
||||||
* @param files output map that associates the size of each file with its name
|
* @param files output list that associates the size of each file with its name
|
||||||
* @param path root path
|
* @param path root path
|
||||||
* @param ignored ignored paths
|
* @param ignored ignored paths
|
||||||
* @return On success, an empty string is returned. On error, a error message is returned.
|
* @return On success, an empty string is returned. On error, a error message is returned.
|
||||||
*/
|
*/
|
||||||
static std::string recursiveAddFiles(std::map<std::string, std::size_t> &files, const std::string &path, const PathMatch& ignored) {
|
static std::string recursiveAddFiles(std::list<std::pair<std::string, std::size_t>> &files, const std::string &path, const PathMatch& ignored) {
|
||||||
const std::set<std::string> extra;
|
const std::set<std::string> extra;
|
||||||
return recursiveAddFiles(files, path, extra, ignored);
|
return recursiveAddFiles(files, path, extra, ignored);
|
||||||
}
|
}
|
||||||
|
@ -52,27 +53,27 @@ public:
|
||||||
* Add source files from given directory and all subdirectries to the
|
* Add source files from given directory and all subdirectries to the
|
||||||
* given map. Only files with accepted extensions
|
* given map. Only files with accepted extensions
|
||||||
* (*.c;*.cpp;*.cxx;*.c++;*.cc;*.txx) are added.
|
* (*.c;*.cpp;*.cxx;*.c++;*.cc;*.txx) are added.
|
||||||
* @param files output map that associates the size of each file with its name
|
* @param files output list that associates the size of each file with its name
|
||||||
* @param path root path
|
* @param path root path
|
||||||
* @param extra Extra file extensions
|
* @param extra Extra file extensions
|
||||||
* @param ignored ignored paths
|
* @param ignored ignored paths
|
||||||
* @return On success, an empty string is returned. On error, a error message is returned.
|
* @return On success, an empty string is returned. On error, a error message is returned.
|
||||||
*/
|
*/
|
||||||
static std::string recursiveAddFiles(std::map<std::string, std::size_t> &files, const std::string &path, const std::set<std::string> &extra, const PathMatch& ignored);
|
static std::string recursiveAddFiles(std::list<std::pair<std::string, std::size_t>> &files, const std::string &path, const std::set<std::string> &extra, const PathMatch& ignored);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief (Recursively) add source files to a map.
|
* @brief (Recursively) add source files to a map.
|
||||||
* Add source files from given directory and all subdirectries to the
|
* Add source files from given directory and all subdirectries to the
|
||||||
* given map. Only files with accepted extensions
|
* given map. Only files with accepted extensions
|
||||||
* (*.c;*.cpp;*.cxx;*.c++;*.cc;*.txx) are added.
|
* (*.c;*.cpp;*.cxx;*.c++;*.cc;*.txx) are added.
|
||||||
* @param files output map that associates the size of each file with its name
|
* @param files output list that associates the size of each file with its name
|
||||||
* @param path root path
|
* @param path root path
|
||||||
* @param extra Extra file extensions
|
* @param extra Extra file extensions
|
||||||
* @param recursive Enable recursion
|
* @param recursive Enable recursion
|
||||||
* @param ignored ignored paths
|
* @param ignored ignored paths
|
||||||
* @return On success, an empty string is returned. On error, a error message is returned.
|
* @return On success, an empty string is returned. On error, a error message is returned.
|
||||||
*/
|
*/
|
||||||
static std::string addFiles(std::map<std::string, std::size_t> &files, const std::string &path, const std::set<std::string> &extra, bool recursive, const PathMatch& ignored);
|
static std::string addFiles(std::list<std::pair<std::string, std::size_t>> &files, const std::string &path, const std::set<std::string> &extra, bool recursive, const PathMatch& ignored);
|
||||||
};
|
};
|
||||||
|
|
||||||
/// @}
|
/// @}
|
||||||
|
|
|
@ -38,6 +38,7 @@
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <list>
|
#include <list>
|
||||||
|
#include <map>
|
||||||
#include <sstream> // IWYU pragma: keep
|
#include <sstream> // IWYU pragma: keep
|
||||||
#include <sys/select.h>
|
#include <sys/select.h>
|
||||||
#include <sys/wait.h>
|
#include <sys/wait.h>
|
||||||
|
@ -60,7 +61,7 @@ enum class Color;
|
||||||
using std::memset;
|
using std::memset;
|
||||||
|
|
||||||
|
|
||||||
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)
|
ProcessExecutor::ProcessExecutor(const std::list<std::pair<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)
|
: Executor(files, fileSettings, settings, suppressions, errorLogger)
|
||||||
, mExecuteCommand(std::move(executeCommand))
|
, mExecuteCommand(std::move(executeCommand))
|
||||||
{
|
{
|
||||||
|
@ -236,7 +237,7 @@ unsigned int ProcessExecutor::check()
|
||||||
std::map<pid_t, std::string> childFile;
|
std::map<pid_t, std::string> childFile;
|
||||||
std::map<int, std::string> pipeFile;
|
std::map<int, std::string> pipeFile;
|
||||||
std::size_t processedsize = 0;
|
std::size_t processedsize = 0;
|
||||||
std::map<std::string, std::size_t>::const_iterator iFile = mFiles.cbegin();
|
std::list<std::pair<std::string, std::size_t>>::const_iterator iFile = mFiles.cbegin();
|
||||||
std::list<FileSettings>::const_iterator iFileSettings = mFileSettings.cbegin();
|
std::list<FileSettings>::const_iterator iFileSettings = mFileSettings.cbegin();
|
||||||
for (;;) {
|
for (;;) {
|
||||||
// Start a new child
|
// Start a new child
|
||||||
|
@ -325,7 +326,9 @@ unsigned int ProcessExecutor::check()
|
||||||
std::size_t size = 0;
|
std::size_t size = 0;
|
||||||
if (p != pipeFile.end()) {
|
if (p != pipeFile.end()) {
|
||||||
pipeFile.erase(p);
|
pipeFile.erase(p);
|
||||||
const std::map<std::string, std::size_t>::const_iterator fs = mFiles.find(name);
|
const auto fs = std::find_if(mFiles.cbegin(), mFiles.cend(), [&name](const std::pair<std::string, std::size_t>& entry) {
|
||||||
|
return entry.first == name;
|
||||||
|
});
|
||||||
if (fs != mFiles.end()) {
|
if (fs != mFiles.end()) {
|
||||||
size = fs->second;
|
size = fs->second;
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,8 +24,8 @@
|
||||||
|
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#include <list>
|
#include <list>
|
||||||
#include <map>
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
class Settings;
|
class Settings;
|
||||||
class ErrorLogger;
|
class ErrorLogger;
|
||||||
|
@ -41,7 +41,7 @@ struct FileSettings;
|
||||||
*/
|
*/
|
||||||
class ProcessExecutor : public Executor {
|
class ProcessExecutor : public Executor {
|
||||||
public:
|
public:
|
||||||
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 std::list<std::pair<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;
|
ProcessExecutor(const ProcessExecutor &) = delete;
|
||||||
void operator=(const ProcessExecutor &) = delete;
|
void operator=(const ProcessExecutor &) = delete;
|
||||||
|
|
||||||
|
|
|
@ -31,7 +31,7 @@
|
||||||
|
|
||||||
class ErrorLogger;
|
class 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)
|
SingleExecutor::SingleExecutor(CppCheck &cppcheck, const std::list<std::pair<std::string, std::size_t>> &files, const std::list<FileSettings>& fileSettings, const Settings &settings, Suppressions &suppressions, ErrorLogger &errorLogger)
|
||||||
: Executor(files, fileSettings, settings, suppressions, errorLogger)
|
: Executor(files, fileSettings, settings, suppressions, errorLogger)
|
||||||
, mCppcheck(cppcheck)
|
, mCppcheck(cppcheck)
|
||||||
{
|
{
|
||||||
|
@ -50,7 +50,7 @@ unsigned int SingleExecutor::check()
|
||||||
std::size_t processedsize = 0;
|
std::size_t processedsize = 0;
|
||||||
unsigned int c = 0;
|
unsigned int c = 0;
|
||||||
|
|
||||||
for (std::map<std::string, std::size_t>::const_iterator i = mFiles.cbegin(); i != mFiles.cend(); ++i) {
|
for (std::list<std::pair<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)) {
|
if (!mSettings.library.markupFile(i->first) || !mSettings.library.processMarkupAfterCode(i->first)) {
|
||||||
result += mCppcheck.check(i->first);
|
result += mCppcheck.check(i->first);
|
||||||
processedsize += i->second;
|
processedsize += i->second;
|
||||||
|
@ -77,7 +77,7 @@ unsigned int SingleExecutor::check()
|
||||||
// second loop to parse all markup files which may not work until all
|
// second loop to parse all markup files which may not work until all
|
||||||
// c/cpp files have been parsed and checked
|
// c/cpp files have been parsed and checked
|
||||||
// TODO: get rid of duplicated code
|
// TODO: get rid of duplicated code
|
||||||
for (std::map<std::string, std::size_t>::const_iterator i = mFiles.cbegin(); i != mFiles.cend(); ++i) {
|
for (std::list<std::pair<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)) {
|
if (mSettings.library.markupFile(i->first) && mSettings.library.processMarkupAfterCode(i->first)) {
|
||||||
result += mCppcheck.check(i->first);
|
result += mCppcheck.check(i->first);
|
||||||
processedsize += i->second;
|
processedsize += i->second;
|
||||||
|
|
|
@ -23,8 +23,8 @@
|
||||||
|
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#include <list>
|
#include <list>
|
||||||
#include <map>
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
class ErrorLogger;
|
class ErrorLogger;
|
||||||
class Settings;
|
class Settings;
|
||||||
|
@ -35,7 +35,7 @@ struct FileSettings;
|
||||||
class SingleExecutor : public Executor
|
class SingleExecutor : public Executor
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
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(CppCheck &cppcheck, const std::list<std::pair<std::string, std::size_t>> &files, const std::list<FileSettings>& fileSettings, const Settings &settings, Suppressions &suppressions, ErrorLogger &errorLogger);
|
||||||
SingleExecutor(const SingleExecutor &) = delete;
|
SingleExecutor(const SingleExecutor &) = delete;
|
||||||
void operator=(const SingleExecutor &) = delete;
|
void operator=(const SingleExecutor &) = delete;
|
||||||
|
|
||||||
|
|
|
@ -39,7 +39,7 @@
|
||||||
|
|
||||||
enum class Color;
|
enum class Color;
|
||||||
|
|
||||||
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)
|
ThreadExecutor::ThreadExecutor(const std::list<std::pair<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)
|
: Executor(files, fileSettings, settings, suppressions, errorLogger)
|
||||||
, mExecuteCommand(std::move(executeCommand))
|
, mExecuteCommand(std::move(executeCommand))
|
||||||
{
|
{
|
||||||
|
@ -81,7 +81,7 @@ private:
|
||||||
class ThreadData
|
class ThreadData
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ThreadData(ThreadExecutor &threadExecutor, ErrorLogger &errorLogger, const Settings &settings, const std::map<std::string, std::size_t> &files, const std::list<FileSettings> &fileSettings, CppCheck::ExecuteCmdFn executeCommand)
|
ThreadData(ThreadExecutor &threadExecutor, ErrorLogger &errorLogger, const Settings &settings, const std::list<std::pair<std::string, std::size_t>> &files, const std::list<FileSettings> &fileSettings, CppCheck::ExecuteCmdFn executeCommand)
|
||||||
: mFiles(files), mFileSettings(fileSettings), mSettings(settings), mExecuteCommand(std::move(executeCommand)), logForwarder(threadExecutor, errorLogger)
|
: mFiles(files), mFileSettings(fileSettings), mSettings(settings), mExecuteCommand(std::move(executeCommand)), logForwarder(threadExecutor, errorLogger)
|
||||||
{
|
{
|
||||||
mItNextFile = mFiles.begin();
|
mItNextFile = mFiles.begin();
|
||||||
|
@ -140,8 +140,8 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const std::map<std::string, std::size_t> &mFiles;
|
const std::list<std::pair<std::string, std::size_t>> &mFiles;
|
||||||
std::map<std::string, std::size_t>::const_iterator mItNextFile;
|
std::list<std::pair<std::string, std::size_t>>::const_iterator mItNextFile;
|
||||||
const std::list<FileSettings> &mFileSettings;
|
const std::list<FileSettings> &mFileSettings;
|
||||||
std::list<FileSettings>::const_iterator mItNextFileSettings;
|
std::list<FileSettings>::const_iterator mItNextFileSettings;
|
||||||
|
|
||||||
|
|
|
@ -24,8 +24,8 @@
|
||||||
|
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#include <list>
|
#include <list>
|
||||||
#include <map>
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
class Settings;
|
class Settings;
|
||||||
class ErrorLogger;
|
class ErrorLogger;
|
||||||
|
@ -43,7 +43,7 @@ class ThreadExecutor : public Executor {
|
||||||
friend class SyncLogForwarder;
|
friend class SyncLogForwarder;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
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);
|
ThreadExecutor(const std::list<std::pair<std::string, std::size_t>> &files, const std::list<FileSettings>& fileSettings, const Settings &settings, Suppressions &suppressions, ErrorLogger &errorLogger, CppCheck::ExecuteCmdFn executeCommand);
|
||||||
ThreadExecutor(const ThreadExecutor &) = delete;
|
ThreadExecutor(const ThreadExecutor &) = delete;
|
||||||
void operator=(const ThreadExecutor &) = delete;
|
void operator=(const ThreadExecutor &) = delete;
|
||||||
|
|
||||||
|
|
|
@ -34,10 +34,10 @@
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#include <iterator>
|
#include <iterator>
|
||||||
#include <list>
|
#include <list>
|
||||||
#include <map>
|
|
||||||
#include <ostream>
|
#include <ostream>
|
||||||
#include <set>
|
#include <set>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <utility>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include <QByteArray>
|
#include <QByteArray>
|
||||||
|
@ -111,9 +111,10 @@ void CheckThread::run()
|
||||||
if (!mFiles.isEmpty() || mAnalyseWholeProgram) {
|
if (!mFiles.isEmpty() || mAnalyseWholeProgram) {
|
||||||
mAnalyseWholeProgram = false;
|
mAnalyseWholeProgram = false;
|
||||||
qDebug() << "Whole program analysis";
|
qDebug() << "Whole program analysis";
|
||||||
std::map<std::string,std::size_t> files2;
|
std::list<std::pair<std::string, std::size_t>> files2;
|
||||||
for (const QString& file : mFiles)
|
std::transform(mFiles.cbegin(), mFiles.cend(), std::back_inserter(files2), [&](const QString& file) {
|
||||||
files2[file.toStdString()] = 0;
|
return std::pair<std::string, std::size_t>{file.toStdString(), 0};
|
||||||
|
});
|
||||||
mCppcheck.analyseWholeProgram(mCppcheck.settings().buildDir, files2, {});
|
mCppcheck.analyseWholeProgram(mCppcheck.settings().buildDir, files2, {});
|
||||||
mFiles.clear();
|
mFiles.clear();
|
||||||
emit done();
|
emit done();
|
||||||
|
|
|
@ -39,6 +39,7 @@
|
||||||
#include <cctype>
|
#include <cctype>
|
||||||
#include <list>
|
#include <list>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
#include <set>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#include <numeric>
|
#include <numeric>
|
||||||
|
|
|
@ -1451,7 +1451,7 @@ void CppCheck::executeAddons(const std::vector<std::string>& files, const std::s
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CppCheck::executeAddonsWholeProgram(const std::map<std::string, std::size_t> &files)
|
void CppCheck::executeAddonsWholeProgram(const std::list<std::pair<std::string, std::size_t>> &files)
|
||||||
{
|
{
|
||||||
if (mSettings.addons.empty())
|
if (mSettings.addons.empty())
|
||||||
return;
|
return;
|
||||||
|
@ -1722,7 +1722,7 @@ bool CppCheck::analyseWholeProgram()
|
||||||
return errors && (mExitCode > 0);
|
return errors && (mExitCode > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CppCheck::analyseWholeProgram(const std::string &buildDir, const std::map<std::string, std::size_t> &files, const std::list<FileSettings>& fileSettings)
|
void CppCheck::analyseWholeProgram(const std::string &buildDir, const std::list<std::pair<std::string, std::size_t>> &files, const std::list<FileSettings>& fileSettings)
|
||||||
{
|
{
|
||||||
executeAddonsWholeProgram(files); // TODO: pass FileSettings
|
executeAddonsWholeProgram(files); // TODO: pass FileSettings
|
||||||
if (buildDir.empty()) {
|
if (buildDir.empty()) {
|
||||||
|
@ -1790,7 +1790,7 @@ bool CppCheck::isUnusedFunctionCheckEnabled() const
|
||||||
return (mSettings.useSingleJob() && mSettings.checks.isEnabled(Checks::unusedFunction));
|
return (mSettings.useSingleJob() && mSettings.checks.isEnabled(Checks::unusedFunction));
|
||||||
}
|
}
|
||||||
|
|
||||||
void CppCheck::removeCtuInfoFiles(const std::map<std::string, std::size_t> &files, const std::list<FileSettings>& fileSettings)
|
void CppCheck::removeCtuInfoFiles(const std::list<std::pair<std::string, std::size_t>> &files, const std::list<FileSettings>& fileSettings)
|
||||||
{
|
{
|
||||||
if (mSettings.buildDir.empty()) {
|
if (mSettings.buildDir.empty()) {
|
||||||
for (const auto& f: files) {
|
for (const auto& f: files) {
|
||||||
|
|
|
@ -137,14 +137,14 @@ public:
|
||||||
void analyseClangTidy(const FileSettings &fileSettings);
|
void analyseClangTidy(const FileSettings &fileSettings);
|
||||||
|
|
||||||
/** analyse whole program use .analyzeinfo files */
|
/** analyse whole program use .analyzeinfo files */
|
||||||
void analyseWholeProgram(const std::string &buildDir, const std::map<std::string, std::size_t> &files, const std::list<FileSettings>& fileSettings);
|
void analyseWholeProgram(const std::string &buildDir, const std::list<std::pair<std::string, std::size_t>> &files, const std::list<FileSettings>& fileSettings);
|
||||||
|
|
||||||
/** Check if the user wants to check for unused functions
|
/** Check if the user wants to check for unused functions
|
||||||
* and if it's possible at all */
|
* and if it's possible at all */
|
||||||
bool isUnusedFunctionCheckEnabled() const;
|
bool isUnusedFunctionCheckEnabled() const;
|
||||||
|
|
||||||
/** Remove *.ctu-info files */
|
/** Remove *.ctu-info files */
|
||||||
void removeCtuInfoFiles(const std::map<std::string, std::size_t>& files, const std::list<FileSettings>& fileSettings); // cppcheck-suppress functionConst // has side effects
|
void removeCtuInfoFiles(const std::list<std::pair<std::string, std::size_t>>& files, const std::list<FileSettings>& fileSettings); // cppcheck-suppress functionConst // has side effects
|
||||||
|
|
||||||
static void resetTimerResults();
|
static void resetTimerResults();
|
||||||
static void printTimerResults(SHOWTIME_MODES mode);
|
static void printTimerResults(SHOWTIME_MODES mode);
|
||||||
|
@ -188,7 +188,7 @@ private:
|
||||||
/**
|
/**
|
||||||
* Execute addons
|
* Execute addons
|
||||||
*/
|
*/
|
||||||
void executeAddonsWholeProgram(const std::map<std::string, std::size_t> &files);
|
void executeAddonsWholeProgram(const std::list<std::pair<std::string, std::size_t>> &files);
|
||||||
|
|
||||||
#ifdef HAVE_RULES
|
#ifdef HAVE_RULES
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -387,3 +387,48 @@ def test_project_file_filter_no_match(tmpdir):
|
||||||
]
|
]
|
||||||
|
|
||||||
assert_cppcheck(args, ec_exp=1, err_exp=[], out_exp=out_lines)
|
assert_cppcheck(args, ec_exp=1, err_exp=[], out_exp=out_lines)
|
||||||
|
|
||||||
|
|
||||||
|
def test_project_file_order(tmpdir):
|
||||||
|
test_file_a = os.path.join(tmpdir, 'a.c')
|
||||||
|
with open(test_file_a, 'wt'):
|
||||||
|
pass
|
||||||
|
test_file_b = os.path.join(tmpdir, 'b.c')
|
||||||
|
with open(test_file_b, 'wt'):
|
||||||
|
pass
|
||||||
|
test_file_c = os.path.join(tmpdir, 'c.c')
|
||||||
|
with open(test_file_c, 'wt'):
|
||||||
|
pass
|
||||||
|
test_file_d = os.path.join(tmpdir, 'd.c')
|
||||||
|
with open(test_file_d, 'wt'):
|
||||||
|
pass
|
||||||
|
|
||||||
|
project_file = os.path.join(tmpdir, 'test.cppcheck')
|
||||||
|
with open(project_file, 'wt') as f:
|
||||||
|
f.write(
|
||||||
|
"""<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project>
|
||||||
|
<paths>
|
||||||
|
<dir name="{}"/>
|
||||||
|
<dir name="{}"/>
|
||||||
|
<dir name="{}"/>
|
||||||
|
<dir name="{}"/>
|
||||||
|
</paths>
|
||||||
|
</project>""".format(test_file_c, test_file_d, test_file_b, test_file_a))
|
||||||
|
|
||||||
|
args = ['--project={}'.format(project_file)]
|
||||||
|
|
||||||
|
exitcode, stdout, stderr = cppcheck(args)
|
||||||
|
assert exitcode == 0
|
||||||
|
lines = stdout.splitlines()
|
||||||
|
assert lines == [
|
||||||
|
'Checking {} ...'.format(test_file_c),
|
||||||
|
'1/4 files checked 0% done',
|
||||||
|
'Checking {} ...'.format(test_file_d),
|
||||||
|
'2/4 files checked 0% done',
|
||||||
|
'Checking {} ...'.format(test_file_b),
|
||||||
|
'3/4 files checked 0% done',
|
||||||
|
'Checking {} ...'.format(test_file_a),
|
||||||
|
'4/4 files checked 0% done'
|
||||||
|
]
|
||||||
|
assert stderr == ''
|
||||||
|
|
|
@ -632,3 +632,35 @@ def test_file_filter_no_match(tmpdir):
|
||||||
]
|
]
|
||||||
|
|
||||||
assert_cppcheck(args, ec_exp=1, err_exp=[], out_exp=out_lines)
|
assert_cppcheck(args, ec_exp=1, err_exp=[], out_exp=out_lines)
|
||||||
|
|
||||||
|
|
||||||
|
def test_file_order(tmpdir):
|
||||||
|
test_file_a = os.path.join(tmpdir, 'a.c')
|
||||||
|
with open(test_file_a, 'wt'):
|
||||||
|
pass
|
||||||
|
test_file_b = os.path.join(tmpdir, 'b.c')
|
||||||
|
with open(test_file_b, 'wt'):
|
||||||
|
pass
|
||||||
|
test_file_c = os.path.join(tmpdir, 'c.c')
|
||||||
|
with open(test_file_c, 'wt'):
|
||||||
|
pass
|
||||||
|
test_file_d = os.path.join(tmpdir, 'd.c')
|
||||||
|
with open(test_file_d, 'wt'):
|
||||||
|
pass
|
||||||
|
|
||||||
|
args = [test_file_c, test_file_d, test_file_b, test_file_a]
|
||||||
|
|
||||||
|
exitcode, stdout, stderr = cppcheck(args)
|
||||||
|
assert exitcode == 0
|
||||||
|
lines = stdout.splitlines()
|
||||||
|
assert lines == [
|
||||||
|
'Checking {} ...'.format(test_file_c),
|
||||||
|
'1/4 files checked 0% done',
|
||||||
|
'Checking {} ...'.format(test_file_d),
|
||||||
|
'2/4 files checked 0% done',
|
||||||
|
'Checking {} ...'.format(test_file_b),
|
||||||
|
'3/4 files checked 0% done',
|
||||||
|
'Checking {} ...'.format(test_file_a),
|
||||||
|
'4/4 files checked 0% done'
|
||||||
|
]
|
||||||
|
assert stderr == ''
|
||||||
|
|
|
@ -75,7 +75,7 @@ ScopedFile::~ScopedFile() {
|
||||||
// TODO: remove all files
|
// TODO: remove all files
|
||||||
// TODO: simplify the function call
|
// TODO: simplify the function call
|
||||||
// hack to be able to delete *.plist output files
|
// hack to be able to delete *.plist output files
|
||||||
std::map<std::string, std::size_t> files;
|
std::list<std::pair<std::string, std::size_t>> files;
|
||||||
const std::string res = FileLister::addFiles(files, mPath, {".plist"}, false, PathMatch({}));
|
const std::string res = FileLister::addFiles(files, mPath, {".plist"}, false, PathMatch({}));
|
||||||
if (!res.empty()) {
|
if (!res.empty()) {
|
||||||
std::cout << "ScopedFile(" << mPath + ") - generating file list failed (" << res << ")" << std::endl;
|
std::cout << "ScopedFile(" << mPath + ") - generating file list failed (" << res << ")" << std::endl;
|
||||||
|
|
|
@ -21,8 +21,9 @@
|
||||||
#include "pathmatch.h"
|
#include "pathmatch.h"
|
||||||
#include "fixture.h"
|
#include "fixture.h"
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#include <map>
|
#include <list>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
@ -57,7 +58,7 @@ private:
|
||||||
const std::string adddir = findBaseDir() + ".";
|
const std::string adddir = findBaseDir() + ".";
|
||||||
|
|
||||||
// Recursively add add files..
|
// Recursively add add files..
|
||||||
std::map<std::string, std::size_t> files;
|
std::list<std::pair<std::string, std::size_t>> files;
|
||||||
std::vector<std::string> masks;
|
std::vector<std::string> masks;
|
||||||
PathMatch matcher(masks);
|
PathMatch matcher(masks);
|
||||||
std::string err = FileLister::recursiveAddFiles(files, adddir, matcher);
|
std::string err = FileLister::recursiveAddFiles(files, adddir, matcher);
|
||||||
|
@ -73,19 +74,25 @@ private:
|
||||||
const std::string dirprefix = adddir + "/";
|
const std::string dirprefix = adddir + "/";
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
const auto find_file = [&](const std::string& name) {
|
||||||
|
return std::find_if(files.cbegin(), files.cend(), [&name](const std::pair<std::string, std::size_t>& entry) {
|
||||||
|
return entry.first == name;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
// Make sure source files are added..
|
// Make sure source files are added..
|
||||||
ASSERT(files.find(dirprefix + "cli/main.cpp") != files.end());
|
ASSERT(find_file(dirprefix + "cli/main.cpp") != files.end());
|
||||||
ASSERT(files.find(dirprefix + "lib/token.cpp") != files.end());
|
ASSERT(find_file(dirprefix + "lib/token.cpp") != files.end());
|
||||||
ASSERT(files.find(dirprefix + "lib/tokenize.cpp") != files.end());
|
ASSERT(find_file(dirprefix + "lib/tokenize.cpp") != files.end());
|
||||||
ASSERT(files.find(dirprefix + "gui/main.cpp") != files.end());
|
ASSERT(find_file(dirprefix + "gui/main.cpp") != files.end());
|
||||||
ASSERT(files.find(dirprefix + "test/testfilelister.cpp") != files.end());
|
ASSERT(find_file(dirprefix + "test/testfilelister.cpp") != files.end());
|
||||||
|
|
||||||
// Make sure headers are not added..
|
// Make sure headers are not added..
|
||||||
ASSERT(files.find(dirprefix + "lib/tokenize.h") == files.end());
|
ASSERT(find_file(dirprefix + "lib/tokenize.h") == files.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
void recursiveAddFilesEmptyPath() const {
|
void recursiveAddFilesEmptyPath() const {
|
||||||
std::map<std::string, std::size_t> files;
|
std::list<std::pair<std::string, std::size_t>> files;
|
||||||
const std::string err = FileLister::recursiveAddFiles(files, "", PathMatch({}));
|
const std::string err = FileLister::recursiveAddFiles(files, "", PathMatch({}));
|
||||||
ASSERT_EQUALS("no path specified", err);
|
ASSERT_EQUALS("no path specified", err);
|
||||||
}
|
}
|
||||||
|
@ -93,7 +100,7 @@ private:
|
||||||
void excludeFile1() const {
|
void excludeFile1() const {
|
||||||
const std::string basedir = findBaseDir();
|
const std::string basedir = findBaseDir();
|
||||||
|
|
||||||
std::map<std::string, std::size_t> files;
|
std::list<std::pair<std::string, std::size_t>> files;
|
||||||
std::vector<std::string> ignored{"lib/token.cpp"};
|
std::vector<std::string> ignored{"lib/token.cpp"};
|
||||||
PathMatch matcher(ignored);
|
PathMatch matcher(ignored);
|
||||||
std::string err = FileLister::recursiveAddFiles(files, basedir + "lib/token.cpp", matcher);
|
std::string err = FileLister::recursiveAddFiles(files, basedir + "lib/token.cpp", matcher);
|
||||||
|
@ -104,7 +111,7 @@ private:
|
||||||
void excludeFile2() const {
|
void excludeFile2() const {
|
||||||
const std::string basedir = findBaseDir();
|
const std::string basedir = findBaseDir();
|
||||||
|
|
||||||
std::map<std::string, std::size_t> files;
|
std::list<std::pair<std::string, std::size_t>> files;
|
||||||
std::vector<std::string> ignored;
|
std::vector<std::string> ignored;
|
||||||
PathMatch matcher(ignored);
|
PathMatch matcher(ignored);
|
||||||
std::string err = FileLister::recursiveAddFiles(files, basedir + "lib/token.cpp", matcher);
|
std::string err = FileLister::recursiveAddFiles(files, basedir + "lib/token.cpp", matcher);
|
||||||
|
|
|
@ -74,11 +74,11 @@ private:
|
||||||
|
|
||||||
std::list<FileSettings> fileSettings;
|
std::list<FileSettings> fileSettings;
|
||||||
|
|
||||||
std::map<std::string, std::size_t> filemap;
|
std::list<std::pair<std::string, std::size_t>> filelist;
|
||||||
if (opt.filesList.empty()) {
|
if (opt.filesList.empty()) {
|
||||||
for (int i = 1; i <= files; ++i) {
|
for (int i = 1; i <= files; ++i) {
|
||||||
std::string f_s = fprefix() + "_" + std::to_string(i) + ".cpp";
|
std::string f_s = fprefix() + "_" + std::to_string(i) + ".cpp";
|
||||||
filemap[f_s] = data.size();
|
filelist.emplace_back(f_s, data.size());
|
||||||
if (useFS) {
|
if (useFS) {
|
||||||
FileSettings fs;
|
FileSettings fs;
|
||||||
fs.filename = std::move(f_s);
|
fs.filename = std::move(f_s);
|
||||||
|
@ -89,7 +89,7 @@ private:
|
||||||
else {
|
else {
|
||||||
for (const auto& f : opt.filesList)
|
for (const auto& f : opt.filesList)
|
||||||
{
|
{
|
||||||
filemap[f] = data.size();
|
filelist.emplace_back(f, data.size());
|
||||||
if (useFS) {
|
if (useFS) {
|
||||||
FileSettings fs;
|
FileSettings fs;
|
||||||
fs.filename = f;
|
fs.filename = f;
|
||||||
|
@ -117,15 +117,15 @@ private:
|
||||||
};
|
};
|
||||||
|
|
||||||
std::vector<std::unique_ptr<ScopedFile>> scopedfiles;
|
std::vector<std::unique_ptr<ScopedFile>> scopedfiles;
|
||||||
scopedfiles.reserve(filemap.size());
|
scopedfiles.reserve(filelist.size());
|
||||||
for (std::map<std::string, std::size_t>::const_iterator i = filemap.cbegin(); i != filemap.cend(); ++i)
|
for (std::list<std::pair<std::string, std::size_t>>::const_iterator i = filelist.cbegin(); i != filelist.cend(); ++i)
|
||||||
scopedfiles.emplace_back(new ScopedFile(i->first, data));
|
scopedfiles.emplace_back(new ScopedFile(i->first, data));
|
||||||
|
|
||||||
// clear files list so only fileSettings are used
|
// clear files list so only fileSettings are used
|
||||||
if (useFS)
|
if (useFS)
|
||||||
filemap.clear();
|
filelist.clear();
|
||||||
|
|
||||||
ProcessExecutor executor(filemap, fileSettings, s, s.nomsg, *this, executeFn);
|
ProcessExecutor executor(filelist, fileSettings, s, s.nomsg, *this, executeFn);
|
||||||
ASSERT_EQUALS(result, executor.check());
|
ASSERT_EQUALS(result, executor.check());
|
||||||
ASSERT_EQUALS(opt.executeCommandCalled, executeCommandCalled);
|
ASSERT_EQUALS(opt.executeCommandCalled, executeCommandCalled);
|
||||||
ASSERT_EQUALS(opt.exe, exe);
|
ASSERT_EQUALS(opt.exe, exe);
|
||||||
|
|
|
@ -79,11 +79,11 @@ private:
|
||||||
|
|
||||||
std::list<FileSettings> fileSettings;
|
std::list<FileSettings> fileSettings;
|
||||||
|
|
||||||
std::map<std::string, std::size_t> filemap;
|
std::list<std::pair<std::string, std::size_t>> filelist;
|
||||||
if (opt.filesList.empty()) {
|
if (opt.filesList.empty()) {
|
||||||
for (int i = 1; i <= files; ++i) {
|
for (int i = 1; i <= files; ++i) {
|
||||||
std::string f_s = fprefix() + "_" + zpad3(i) + ".cpp";
|
std::string f_s = fprefix() + "_" + zpad3(i) + ".cpp";
|
||||||
filemap[f_s] = data.size();
|
filelist.emplace_back(f_s, data.size());
|
||||||
if (useFS) {
|
if (useFS) {
|
||||||
FileSettings fs;
|
FileSettings fs;
|
||||||
fs.filename = std::move(f_s);
|
fs.filename = std::move(f_s);
|
||||||
|
@ -94,7 +94,7 @@ private:
|
||||||
else {
|
else {
|
||||||
for (const auto& f : opt.filesList)
|
for (const auto& f : opt.filesList)
|
||||||
{
|
{
|
||||||
filemap[f] = data.size();
|
filelist.emplace_back(f, data.size());
|
||||||
if (useFS) {
|
if (useFS) {
|
||||||
FileSettings fs;
|
FileSettings fs;
|
||||||
fs.filename = f;
|
fs.filename = f;
|
||||||
|
@ -123,15 +123,15 @@ private:
|
||||||
cppcheck.settings() = s;
|
cppcheck.settings() = s;
|
||||||
|
|
||||||
std::vector<std::unique_ptr<ScopedFile>> scopedfiles;
|
std::vector<std::unique_ptr<ScopedFile>> scopedfiles;
|
||||||
scopedfiles.reserve(filemap.size());
|
scopedfiles.reserve(filelist.size());
|
||||||
for (std::map<std::string, std::size_t>::const_iterator i = filemap.cbegin(); i != filemap.cend(); ++i)
|
for (std::list<std::pair<std::string, std::size_t>>::const_iterator i = filelist.cbegin(); i != filelist.cend(); ++i)
|
||||||
scopedfiles.emplace_back(new ScopedFile(i->first, data));
|
scopedfiles.emplace_back(new ScopedFile(i->first, data));
|
||||||
|
|
||||||
// clear files list so only fileSettings are used
|
// clear files list so only fileSettings are used
|
||||||
if (useFS)
|
if (useFS)
|
||||||
filemap.clear();
|
filelist.clear();
|
||||||
|
|
||||||
SingleExecutor executor(cppcheck, filemap, fileSettings, s, s.nomsg, *this);
|
SingleExecutor executor(cppcheck, filelist, fileSettings, s, s.nomsg, *this);
|
||||||
ASSERT_EQUALS(result, executor.check());
|
ASSERT_EQUALS(result, executor.check());
|
||||||
ASSERT_EQUALS(opt.executeCommandCalled, executeCommandCalled);
|
ASSERT_EQUALS(opt.executeCommandCalled, executeCommandCalled);
|
||||||
ASSERT_EQUALS(opt.exe, exe);
|
ASSERT_EQUALS(opt.exe, exe);
|
||||||
|
|
|
@ -193,9 +193,9 @@ private:
|
||||||
errout.str("");
|
errout.str("");
|
||||||
output.str("");
|
output.str("");
|
||||||
|
|
||||||
std::map<std::string, std::size_t> files;
|
std::list<std::pair<std::string, std::size_t>> files;
|
||||||
for (std::map<std::string, std::string>::const_iterator i = f.cbegin(); i != f.cend(); ++i) {
|
for (std::map<std::string, std::string>::const_iterator i = f.cbegin(); i != f.cend(); ++i) {
|
||||||
files[i->first] = i->second.size();
|
files.emplace_back(i->first, i->second.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
CppCheck cppCheck(*this, true, nullptr);
|
CppCheck cppCheck(*this, true, nullptr);
|
||||||
|
@ -227,8 +227,8 @@ private:
|
||||||
errout.str("");
|
errout.str("");
|
||||||
output.str("");
|
output.str("");
|
||||||
|
|
||||||
std::map<std::string, std::size_t> files;
|
std::list<std::pair<std::string, std::size_t>> files;
|
||||||
files["test.cpp"] = strlen(code);
|
files.emplace_back("test.cpp", strlen(code));
|
||||||
|
|
||||||
Settings settings;
|
Settings settings;
|
||||||
settings.jobs = 2;
|
settings.jobs = 2;
|
||||||
|
@ -242,7 +242,7 @@ private:
|
||||||
ThreadExecutor executor(files, fileSettings, settings, settings.nomsg, *this, CppCheckExecutor::executeCommand);
|
ThreadExecutor executor(files, fileSettings, settings, settings.nomsg, *this, CppCheckExecutor::executeCommand);
|
||||||
std::vector<std::unique_ptr<ScopedFile>> scopedfiles;
|
std::vector<std::unique_ptr<ScopedFile>> scopedfiles;
|
||||||
scopedfiles.reserve(files.size());
|
scopedfiles.reserve(files.size());
|
||||||
for (std::map<std::string, std::size_t>::const_iterator i = files.cbegin(); i != files.cend(); ++i)
|
for (std::list<std::pair<std::string, std::size_t>>::const_iterator i = files.cbegin(); i != files.cend(); ++i)
|
||||||
scopedfiles.emplace_back(new ScopedFile(i->first, code));
|
scopedfiles.emplace_back(new ScopedFile(i->first, code));
|
||||||
|
|
||||||
const unsigned int exitCode = executor.check();
|
const unsigned int exitCode = executor.check();
|
||||||
|
@ -257,8 +257,8 @@ private:
|
||||||
errout.str("");
|
errout.str("");
|
||||||
output.str("");
|
output.str("");
|
||||||
|
|
||||||
std::map<std::string, std::size_t> files;
|
std::list<std::pair<std::string, std::size_t>> files;
|
||||||
files["test.cpp"] = strlen(code);
|
files.emplace_back("test.cpp", strlen(code));
|
||||||
|
|
||||||
Settings settings;
|
Settings settings;
|
||||||
settings.jobs = 2;
|
settings.jobs = 2;
|
||||||
|
@ -272,7 +272,7 @@ private:
|
||||||
ProcessExecutor executor(files, fileSettings, settings, settings.nomsg, *this, CppCheckExecutor::executeCommand);
|
ProcessExecutor executor(files, fileSettings, settings, settings.nomsg, *this, CppCheckExecutor::executeCommand);
|
||||||
std::vector<std::unique_ptr<ScopedFile>> scopedfiles;
|
std::vector<std::unique_ptr<ScopedFile>> scopedfiles;
|
||||||
scopedfiles.reserve(files.size());
|
scopedfiles.reserve(files.size());
|
||||||
for (std::map<std::string, std::size_t>::const_iterator i = files.cbegin(); i != files.cend(); ++i)
|
for (std::list<std::pair<std::string, std::size_t>>::const_iterator i = files.cbegin(); i != files.cend(); ++i)
|
||||||
scopedfiles.emplace_back(new ScopedFile(i->first, code));
|
scopedfiles.emplace_back(new ScopedFile(i->first, code));
|
||||||
|
|
||||||
const unsigned int exitCode = executor.check();
|
const unsigned int exitCode = executor.check();
|
||||||
|
|
|
@ -74,11 +74,11 @@ private:
|
||||||
|
|
||||||
std::list<FileSettings> fileSettings;
|
std::list<FileSettings> fileSettings;
|
||||||
|
|
||||||
std::map<std::string, std::size_t> filemap;
|
std::list<std::pair<std::string, std::size_t>> filelist;
|
||||||
if (opt.filesList.empty()) {
|
if (opt.filesList.empty()) {
|
||||||
for (int i = 1; i <= files; ++i) {
|
for (int i = 1; i <= files; ++i) {
|
||||||
std::string f_s = fprefix() + "_" + std::to_string(i) + ".cpp";
|
std::string f_s = fprefix() + "_" + std::to_string(i) + ".cpp";
|
||||||
filemap[f_s] = data.size();
|
filelist.emplace_back(f_s, data.size());
|
||||||
if (useFS) {
|
if (useFS) {
|
||||||
FileSettings fs;
|
FileSettings fs;
|
||||||
fs.filename = std::move(f_s);
|
fs.filename = std::move(f_s);
|
||||||
|
@ -89,7 +89,7 @@ private:
|
||||||
else {
|
else {
|
||||||
for (const auto& f : opt.filesList)
|
for (const auto& f : opt.filesList)
|
||||||
{
|
{
|
||||||
filemap[f] = data.size();
|
filelist.emplace_back(f, data.size());
|
||||||
if (useFS) {
|
if (useFS) {
|
||||||
FileSettings fs;
|
FileSettings fs;
|
||||||
fs.filename = f;
|
fs.filename = f;
|
||||||
|
@ -118,15 +118,15 @@ private:
|
||||||
};
|
};
|
||||||
|
|
||||||
std::vector<std::unique_ptr<ScopedFile>> scopedfiles;
|
std::vector<std::unique_ptr<ScopedFile>> scopedfiles;
|
||||||
scopedfiles.reserve(filemap.size());
|
scopedfiles.reserve(filelist.size());
|
||||||
for (std::map<std::string, std::size_t>::const_iterator i = filemap.cbegin(); i != filemap.cend(); ++i)
|
for (std::list<std::pair<std::string, std::size_t>>::const_iterator i = filelist.cbegin(); i != filelist.cend(); ++i)
|
||||||
scopedfiles.emplace_back(new ScopedFile(i->first, data));
|
scopedfiles.emplace_back(new ScopedFile(i->first, data));
|
||||||
|
|
||||||
// clear files list so only fileSettings are used
|
// clear files list so only fileSettings are used
|
||||||
if (useFS)
|
if (useFS)
|
||||||
filemap.clear();
|
filelist.clear();
|
||||||
|
|
||||||
ThreadExecutor executor(filemap, fileSettings, s, s.nomsg, *this, executeFn);
|
ThreadExecutor executor(filelist, fileSettings, s, s.nomsg, *this, executeFn);
|
||||||
ASSERT_EQUALS(result, executor.check());
|
ASSERT_EQUALS(result, executor.check());
|
||||||
ASSERT_EQUALS(opt.executeCommandCalled, executeCommandCalled);
|
ASSERT_EQUALS(opt.executeCommandCalled, executeCommandCalled);
|
||||||
ASSERT_EQUALS(opt.exe, exe);
|
ASSERT_EQUALS(opt.exe, exe);
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
#include <fstream> // IWYU pragma: keep
|
#include <fstream> // IWYU pragma: keep
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <list>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <set>
|
#include <set>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
@ -139,16 +140,16 @@ static void compilefiles(std::ostream &fout, const std::vector<std::string> &fil
|
||||||
|
|
||||||
static std::string getCppFiles(std::vector<std::string> &files, const std::string &path, bool recursive)
|
static std::string getCppFiles(std::vector<std::string> &files, const std::string &path, bool recursive)
|
||||||
{
|
{
|
||||||
std::map<std::string,size_t> filemap;
|
std::list<std::pair<std::string, std::size_t>> filelist;
|
||||||
const std::set<std::string> extra;
|
const std::set<std::string> extra;
|
||||||
const std::vector<std::string> masks;
|
const std::vector<std::string> masks;
|
||||||
const PathMatch matcher(masks);
|
const PathMatch matcher(masks);
|
||||||
std::string err = FileLister::addFiles(filemap, path, extra, recursive, matcher);
|
std::string err = FileLister::addFiles(filelist, path, extra, recursive, matcher);
|
||||||
if (!err.empty())
|
if (!err.empty())
|
||||||
return err;
|
return err;
|
||||||
|
|
||||||
// add *.cpp files to the "files" vector..
|
// add *.cpp files to the "files" vector..
|
||||||
for (const std::pair<const std::string&, size_t> file : filemap) {
|
for (const std::pair<const std::string&, size_t> file : filelist) {
|
||||||
if (endsWith(file.first, ".cpp"))
|
if (endsWith(file.first, ".cpp"))
|
||||||
files.push_back(file.first);
|
files.push_back(file.first);
|
||||||
}
|
}
|
||||||
|
|
|
@ -70,7 +70,6 @@
|
||||||
<OutputFile>$(OutDir)dmake.exe</OutputFile>
|
<OutputFile>$(OutDir)dmake.exe</OutputFile>
|
||||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
<SubSystem>Console</SubSystem>
|
<SubSystem>Console</SubSystem>
|
||||||
<TargetMachine>MachineX86</TargetMachine>
|
|
||||||
</Link>
|
</Link>
|
||||||
</ItemDefinitionGroup>
|
</ItemDefinitionGroup>
|
||||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||||
|
@ -93,7 +92,6 @@
|
||||||
<SubSystem>Console</SubSystem>
|
<SubSystem>Console</SubSystem>
|
||||||
<OptimizeReferences>true</OptimizeReferences>
|
<OptimizeReferences>true</OptimizeReferences>
|
||||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||||
<TargetMachine>MachineX86</TargetMachine>
|
|
||||||
</Link>
|
</Link>
|
||||||
</ItemDefinitionGroup>
|
</ItemDefinitionGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|
Loading…
Reference in New Issue