Skip to content
Draft
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
10 changes: 10 additions & 0 deletions cli/cppcheckexecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
11 changes: 2 additions & 9 deletions lib/cppcheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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" };
Expand Down Expand Up @@ -445,15 +445,8 @@ static std::vector<picojson::value> 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())
Expand Down
2 changes: 2 additions & 0 deletions lib/cppcheck.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<FileWithDetails> &files, const std::list<FileSettings>& fileSettings, const std::string& ctuInfo);

static std::string detectPython(const CppCheck::ExecuteCmdFn &executeCommand);

private:
void purgedConfigurationMessage(const std::string &file, const std::string& configuration);

Expand Down