diff --git a/commandLine/src/addons/ofAddon.cpp b/commandLine/src/addons/ofAddon.cpp index bbffcbf7..5816c615 100644 --- a/commandLine/src/addons/ofAddon.cpp +++ b/commandLine/src/addons/ofAddon.cpp @@ -112,6 +112,7 @@ ofAddon::ofAddon(const ofAddon& other): xcframeworks(other.xcframeworks), data(other.data), defines(other.defines), + afterCompileScript(other.afterCompileScript), definesCMAKE(other.definesCMAKE), name(other.name), addonPath(other.addonPath), @@ -528,6 +529,11 @@ void ofAddon::parseVariableValue(const string & variable, const string & value, else if (variable == ADDON_DEFINES) { addReplaceStringVector(defines, value, emptyString, addToValue); } + + else if (variable == ADDON_AFTER_COMPILE_SCRIPT) { + if (!addToValue) afterCompileScript.clear(); + if (!value.empty()) afterCompileScript.emplace_back(value); + } } template diff --git a/commandLine/src/addons/ofAddon.h b/commandLine/src/addons/ofAddon.h index b1f51933..a88e89f4 100644 --- a/commandLine/src/addons/ofAddon.h +++ b/commandLine/src/addons/ofAddon.h @@ -85,6 +85,7 @@ const string ADDON_PKG_CONFIG_LIBRARIES = "ADDON_PKG_CONFIG_LIBRARIES"; const string ADDON_FRAMEWORKS = "ADDON_FRAMEWORKS"; const string ADDON_XCFRAMEWORKS = "ADDON_XCFRAMEWORKS"; const string ADDON_DLLS_TO_COPY = "ADDON_DLLS_TO_COPY"; +const string ADDON_AFTER_COMPILE_SCRIPT = "ADDON_AFTER_COMPILE_SCRIPT"; // About Metadata const string ADDON_NAME = "ADDON_NAME"; @@ -129,6 +130,7 @@ const vector AddonProjectVariables = { ADDON_FRAMEWORKS, ADDON_DLLS_TO_COPY, ADDON_ADDITIONAL_LIBS, + ADDON_AFTER_COMPILE_SCRIPT, }; class ofAddon { @@ -176,6 +178,7 @@ class ofAddon { vector < string > xcframeworks; // osx only vector < string > data; vector < string > defines; + vector < string > afterCompileScript; // one entry per line, run after the build vector < string > definesCMAKE; diff --git a/commandLine/src/main.cpp b/commandLine/src/main.cpp index 98cd6453..01fa2ce7 100644 --- a/commandLine/src/main.cpp +++ b/commandLine/src/main.cpp @@ -32,7 +32,8 @@ enum optionIndex { UNKNOWN, BACKUP_PROJECT_FILES, FRAMEWORKS, CLEANNAME_DISABLE, - DEFINES + DEFINES, + POSTBUILD }; constexpr option::Descriptor usage[] = { @@ -60,6 +61,7 @@ constexpr option::Descriptor usage[] = { { CLEANNAME_DISABLE, 0, "n", "cleanname", option::Arg::Optional, " --cleanname, -f \tcleanname" }, { DEFINES, 0, "D", "defines", option::Arg::Optional, " --defines, -D \tpreprocessor defines list (such as OF_USE_ANGLE=1,MY_FLAG)" }, + { POSTBUILD, 0, "P", "postbuild", option::Arg::Optional, " --postbuild, -P \tscript to run after the project compiles (Xcode run script / VS post-build event)" }, { 0, 0, 0, 0, 0, 0 } }; @@ -88,6 +90,7 @@ vector srcPaths; vector targets; vector frameworks; vector defines; +string postBuildScript; string ofPathEnv; string templateName; @@ -275,6 +278,9 @@ void updateProject(const fs::path & path, const string & target, bool bConsiderP for (auto & d : defines) { project->addProjectDefine(d); } + if (!postBuildScript.empty()) { + project->addProjectAfterRule(postBuildScript); + } for (auto & srcPath : srcPaths) { project->addSrcRecursively(srcPath); @@ -596,6 +602,10 @@ int main(int argc, char ** argv) { defines = ofSplitString(options[DEFINES].arg, ",", true, true); } + if (options[POSTBUILD].count() > 0 && options[POSTBUILD].arg != NULL) { + postBuildScript = ofTrim(options[POSTBUILD].arg); + } + if (parse.nonOptionsCount() > 0) { projectName = parse.nonOption(0); @@ -750,6 +760,9 @@ int main(int argc, char ** argv) { for (auto & d : defines) { project->addProjectDefine(d); } + if (!postBuildScript.empty()) { + project->addProjectAfterRule(postBuildScript); + } for (auto & s : srcPaths) { project->addSrcRecursively(s); diff --git a/commandLine/src/projects/baseProject.cpp b/commandLine/src/projects/baseProject.cpp index fe606b7c..f3a0f701 100644 --- a/commandLine/src/projects/baseProject.cpp +++ b/commandLine/src/projects/baseProject.cpp @@ -586,6 +586,10 @@ void baseProject::addAddon(ofAddon & addon){ addAddonDefines(addon); addAddonFrameworks(addon); + if (!addon.afterCompileScript.empty()) { + ofLogVerbose() << "adding addon after compile script: " << addon.name; + addAfterRule(ofJoinString(addon.afterCompileScript, "\n")); + } copyAddonData(addon); addAddonProps(addon); } @@ -793,14 +797,12 @@ void baseProject::parseConfigMake(){ auto config = ofTrim(line); if(config[0] == '#') continue; if(config == "") continue; - if(config.find("=")!=string::npos){ - auto varValue = ofSplitString(config,"=",true,true); - if(varValue.size()>1){ - auto var = ofTrim(varValue[0]); - auto value = ofTrim(varValue[1]); - if (var=="PROJECT_AFTER_OSX" && target=="osx"){ - addAfterRule(value); - } + auto eq = config.find("="); + if(eq!=string::npos){ + auto var = ofTrim(config.substr(0, eq)); + auto value = ofTrim(config.substr(eq + 1)); + if (var=="PROJECT_AFTER_OSX" && target=="osx" && !value.empty()){ + addAfterRule(value); } } } diff --git a/commandLine/src/projects/baseProject.h b/commandLine/src/projects/baseProject.h index b9433c54..1ea482e0 100644 --- a/commandLine/src/projects/baseProject.h +++ b/commandLine/src/projects/baseProject.h @@ -105,6 +105,8 @@ class baseProject { addDefine(define, libType); projectDefines.emplace_back(define); } + // project-level post-build script (-P/--postbuild) + void addProjectAfterRule(const std::string & script) { addAfterRule(script); } #ifdef OFADDON_OUTPUT_JSON_DEBUG diff --git a/commandLine/src/projects/visualStudioProject.cpp b/commandLine/src/projects/visualStudioProject.cpp index 78d808f4..6e4e855a 100644 --- a/commandLine/src/projects/visualStudioProject.cpp +++ b/commandLine/src/projects/visualStudioProject.cpp @@ -593,6 +593,22 @@ void visualStudioProject::addCPPFLAG(const string& cppflag, LibType libType){ } +void visualStudioProject::addAfterRule(const string & script) { + pugi::xpath_node_set commands = doc.select_nodes("//ItemDefinitionGroup/PostBuildEvent/Command"); + if (commands.empty()) { + for (auto & event : doc.select_nodes("//ItemDefinitionGroup/PostBuildEvent")) { + event.node().append_child("Command").append_child(pugi::node_pcdata); + } + commands = doc.select_nodes("//ItemDefinitionGroup/PostBuildEvent/Command"); + } + for (auto & command : commands) { + pugi::xml_node text = command.node().first_child(); + if (!text) text = command.node().append_child(pugi::node_pcdata); + string value = ofTrim(text.value()); + text.set_value((value.empty() ? script : value + "\n" + script).c_str()); + } +} + void visualStudioProject::addDefine(const string& define, LibType libType) { addCompileOption("PreprocessorDefinitions", define, ";", libType); // pugi::xpath_node_set items = doc.select_nodes("//ItemDefinitionGroup"); diff --git a/commandLine/src/projects/visualStudioProject.h b/commandLine/src/projects/visualStudioProject.h index c417ccc8..570bc876 100644 --- a/commandLine/src/projects/visualStudioProject.h +++ b/commandLine/src/projects/visualStudioProject.h @@ -26,7 +26,7 @@ class visualStudioProject : public baseProject { } void addLDFLAG(const std::string& ldflag, LibType libType = RELEASE_LIB) override {} - void addAfterRule(const std::string& script) override {} + void addAfterRule(const std::string& script) override; diff --git a/commandLine/src/projects/xcodeProject.cpp b/commandLine/src/projects/xcodeProject.cpp index 73b380a8..5e683f13 100644 --- a/commandLine/src/projects/xcodeProject.cpp +++ b/commandLine/src/projects/xcodeProject.cpp @@ -598,24 +598,20 @@ void xcodeProject::addCPPFLAG(const string & cppflag, LibType libType) { } void xcodeProject::addAfterRule(const string & rule) { - // return; - // cout << ">>>>>> addAfterRule " << rule << endl; - addCommand("Add :objects:" + afterPhaseUUID + ":buildActionMask string 2147483647"); - // addCommand("Add :objects:"+afterPhaseUUID+":files array"); - // addCommand("Add :objects:"+afterPhaseUUID+":inputPaths array"); - addCommand("Add :objects:" + afterPhaseUUID + ":isa string PBXShellScriptBuildPhase"); - // addCommand("Add :objects:"+afterPhaseUUID+":outputPaths array"); - addCommand("Add :objects:" + afterPhaseUUID + ":runOnlyForDeploymentPostprocessing string 0"); - addCommand("Add :objects:" + afterPhaseUUID + ":shellPath string /bin/sh"); - addCommand("Add :objects:" + afterPhaseUUID + ":showEnvVarsInLog string 0"); - - // ofStringReplace(rule, "\"", "\\\""); - // addCommand("Add :objects:"+afterPhaseUUID+":shellScript string \"" + rule + "\""); - addCommand("Add :objects:" + afterPhaseUUID + ":shellScript string " + rule); - - // adding this phase to build phases array - // TODO: Check if nit needs another buildConfigurationListUUID for debug. - addCommand("Add :objects:" + buildConfigurationListUUID + ":buildPhases: string " + afterPhaseUUID); + // own phase per script, so several addons don't overwrite each other + string phaseUUID { generateUUID("afterCompile-" + rule) }; + addCommand("Add :objects:" + phaseUUID + ":buildActionMask string 2147483647"); + addCommand("Add :objects:" + phaseUUID + ":files array"); + addCommand("Add :objects:" + phaseUUID + ":inputPaths array"); + addCommand("Add :objects:" + phaseUUID + ":outputPaths array"); + addCommand("Add :objects:" + phaseUUID + ":isa string PBXShellScriptBuildPhase"); + addCommand("Add :objects:" + phaseUUID + ":name string Run Script - After Compile"); + addCommand("Add :objects:" + phaseUUID + ":runOnlyForDeploymentPostprocessing string 0"); + addCommand("Add :objects:" + phaseUUID + ":shellPath string /bin/sh"); + addCommand("Add :objects:" + phaseUUID + ":showEnvVarsInLog string 0"); + addCommand("Add :objects:" + phaseUUID + ":shellScript string " + rule); + // buildConfigurationListUUID is the app's PBXNativeTarget + addCommand("Add :objects:" + buildConfigurationListUUID + ":buildPhases: string " + phaseUUID); } void xcodeProject::addAddonLibs(const ofAddon & addon) { diff --git a/frontend/app.js b/frontend/app.js index c0e9c479..7adeb08c 100644 --- a/frontend/app.js +++ b/frontend/app.js @@ -1223,7 +1223,8 @@ function generate() { addonList: addonValueArray, //$("#addonsDropdown").val(); ofPath: $("#ofPath").val(), verbose: bVerbose, - defines: definesArr.join(',') + defines: definesArr.join(','), + postBuild: $('#postBuildScript').val().trim() }; // console.log(gen); @@ -1354,6 +1355,7 @@ function enableAdvancedMode(isAdvanced) { $('#ofPathButton').show(); $('#emsdkField').show(); $('#customDefinesField').show(); + $('#postBuildField').show(); if (!defaultSettings['detachConsole']) { $('body').addClass('showConsole'); } @@ -1372,6 +1374,7 @@ function enableAdvancedMode(isAdvanced) { $('#ofPathButton').hide(); $('#emsdkField').hide(); $('#customDefinesField').hide(); + $('#postBuildField').hide(); $("body").removeClass('advanced'); $('a.updateMultiMenuOption').hide(); } diff --git a/frontend/index.html b/frontend/index.html index 60728eae..bbf9416c 100644 --- a/frontend/index.html +++ b/frontend/index.html @@ -302,6 +302,10 @@ +