From 2ef538c17173a4ce6538475f46a533f10d14f35f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sun, 17 May 2020 21:45:37 +0200 Subject: [PATCH] Tweak paths when executing addons in Cppcheck --- gui/mainwindow.cpp | 2 ++ lib/cppcheck.cpp | 14 +++++++++++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp index 2f8dff4ff..1e28cf3fe 100644 --- a/gui/mainwindow.cpp +++ b/gui/mainwindow.cpp @@ -924,6 +924,8 @@ Settings MainWindow::getCppcheckSettings() if (addonFilePath.isEmpty()) continue; + addonFilePath.replace(QChar('\\'), QChar('/')); + QString json; json += "{ \"script\":\"" + addonFilePath + "\""; if (!pythonCmd.isEmpty()) diff --git a/lib/cppcheck.cpp b/lib/cppcheck.cpp index 076f6b0bd..08fbfcad4 100644 --- a/lib/cppcheck.cpp +++ b/lib/cppcheck.cpp @@ -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 pipe(_popen(cmd.c_str(), "r"), _pclose);