diff --git a/Makefile b/Makefile index 2ddfc6c37b2..5e66da2a234 100644 --- a/Makefile +++ b/Makefile @@ -172,7 +172,7 @@ ifndef INCLUDE_FOR_LIB endif ifndef INCLUDE_FOR_CLI - INCLUDE_FOR_CLI=-Ilib -isystem externals/simplecpp -isystem externals/tinyxml2 + INCLUDE_FOR_CLI=-Ilib -isystem externals/picojson -isystem externals/simplecpp -isystem externals/tinyxml2 endif ifndef INCLUDE_FOR_TEST @@ -342,7 +342,7 @@ cppcheck: $(LIBOBJ) $(CLIOBJ) $(EXTOBJ) all: cppcheck testrunner -testrunner: $(TESTOBJ) $(LIBOBJ) $(EXTOBJ) cli/executor.o cli/processexecutor.o cli/threadexecutor.o cli/cmdlineparser.o cli/cppcheckexecutor.o cli/cppcheckexecutorseh.o cli/cppcheckexecutorsig.o cli/stacktrace.o cli/filelister.o cli/clianalysisreport.o cli/xmlanalysisreport.o cli/sarifanalysisreport.o +testrunner: $(TESTOBJ) $(LIBOBJ) $(EXTOBJ) cli/clianalysisreport.o cli/cmdlineparser.o cli/cppcheckexecutor.o cli/cppcheckexecutorseh.o cli/cppcheckexecutorsig.o cli/executor.o cli/filelister.o cli/processexecutor.o cli/sarifanalysisreport.o cli/stacktrace.o cli/threadexecutor.o cli/xmlanalysisreport.o $(CXX) $(CPPFLAGS) $(CXXFLAGS) -o $@ $^ $(LIBS) $(LDFLAGS) $(RDYNAMIC) test: all @@ -653,7 +653,7 @@ cli/processexecutor.o: cli/processexecutor.cpp cli/analysisreport.h cli/cppcheck $(CXX) ${INCLUDE_FOR_CLI} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ cli/processexecutor.cpp cli/sarifanalysisreport.o: cli/sarifanalysisreport.cpp cli/analysisreport.h cli/sarifanalysisreport.h externals/picojson/picojson.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/suppressions.h - $(CXX) ${INCLUDE_FOR_CLI} -isystem externals/picojson $(CPPFLAGS) $(CXXFLAGS) -c -o $@ cli/sarifanalysisreport.cpp + $(CXX) ${INCLUDE_FOR_CLI} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ cli/sarifanalysisreport.cpp cli/stacktrace.o: cli/stacktrace.cpp cli/stacktrace.h lib/config.h lib/utils.h $(CXX) ${INCLUDE_FOR_CLI} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ cli/stacktrace.cpp diff --git a/cli/analysisreport.h b/cli/analysisreport.h index 3c2677fcdc7..f2088a1dc27 100644 --- a/cli/analysisreport.h +++ b/cli/analysisreport.h @@ -19,10 +19,10 @@ #ifndef ANALYSIS_REPORT_H #define ANALYSIS_REPORT_H -#include "errorlogger.h" - #include +class ErrorMessage; + /** * @brief The AnalysisReport class is an abstract class meant to be sub-classed * by others classes that will contain the results of a CppCheck analysis, and @@ -33,7 +33,7 @@ class AnalysisReport { /** * Submit a CppCheck result for inclusion into the report. */ - virtual void addFinding(ErrorMessage msg) = 0; + virtual void addFinding(const ErrorMessage& msg) = 0; /** * Output the results as a string. diff --git a/cli/cli.vcxproj b/cli/cli.vcxproj index d266995de9a..78ca249a59a 100644 --- a/cli/cli.vcxproj +++ b/cli/cli.vcxproj @@ -404,6 +404,7 @@ + @@ -411,8 +412,10 @@ + + @@ -420,6 +423,7 @@ + @@ -428,8 +432,10 @@ + + diff --git a/cli/clianalysisreport.cpp b/cli/clianalysisreport.cpp index 6ff123cc29a..837ebeae736 100644 --- a/cli/clianalysisreport.cpp +++ b/cli/clianalysisreport.cpp @@ -16,11 +16,12 @@ * along with this program. If not, see . */ +#include "clianalysisreport.h" +#include "errorlogger.h" + #include #include -#include "clianalysisreport.h" - #ifdef _WIN32 #include #endif @@ -56,7 +57,7 @@ static inline std::string ansiToOEM(const std::string &msg, bool doConvert) #define ansiToOEM(msg, doConvert) (msg) #endif -void CLIAnalysisReport::addFinding(const ErrorMessage msg) { +void CLIAnalysisReport::addFinding(const ErrorMessage& msg) { const std::string errmsg = msg.toString(mVerbose, mTemplateFormat, mTemplateLocation); if (mErrorOutput) *mErrorOutput << errmsg << std::endl; diff --git a/cli/clianalysisreport.h b/cli/clianalysisreport.h index e39648f97b9..e26cd88e36b 100644 --- a/cli/clianalysisreport.h +++ b/cli/clianalysisreport.h @@ -28,7 +28,7 @@ class CLIAnalysisReport : public AnalysisReport { public: CLIAnalysisReport(bool verbose, std::string templateFormat, std::string templateLocation, std::ofstream* errorOutput); - void addFinding(const ErrorMessage msg) override; + void addFinding(const ErrorMessage& msg) override; std::string serialize() override; private: diff --git a/cli/sarifanalysisreport.cpp b/cli/sarifanalysisreport.cpp index db9485afc90..ac7edd6c51a 100644 --- a/cli/sarifanalysisreport.cpp +++ b/cli/sarifanalysisreport.cpp @@ -17,14 +17,15 @@ */ #include "sarifanalysisreport.h" +#include "errorlogger.h" #include -SARIFAnalysisReport::SARIFAnalysisReport( std::string versionNumber) +SARIFAnalysisReport::SARIFAnalysisReport(std::string versionNumber) : mVersionNumber(std::move(versionNumber)) {} -void SARIFAnalysisReport::addFinding(ErrorMessage msg) { - mFindings[msg.id].emplace_back(std::move(msg)); +void SARIFAnalysisReport::addFinding(const ErrorMessage& msg) { + mFindings[msg.id].emplace_back(msg); } #ifdef PICOJSON_USE_RVALUE_REFERENCE @@ -65,15 +66,15 @@ static std::string sarifSeverity(Severity::SeverityType severity) { } } -static std::string sarifPrecision(Certainty::CertaintyLevel certainty) { +static std::string sarifPrecision(Certainty certainty) { switch (certainty) { - case Certainty::CertaintyLevel::safe: + case Certainty::safe: return "very-high"; - case Certainty::CertaintyLevel::normal: + case Certainty::normal: return "high"; - case Certainty::CertaintyLevel::experimental: + case Certainty::experimental: return "medium"; - case Certainty::CertaintyLevel::inconclusive: + case Certainty::inconclusive: default: return "low"; } diff --git a/cli/sarifanalysisreport.h b/cli/sarifanalysisreport.h index 1a8b0ab4435..76de3871244 100644 --- a/cli/sarifanalysisreport.h +++ b/cli/sarifanalysisreport.h @@ -32,7 +32,7 @@ class SARIFAnalysisReport : public AnalysisReport { public: explicit SARIFAnalysisReport(std::string versionNumber); - void addFinding(ErrorMessage msg) override; + void addFinding(const ErrorMessage& msg) override; std::string serialize() override; private: std::string mVersionNumber; diff --git a/cli/xmlanalysisreport.cpp b/cli/xmlanalysisreport.cpp index 447993120b3..40b7c6d6f65 100644 --- a/cli/xmlanalysisreport.cpp +++ b/cli/xmlanalysisreport.cpp @@ -17,12 +17,13 @@ */ #include "xmlanalysisreport.h" +#include "errorlogger.h" XMLAnalysisReport::XMLAnalysisReport(const std::string& productName) { mBuffer << ErrorMessage::getXMLHeader(productName) << std::endl; } -void XMLAnalysisReport::addFinding(const ErrorMessage msg) { +void XMLAnalysisReport::addFinding(const ErrorMessage& msg) { mBuffer << msg.toXML() << std::endl; } diff --git a/cli/xmlanalysisreport.h b/cli/xmlanalysisreport.h index 33e1afd6f1b..2b7c7562aec 100644 --- a/cli/xmlanalysisreport.h +++ b/cli/xmlanalysisreport.h @@ -30,10 +30,10 @@ class XMLAnalysisReport : public AnalysisReport { public: explicit XMLAnalysisReport(const std::string& productName); - void addFinding(const ErrorMessage msg) override; + void addFinding(const ErrorMessage& msg) override; std::string serialize() override; private: - std::stringstream mBuffer; + std::ostringstream mBuffer; }; #endif //XML_ANALYSIS_REPORT_H diff --git a/test/testrunner.vcxproj b/test/testrunner.vcxproj index cf2cf4b11cd..e5dff0f3170 100755 --- a/test/testrunner.vcxproj +++ b/test/testrunner.vcxproj @@ -24,6 +24,7 @@ + @@ -31,8 +32,10 @@ + + @@ -106,6 +109,7 @@ + @@ -113,8 +117,10 @@ + + diff --git a/tools/dmake.cpp b/tools/dmake.cpp index 96a9be8aaaa..bfe585a1ea2 100644 --- a/tools/dmake.cpp +++ b/tools/dmake.cpp @@ -64,15 +64,18 @@ static void getDeps(const std::string &filename, std::vector &depfi if (std::find(depfiles.cbegin(), depfiles.cend(), filename) != depfiles.cend()) return; - std::ifstream f(filename.c_str()); + std::ifstream f(filename); if (!f.is_open()) { /* * Recursively search for includes in other directories. * Files are searched according to the following priority: * [test, tools] -> cli -> lib -> externals */ - if (filename.compare(0, 4, "cli/") == 0) + if (filename.compare(0, 4, "cli/") == 0) { getDeps("lib" + filename.substr(filename.find('/')), depfiles); + for (const std::string & external : externalfolders) + getDeps(external + filename.substr(filename.find('/')), depfiles); + } else if (filename.compare(0, 5, "test/") == 0) getDeps("cli" + filename.substr(filename.find('/')), depfiles); else if (filename.compare(0, 6, "tools/") == 0) @@ -632,7 +635,7 @@ int main(int argc, char **argv) makeConditionalVariable(fout, "PREFIX", "/usr"); makeConditionalVariable(fout, "INCLUDE_FOR_LIB", "-Ilib -isystem externals -isystem externals/picojson -isystem externals/simplecpp -isystem externals/tinyxml2"); - makeConditionalVariable(fout, "INCLUDE_FOR_CLI", "-Ilib -isystem externals/simplecpp -isystem externals/tinyxml2"); + makeConditionalVariable(fout, "INCLUDE_FOR_CLI", "-Ilib -isystem externals/picojson -isystem externals/simplecpp -isystem externals/tinyxml2"); makeConditionalVariable(fout, "INCLUDE_FOR_TEST", "-Ilib -Icli -isystem externals/simplecpp -isystem externals/tinyxml2"); fout << "BIN=$(DESTDIR)$(PREFIX)/bin\n\n"; @@ -652,7 +655,12 @@ int main(int argc, char **argv) fout << "cppcheck: $(LIBOBJ) $(CLIOBJ) $(EXTOBJ)\n"; fout << "\t$(CXX) $(CPPFLAGS) $(CXXFLAGS) -o $@ $^ $(LIBS) $(LDFLAGS) $(RDYNAMIC)\n\n"; fout << "all:\tcppcheck testrunner\n\n"; - fout << "testrunner: $(TESTOBJ) $(LIBOBJ) $(EXTOBJ) cli/executor.o cli/processexecutor.o cli/threadexecutor.o cli/cmdlineparser.o cli/cppcheckexecutor.o cli/cppcheckexecutorseh.o cli/cppcheckexecutorsig.o cli/stacktrace.o cli/filelister.o\n"; + fout << "testrunner: $(TESTOBJ) $(LIBOBJ) $(EXTOBJ)"; + for (const std::string& f: clifiles) { + if (f != "cli/main.cpp") + fout << " " << f.substr(0, f.find(".")) << ".o"; + } + fout << "\n"; fout << "\t$(CXX) $(CPPFLAGS) $(CXXFLAGS) -o $@ $^ $(LIBS) $(LDFLAGS) $(RDYNAMIC)\n\n"; fout << "test:\tall\n"; fout << "\t./testrunner\n\n";