Skip to content

Commit fd05fd7

Browse files
committed
Allow compiled addons
1 parent c4c12df commit fd05fd7

1 file changed

Lines changed: 21 additions & 7 deletions

File tree

lib/cppcheck.cpp

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,10 @@ static const CWE CWE398(398U); // Indicator of Poor Code Quality
6868
namespace {
6969
struct AddonInfo {
7070
std::string name;
71-
std::string scriptFile;
72-
std::string args;
73-
std::string python;
71+
std::string scriptFile; // addon script
72+
std::string executable; // addon executable
73+
std::string args; // special extra arguments
74+
std::string python; // script interpreter
7475
bool ctu = false;
7576
std::string runScript{};
7677

@@ -111,7 +112,7 @@ namespace {
111112
if (obj.count("ctu")) {
112113
// ctu is specified in the config file
113114
if (!obj["ctu"].is<bool>())
114-
return "Loading " + fileName + " failed. ctu must be array.";
115+
return "Loading " + fileName + " failed. ctu must be boolean.";
115116
ctu = obj["ctu"].get<bool>();
116117
} else {
117118
ctu = false;
@@ -127,6 +128,13 @@ namespace {
127128
python = "";
128129
}
129130

131+
if (obj.count("executable")) {
132+
if (!obj["executable"].is<std::string>())
133+
return "Loading " + fileName + " failed. executable must be a string.";
134+
executable = obj["executable"].get<std::string>();
135+
return "";
136+
}
137+
130138
return getAddonInfo(obj["script"].get<std::string>(), exename);
131139
}
132140

@@ -273,7 +281,9 @@ static std::string executeAddon(const AddonInfo &addonInfo,
273281

274282
std::string pythonExe;
275283

276-
if (!addonInfo.python.empty())
284+
if (!addonInfo.executable.empty())
285+
pythonExe = addonInfo.executable;
286+
else if (!addonInfo.python.empty())
277287
pythonExe = cmdFileName(addonInfo.python);
278288
else if (!defaultPythonExe.empty())
279289
pythonExe = cmdFileName(defaultPythonExe);
@@ -294,9 +304,13 @@ static std::string executeAddon(const AddonInfo &addonInfo,
294304
throw InternalError(nullptr, "Failed to auto detect python");
295305
}
296306

307+
std::string args;
308+
if (addonInfo.executable.empty())
309+
args = cmdFileName(addonInfo.runScript) + " " + cmdFileName(addonInfo.scriptFile);
310+
args += std::string(args.empty() ? "" : " ") + "--cli" + addonInfo.args;
311+
297312
const std::string fileArg = (endsWith(file, FILELIST, sizeof(FILELIST)-1) ? " --file-list " : " ") + cmdFileName(file);
298-
const std::string args =
299-
cmdFileName(addonInfo.runScript) + " " + cmdFileName(addonInfo.scriptFile) + " --cli" + addonInfo.args + fileArg;
313+
args += fileArg;
300314

301315
std::string result;
302316
if (!executeCommand(pythonExe, split(args), redirect, &result))

0 commit comments

Comments
 (0)