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
33 changes: 26 additions & 7 deletions cli/cmdlineparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,25 @@ CmdLineParser::Result CmdLineParser::parseFromArgs(int argc, const char* const a
else if (std::strcmp(argv[i], "--debug-lookup") == 0)
mSettings.debuglookup = true;

else if (std::strncmp(argv[i], "--debug-lookup=", 15) == 0) {
const std::string lookup = argv[i] + 15;
if (lookup == "all")
mSettings.debuglookup = true;
else if (lookup == "addon")
mSettings.debuglookupAddon = true;
else if (lookup == "config")
mSettings.debuglookupConfig = true;
else if (lookup == "library")
mSettings.debuglookupLibrary = true;
else if (lookup == "platform")
mSettings.debuglookupPlatform = true;
else
{
mLogger.printError("unknown lookup '" + lookup + "'");
return Result::Fail;
}
}

// Flag used for various purposes during debugging
else if (std::strcmp(argv[i], "--debug-simplified") == 0)
mSettings.debugSimplified = true;
Expand Down Expand Up @@ -927,7 +946,7 @@ CmdLineParser::Result CmdLineParser::parseFromArgs(int argc, const char* const a

std::string errstr;
const std::vector<std::string> paths = {argv[0]};
if (!mSettings.platform.set(platform, errstr, paths)) {
if (!mSettings.platform.set(platform, errstr, paths, mSettings.debuglookup || mSettings.debuglookupPlatform)) {
mLogger.printError(errstr);
return Result::Fail;
}
Expand Down Expand Up @@ -1021,7 +1040,7 @@ CmdLineParser::Result CmdLineParser::parseFromArgs(int argc, const char* const a
if (!platform.empty()) {
std::string errstr;
const std::vector<std::string> paths = {projectFile, argv[0]};
if (!mSettings.platform.set(platform, errstr, paths)) {
if (!mSettings.platform.set(platform, errstr, paths, mSettings.debuglookup || mSettings.debuglookupPlatform)) {
mLogger.printError(errstr);
return Result::Fail;
}
Expand Down Expand Up @@ -1819,7 +1838,7 @@ std::string CmdLineParser::getVersion() const {

bool CmdLineParser::isCppcheckPremium() const {
if (mSettings.cppcheckCfgProductName.empty())
Settings::loadCppcheckCfg(mSettings, mSettings.supprs);
Settings::loadCppcheckCfg(mSettings, mSettings.supprs, mSettings.debuglookup || mSettings.debuglookupConfig);
return startsWith(mSettings.cppcheckCfgProductName, "Cppcheck Premium");
}

Expand Down Expand Up @@ -1872,7 +1891,7 @@ bool CmdLineParser::tryLoadLibrary(Library& destination, const std::string& base

bool CmdLineParser::loadLibraries(Settings& settings)
{
if (!tryLoadLibrary(settings.library, settings.exename, "std.cfg", settings.debuglookup)) {
if (!tryLoadLibrary(settings.library, settings.exename, "std.cfg", settings.debuglookup || settings.debuglookupLibrary)) {
const std::string msg("Failed to load std.cfg. Your Cppcheck installation is broken, please re-install.");
#ifdef FILESDIR
const std::string details("The Cppcheck binary was compiled with FILESDIR set to \""
Expand All @@ -1890,7 +1909,7 @@ bool CmdLineParser::loadLibraries(Settings& settings)

bool result = true;
for (const auto& lib : settings.libraries) {
if (!tryLoadLibrary(settings.library, settings.exename, lib.c_str(), settings.debuglookup)) {
if (!tryLoadLibrary(settings.library, settings.exename, lib.c_str(), settings.debuglookup || settings.debuglookupLibrary)) {
result = false;
}
}
Expand All @@ -1902,7 +1921,7 @@ bool CmdLineParser::loadAddons(Settings& settings)
bool result = true;
for (const std::string &addon: settings.addons) {
AddonInfo addonInfo;
const std::string failedToGetAddonInfo = addonInfo.getAddonInfo(addon, settings.exename);
const std::string failedToGetAddonInfo = addonInfo.getAddonInfo(addon, settings.exename, settings.debuglookup || settings.debuglookupAddon);
if (!failedToGetAddonInfo.empty()) {
mLogger.printRaw(failedToGetAddonInfo); // TODO: do not print as raw
result = false;
Expand All @@ -1915,7 +1934,7 @@ bool CmdLineParser::loadAddons(Settings& settings)

bool CmdLineParser::loadCppcheckCfg()
{
const std::string cfgErr = Settings::loadCppcheckCfg(mSettings, mSuppressions);
const std::string cfgErr = Settings::loadCppcheckCfg(mSettings, mSuppressions, mSettings.debuglookup || mSettings.debuglookupConfig);
if (!cfgErr.empty()) {
mLogger.printError("could not load cppcheck.cfg - " + cfgErr);
return false;
Expand Down
18 changes: 14 additions & 4 deletions lib/addoninfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,29 @@

#include "json.h"

static std::string getFullPath(const std::string &fileName, const std::string &exename) {
static std::string getFullPath(const std::string &fileName, const std::string &exename, bool debug = false) {
if (debug)
std::cout << "looking for addon '" << fileName << "'" << std::endl;
if (Path::isFile(fileName))
return fileName;

const std::string exepath = Path::getPathFromFilename(exename);
if (debug)
std::cout << "looking for addon '" << (exepath + fileName) << "'" << std::endl;
Comment thread
danmar marked this conversation as resolved.
if (Path::isFile(exepath + fileName))
return exepath + fileName;
if (debug)
std::cout << "looking for addon '" << (exepath + "addons/" + fileName) << "'" << std::endl;
if (Path::isFile(exepath + "addons/" + fileName))
return exepath + "addons/" + fileName;

#ifdef FILESDIR
if (debug)
std::cout << "looking for addon '" << (FILESDIR + ("/" + fileName)) << "'" << std::endl;
if (Path::isFile(FILESDIR + ("/" + fileName)))
return FILESDIR + ("/" + fileName);
if (debug)
std::cout << "looking for addon '" << (FILESDIR + ("/addons/" + fileName)) << "'" << std::endl;
if (Path::isFile(FILESDIR + ("/addons/" + fileName)))
return FILESDIR + ("/addons/" + fileName);
#endif
Expand Down Expand Up @@ -124,18 +134,18 @@ static std::string parseAddonInfo(AddonInfo& addoninfo, const picojson::value &j
return addoninfo.getAddonInfo(val.get<std::string>(), exename);
}

std::string AddonInfo::getAddonInfo(const std::string &fileName, const std::string &exename) {
std::string AddonInfo::getAddonInfo(const std::string &fileName, const std::string &exename, bool debug) {
if (fileName[0] == '{') {
picojson::value json;
const std::string err = picojson::parse(json, fileName);
(void)err; // TODO: report
return parseAddonInfo(*this, json, fileName, exename);
}
if (fileName.find('.') == std::string::npos)
return getAddonInfo(fileName + ".py", exename);
return getAddonInfo(fileName + ".py", exename, debug);

if (endsWith(fileName, ".py")) {
scriptFile = Path::fromNativeSeparators(getFullPath(fileName, exename));
scriptFile = Path::fromNativeSeparators(getFullPath(fileName, exename, debug));
if (scriptFile.empty())
return "Did not find addon " + fileName;

Expand Down
2 changes: 1 addition & 1 deletion lib/addoninfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ struct CPPCHECKLIB AddonInfo {
bool ctu = false;
std::string runScript;

std::string getAddonInfo(const std::string &fileName, const std::string &exename);
std::string getAddonInfo(const std::string &fileName, const std::string &exename, bool debug = false);
};

#endif // addonInfoH
14 changes: 7 additions & 7 deletions lib/platform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ bool Platform::set(Type t)
return false;
}

bool Platform::set(const std::string& platformstr, std::string& errstr, const std::vector<std::string>& paths, bool verbose)
bool Platform::set(const std::string& platformstr, std::string& errstr, const std::vector<std::string>& paths, bool debug)
{
if (platformstr == "win32A")
set(Type::Win32A);
Expand All @@ -173,9 +173,9 @@ bool Platform::set(const std::string& platformstr, std::string& errstr, const st
else {
bool found = false;
for (const std::string& path : paths) {
if (verbose)
if (debug)
std::cout << "looking for platform '" + platformstr + "' in '" + path + "'" << std::endl;
if (loadFromFile(path.c_str(), platformstr, verbose)) {
if (loadFromFile(path.c_str(), platformstr, debug)) {
found = true;
break;
}
Expand All @@ -189,7 +189,7 @@ bool Platform::set(const std::string& platformstr, std::string& errstr, const st
return true;
}

bool Platform::loadFromFile(const char exename[], const std::string &filename, bool verbose)
bool Platform::loadFromFile(const char exename[], const std::string &filename, bool debug)
{
// TODO: only append .xml if missing
// TODO: use native separators
Expand All @@ -216,15 +216,15 @@ bool Platform::loadFromFile(const char exename[], const std::string &filename, b
tinyxml2::XMLDocument doc;
bool success = false;
for (const std::string & f : filenames) {
if (verbose)
if (debug)
std::cout << "try to load platform file '" << f << "' ... ";
if (doc.LoadFile(f.c_str()) == tinyxml2::XML_SUCCESS) {
if (verbose)
if (debug)
std::cout << "Success" << std::endl;
success = true;
break;
}
if (verbose)
if (debug)
std::cout << doc.ErrorStr() << std::endl;
}
if (!success)
Expand Down
6 changes: 3 additions & 3 deletions lib/platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,16 +122,16 @@ class CPPCHECKLIB Platform {
bool set(Type t);

/** set the platform type */
bool set(const std::string& platformstr, std::string& errstr, const std::vector<std::string>& paths = {}, bool verbose = false);
bool set(const std::string& platformstr, std::string& errstr, const std::vector<std::string>& paths = {}, bool debug = false);

/**
* load platform file
* @param exename application path
* @param filename platform filename
* @param verbose log verbose information about the lookup
* @param debug log verbose information about the lookup
* @return returns true if file was loaded successfully
*/
bool loadFromFile(const char exename[], const std::string &filename, bool verbose = false);
bool loadFromFile(const char exename[], const std::string &filename, bool debug = false);

/** load platform from xml document, primarily for testing */
bool loadFromXmlDocument(const tinyxml2::XMLDocument *doc);
Expand Down
17 changes: 14 additions & 3 deletions lib/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,21 +62,32 @@ Settings::Settings()
pid = getPid();
}

std::string Settings::loadCppcheckCfg(Settings& settings, Suppressions& suppressions)
std::string Settings::loadCppcheckCfg(Settings& settings, Suppressions& suppressions, bool debug)
{
// TODO: this always needs to be run *after* the Settings has been filled
static const std::string cfgFilename = "cppcheck.cfg";
std::string fileName;
#ifdef FILESDIR
if (Path::isFile(Path::join(FILESDIR, cfgFilename)))
fileName = Path::join(FILESDIR, cfgFilename);
{
const std::string filesdirCfg = Path::join(FILESDIR, cfgFilename);
if (debug)
std::cout << "looking for '" << filesdirCfg << "'" << std::endl;
if (Path::isFile(filesdirCfg))
fileName = filesdirCfg;
}
#endif
// cppcheck-suppress knownConditionTrueFalse
if (fileName.empty()) {
// TODO: make sure that exename is set
fileName = Path::getPathFromFilename(settings.exename) + cfgFilename;
if (debug)
std::cout << "looking for '" << fileName << "'" << std::endl;
if (!Path::isFile(fileName))
{
if (debug)
std::cout << "no configuration found" << std::endl;
return "";
}
}

std::ifstream fin(fileName);
Expand Down
16 changes: 14 additions & 2 deletions lib/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ class CPPCHECKLIB WARN_UNUSED Settings {
public:
Settings();

static std::string loadCppcheckCfg(Settings& settings, Suppressions& suppressions);
static std::string loadCppcheckCfg(Settings& settings, Suppressions& suppressions, bool debug = false);

static std::pair<std::string, std::string> getNameAndVersion(const std::string& productName);

Expand Down Expand Up @@ -174,9 +174,21 @@ class CPPCHECKLIB WARN_UNUSED Settings {
/** @brief Are we running from DACA script? */
bool daca{};

/** @brief Internal: Is --debug-lookup given? */
/** @brief Internal: Is --debug-lookup or --debug-lookup=all given? */
bool debuglookup{};

/** @brief Internal: Is --debug-lookup=addon given? */
bool debuglookupAddon{};

/** @brief Internal: Is --debug-lookup=config given? */
bool debuglookupConfig{};

/** @brief Internal: Is --debug-lookup=library given? */
bool debuglookupLibrary{};

/** @brief Internal: Is --debug-lookup=platform given? */
bool debuglookupPlatform{};

/** @brief Is --debug-normal given? */
bool debugnormal{};

Expand Down
Loading