Tweak paths when executing addons in Cppcheck

This commit is contained in:
Daniel Marjamäki 2020-05-17 21:45:37 +02:00
parent 9eda399323
commit 2ef538c171
2 changed files with 13 additions and 3 deletions

View File

@ -924,6 +924,8 @@ Settings MainWindow::getCppcheckSettings()
if (addonFilePath.isEmpty())
continue;
addonFilePath.replace(QChar('\\'), QChar('/'));
QString json;
json += "{ \"script\":\"" + addonFilePath + "\"";
if (!pythonCmd.isEmpty())

View File

@ -156,16 +156,24 @@ namespace {
};
}
static std::string cmdFileName(std::string f)
{
f = Path::toNativeSeparators(f);
if (f.find(" ") != std::string::npos)
return "\"" + f + "\"";
return f;
}
static std::string executeAddon(const AddonInfo &addonInfo,
const std::string &defaultPythonExe,
const std::string &dumpFile)
{
std::string pythonExe = (addonInfo.python != "") ? addonInfo.python : defaultPythonExe;
std::string pythonExe = cmdFileName((addonInfo.python != "") ? addonInfo.python : defaultPythonExe);
if (pythonExe.find(" ") != std::string::npos) {
// popen strips the first quote. Needs 2 sets to fully quote.
pythonExe = "\"\"" + pythonExe + "\"\"";
pythonExe = "\"" + pythonExe + "\"";
}
// Can python be executed?
@ -187,7 +195,7 @@ static std::string executeAddon(const AddonInfo &addonInfo,
throw InternalError(nullptr, "Failed to execute '" + cmd + "' (" + result + ")");
}
const std::string cmd = pythonExe + " \"" + addonInfo.scriptFile + "\" --cli" + addonInfo.args + " \"" + dumpFile + "\" 2>&1";
const std::string cmd = pythonExe + " " + cmdFileName(addonInfo.scriptFile) + " --cli" + addonInfo.args + " " + cmdFileName(dumpFile) + " 2>&1";
#ifdef _WIN32
std::unique_ptr<FILE, decltype(&_pclose)> pipe(_popen(cmd.c_str(), "r"), _pclose);