diff --git a/cli/cppcheckexecutor.cpp b/cli/cppcheckexecutor.cpp index 69f3e842785..f724a54ef02 100644 --- a/cli/cppcheckexecutor.cpp +++ b/cli/cppcheckexecutor.cpp @@ -272,6 +272,16 @@ int CppCheckExecutor::check(int argc, const char* const argv[]) settings.loadSummaries(); + if (settings.addonPython.empty()) + { + std::string detectedPythonExe = CppCheck::detectPython(executeCommand); + if (detectedPythonExe.empty()) { + //throw InternalError(nullptr, "Failed to auto detect python"); + return EXIT_SUCCESS; + } + settings.addonPython = std::move(detectedPythonExe); + } + mFiles = parser.getFiles(); mFileSettings = parser.getFileSettings(); diff --git a/lib/cppcheck.cpp b/lib/cppcheck.cpp index 0a8e721936b..48df3a46c1c 100644 --- a/lib/cppcheck.cpp +++ b/lib/cppcheck.cpp @@ -403,7 +403,7 @@ static void createDumpFile(const Settings& settings, << "/>\n"; } -static std::string detectPython(const CppCheck::ExecuteCmdFn &executeCommand) +std::string CppCheck::detectPython(const CppCheck::ExecuteCmdFn &executeCommand) { #ifdef _WIN32 const char *py_exes[] = { "python3.exe", "python.exe" }; @@ -445,15 +445,8 @@ static std::vector executeAddon(const AddonInfo &addonInfo, pythonExe = addonInfo.executable; else if (!addonInfo.python.empty()) pythonExe = cmdFileName(addonInfo.python); - else if (!defaultPythonExe.empty()) + else pythonExe = cmdFileName(defaultPythonExe); - else { - // store in static variable so we only look this up once - TODO: do not cache globally - static const std::string detectedPythonExe = detectPython(executeCommand); - if (detectedPythonExe.empty()) - throw InternalError(nullptr, "Failed to auto detect python"); - pythonExe = detectedPythonExe; - } std::string args; if (addonInfo.executable.empty()) diff --git a/lib/cppcheck.h b/lib/cppcheck.h index 94f2b721037..3e458dcf27f 100644 --- a/lib/cppcheck.h +++ b/lib/cppcheck.h @@ -142,6 +142,8 @@ class CPPCHECKLIB CppCheck { /** analyse whole program use .analyzeinfo files or ctuinfo string */ unsigned int analyseWholeProgram(const std::string &buildDir, const std::list &files, const std::list& fileSettings, const std::string& ctuInfo); + static std::string detectPython(const CppCheck::ExecuteCmdFn &executeCommand); + private: void purgedConfigurationMessage(const std::string &file, const std::string& configuration);