Allow compiled addons

This commit is contained in:
Daniel Marjamäki 2021-10-11 19:26:51 +02:00
parent c4c12df372
commit fd05fd7934
1 changed files with 21 additions and 7 deletions

View File

@ -68,9 +68,10 @@ static const CWE CWE398(398U); // Indicator of Poor Code Quality
namespace { namespace {
struct AddonInfo { struct AddonInfo {
std::string name; std::string name;
std::string scriptFile; std::string scriptFile; // addon script
std::string args; std::string executable; // addon executable
std::string python; std::string args; // special extra arguments
std::string python; // script interpreter
bool ctu = false; bool ctu = false;
std::string runScript{}; std::string runScript{};
@ -111,7 +112,7 @@ namespace {
if (obj.count("ctu")) { if (obj.count("ctu")) {
// ctu is specified in the config file // ctu is specified in the config file
if (!obj["ctu"].is<bool>()) if (!obj["ctu"].is<bool>())
return "Loading " + fileName + " failed. ctu must be array."; return "Loading " + fileName + " failed. ctu must be boolean.";
ctu = obj["ctu"].get<bool>(); ctu = obj["ctu"].get<bool>();
} else { } else {
ctu = false; ctu = false;
@ -127,6 +128,13 @@ namespace {
python = ""; python = "";
} }
if (obj.count("executable")) {
if (!obj["executable"].is<std::string>())
return "Loading " + fileName + " failed. executable must be a string.";
executable = obj["executable"].get<std::string>();
return "";
}
return getAddonInfo(obj["script"].get<std::string>(), exename); return getAddonInfo(obj["script"].get<std::string>(), exename);
} }
@ -273,7 +281,9 @@ static std::string executeAddon(const AddonInfo &addonInfo,
std::string pythonExe; std::string pythonExe;
if (!addonInfo.python.empty()) if (!addonInfo.executable.empty())
pythonExe = addonInfo.executable;
else if (!addonInfo.python.empty())
pythonExe = cmdFileName(addonInfo.python); pythonExe = cmdFileName(addonInfo.python);
else if (!defaultPythonExe.empty()) else if (!defaultPythonExe.empty())
pythonExe = cmdFileName(defaultPythonExe); pythonExe = cmdFileName(defaultPythonExe);
@ -294,9 +304,13 @@ static std::string executeAddon(const AddonInfo &addonInfo,
throw InternalError(nullptr, "Failed to auto detect python"); throw InternalError(nullptr, "Failed to auto detect python");
} }
std::string args;
if (addonInfo.executable.empty())
args = cmdFileName(addonInfo.runScript) + " " + cmdFileName(addonInfo.scriptFile);
args += std::string(args.empty() ? "" : " ") + "--cli" + addonInfo.args;
const std::string fileArg = (endsWith(file, FILELIST, sizeof(FILELIST)-1) ? " --file-list " : " ") + cmdFileName(file); const std::string fileArg = (endsWith(file, FILELIST, sizeof(FILELIST)-1) ? " --file-list " : " ") + cmdFileName(file);
const std::string args = args += fileArg;
cmdFileName(addonInfo.runScript) + " " + cmdFileName(addonInfo.scriptFile) + " --cli" + addonInfo.args + fileArg;
std::string result; std::string result;
if (!executeCommand(pythonExe, split(args), redirect, &result)) if (!executeCommand(pythonExe, split(args), redirect, &result))