From 252989fc6904b59b201726489e97f514fddd3d1b Mon Sep 17 00:00:00 2001 From: kaetemi Date: Sat, 3 Mar 2012 14:23:46 +0100 Subject: [PATCH] Added: #1440 Project value macros --HG-- branch : build_pipeline_v3 --- .../pipeline/service/pipeline_project.cpp | 158 ++++++++++++++++-- .../tools/pipeline/service/pipeline_project.h | 12 ++ .../pipeline/service/pipeline_service.cpp | 40 +++++ .../pipeline/service/pipeline_workspace.cpp | 11 ++ .../pipeline/service/pipeline_workspace.h | 2 +- .../DFN/pipeline/pipeline_macro.dfn | 6 + .../DFN/pipeline/pipeline_project.dfn | 5 +- .../common_interface.pipeline_project | 35 +++- 8 files changed, 249 insertions(+), 20 deletions(-) create mode 100644 code/ryzom/common/data_leveldesign/leveldesign/DFN/pipeline/pipeline_macro.dfn diff --git a/code/nel/tools/pipeline/service/pipeline_project.cpp b/code/nel/tools/pipeline/service/pipeline_project.cpp index 5fb842316..a6f1d731e 100644 --- a/code/nel/tools/pipeline/service/pipeline_project.cpp +++ b/code/nel/tools/pipeline/service/pipeline_project.cpp @@ -34,8 +34,12 @@ // NeL includes // #include #include +#include +#include +#include // Project includes +#include "pipeline_service.h" using namespace std; // using namespace NLMISC; @@ -112,31 +116,165 @@ bool CPipelineProject::getValueNb(uint &result, const std::string &name) return true; } +bool CPipelineProject::getMacro(std::string &result, const std::string &name) +{ + // TODO: Maybe preload the macros into a map. + + NLGEORGES::UFormElm *elm; + if (!m_Form->getRootNode().getNodeByName(&elm, "Macros")) + { + nlwarning("Node 'Macros' not found in '%s'", m_Form->getFilename().c_str()); + return false; + } + uint size; + if (!elm->getArraySize(size)) + { + nlwarning("Array size of node 'Macros' not found in '%s'", name.c_str(), m_Form->getFilename().c_str()); + return false; + } + for (uint i = 0; i < size; ++i) + { + NLGEORGES::UFormElm *macro; + if (!elm->getArrayNode(¯o, i)) + { + nlwarning("Array node of node 'Macros' at '%i' not found in '%s'", i, m_Form->getFilename().c_str()); + return false; + } + std::string macroName; + if (!macro->getValueByName(macroName, "Name")) + { + nlwarning("Macro does not contain value 'Name' at '%i' in '%s'", i, m_Form->getFilename().c_str()); + return false; + } + if (macroName == name) + { + std::string macroValue; + if (!macro->getValueByName(macroValue, "Value")) + { + nlwarning("Macro does not contain value 'Value' at '%i' in '%s'", i, m_Form->getFilename().c_str()); + return false; + } + parseValue(result, macroValue); + return true; + } + } + + nlwarning("Macro '%s' not found in '%s'", name.c_str(), m_Form->getFilename().c_str()); + result = std::string("[&") + name + std::string("]"); + return false; +} + +std::string CPipelineProject::getName() +{ + return NLMISC::CFile::getFilenameWithoutExtension(m_Form->getFilename()); +} + + +std::string CPipelineProject::getOutputDirectory() +{ + return g_PipelineDirectory + getName() + "/"; +} + +std::string CPipelineProject::getTempDirectory() +{ + if (m_TempDirectory.empty()) + { + std::stringstream ss; + ss << g_PipelineDirectory; + ss << getName(); + ss << "."; + ss << NLMISC::CTime::getSecondsSince1970(); + ss << "."; + ss << rand(); + ss << PIPELINE_DIRECTORY_TEMP_SUFFIX; + m_TempDirectory = ss.str(); + } + return m_TempDirectory; +} + void CPipelineProject::parseValue(std::string &result, const std::string &value) { std::stringstream ss; - std::string::const_iterator lastEnd = value.begin(); - std::string::const_iterator findOpen = find(lastEnd, value.end(), '['); - ss << std::string(lastEnd, findOpen); + std::string::const_iterator lastEndPP = value.begin(); + std::string::const_iterator findOpen = find(lastEndPP, value.end(), '['); + ss << std::string(lastEndPP, findOpen); while (findOpen != value.end()) { ++findOpen; switch (*findOpen) { - case '$': - // TODO + case '$': // SERVICE CONFIGURATION VALUE + { + ++findOpen; + lastEndPP = find(findOpen, value.end(), ']'); + std::string tagName = std::string(findOpen, lastEndPP); + if (NLNET::IService::getInstance()->ConfigFile.exists(tagName)) + { + std::string cfgValue = NLNET::IService::getInstance()->ConfigFile.getVar(tagName).asString(); + ss << cfgValue; + } + else + { + nlwarning("Unknown service configuration value '%s' in '%s'", tagName.c_str(), m_Form->getFilename().c_str()); + ss << "[$"; + ss << tagName; + ss << "]"; + } + ++lastEndPP; + } break; - case '@': - // TODO + case '!': // SPECIAL PROJECT VALUE + { + ++findOpen; + lastEndPP = find(findOpen, value.end(), ']'); + std::string tagName = std::string(findOpen, lastEndPP); + if (tagName == "OutputDirectory") + { + ss << getOutputDirectory(); + } + else if (tagName == "TempDirectory") + { + ss << getTempDirectory(); + } + else + { + nlwarning("Unknown special project value '%s' in '%s'", tagName.c_str(), m_Form->getFilename().c_str()); + ss << "[!"; + ss << tagName; + ss << "]"; + } + ++lastEndPP; + } break; - case '#': - // TODO + case '&': // PROJECT MACRO VALUE + { + ++findOpen; + lastEndPP = find(findOpen, value.end(), ']'); + std::string tagName = std::string(findOpen, lastEndPP); + std::string macroValue; + getMacro(macroValue, tagName); + ss << macroValue; + ++lastEndPP; + } break; - default: + case '@': // WORKSPACE PROJECT VALUE + // TODO + // break; + case '#': // LEVELDESIGN SHEET VALUE // TODO + // break; + default: + lastEndPP = find(findOpen, value.end(), ']'); + --findOpen; + ++lastEndPP; + std::string unknownTag = std::string(findOpen, lastEndPP); + ss << unknownTag; + nlwarning("Unknown tag '%s'", unknownTag.c_str()); break; } + findOpen = find(lastEndPP, value.end(), '['); + ss << std::string(lastEndPP, findOpen); } result = ss.str(); diff --git a/code/nel/tools/pipeline/service/pipeline_project.h b/code/nel/tools/pipeline/service/pipeline_project.h index 0f44cd25f..51666b627 100644 --- a/code/nel/tools/pipeline/service/pipeline_project.h +++ b/code/nel/tools/pipeline/service/pipeline_project.h @@ -51,6 +51,7 @@ class CPipelineProject protected: CPipelineWorkspace *m_Workspace; NLMISC::CRefPtr m_Form; + std::string m_TempDirectory; public: CPipelineProject(CPipelineWorkspace *workspace, NLGEORGES::UForm *form); @@ -60,6 +61,17 @@ public: bool getValues(std::vector &resultAppend, const std::string &name); bool getValueNb(uint &result, const std::string &name); + bool getMacro(std::string &result, const std::string &name); + + /// Gets the project name. + std::string getName(); + + /// Gets the output directory for the project. + std::string getOutputDirectory(); + + /// Gets a temporary directory for the current process. Should be created/deleted by process when (no longer) needed. Temp directories MUST NOT be shared between seperate processes, as these may run in different systems. + std::string getTempDirectory(); + private: // Strip all macros and turn all macro paths into real paths. void parseValue(std::string &result, const std::string &value); diff --git a/code/nel/tools/pipeline/service/pipeline_service.cpp b/code/nel/tools/pipeline/service/pipeline_service.cpp index a10d164e7..b7a71bc00 100644 --- a/code/nel/tools/pipeline/service/pipeline_service.cpp +++ b/code/nel/tools/pipeline/service/pipeline_service.cpp @@ -49,6 +49,7 @@ // Project includes #include "pipeline_workspace.h" +#include "pipeline_project.h" #include "database_status.h" #include "pipeline_interface_impl.h" #include "pipeline_process_impl.h" @@ -301,8 +302,10 @@ public: { g_DatabaseDirectory = CPath::standardizePath(ConfigFile.getVar("DatabaseDirectory").asString(), true); if (!CFile::isDirectory(g_DatabaseDirectory)) nlwarning("'DatabaseDirectory' does not exist! (%s)", g_DatabaseDirectory.c_str()); + ConfigFile.getVar("DatabaseDirectory").setAsString(g_DatabaseDirectory); g_PipelineDirectory = CPath::standardizePath(ConfigFile.getVar("PipelineDirectory").asString(), true); if (!CFile::isDirectory(g_PipelineDirectory)) nlwarning("'PipelineDirectory' does not exist! (%s)", g_PipelineDirectory.c_str()); + ConfigFile.getVar("PipelineDirectory").setAsString(g_PipelineDirectory); s_TaskManager = new CTaskManager(); @@ -480,6 +483,43 @@ NLMISC_COMMAND(listProcessPlugins, "List process plugins.", "") } log.displayNL("LISTPP '%s': '%s' (%s), '%s' (%s)", args[0].c_str(), it->Handler.c_str(), statusHandler.c_str(), it->Info.c_str(), statusInfo.c_str()); } + return true; +} + +NLMISC_COMMAND(showProjectMacro, "Show project macro.", " ") +{ + if(args.size() != 2) return false; + PIPELINE::CPipelineProject *project = PIPELINE::g_PipelineWorkspace->getProject(args[0]); + if (project) + { + std::string result; + project->getMacro(result, args[1]); + log.displayNL("MACRO: '%s', '%s': '%s'", args[0].c_str(), args[1].c_str(), result.c_str()); + return true; + } + else + { + log.displayNL("MACRO: Project '%s' does not exist", args[0].c_str()); + return false; + } +} + +NLMISC_COMMAND(showProjectValue, "Show project value.", " ") +{ + if(args.size() != 2) return false; + PIPELINE::CPipelineProject *project = PIPELINE::g_PipelineWorkspace->getProject(args[0]); + if (project) + { + std::string result; + project->getValue(result, args[1]); + log.displayNL("VALUE: '%s', '%s': '%s'", args[0].c_str(), args[1].c_str(), result.c_str()); + return true; + } + else + { + log.displayNL("VALUE: Project '%s' does not exist", args[0].c_str()); + return false; + } } NLNET_SERVICE_MAIN(PIPELINE::CPipelineService, PIPELINE_SHORT_SERVICE_NAME, PIPELINE_LONG_SERVICE_NAME, 0, PIPELINE::s_ShardCallbacks, PIPELINE_SERVICE_DIRECTORY, PIPELINE_SERVICE_DIRECTORY) diff --git a/code/nel/tools/pipeline/service/pipeline_workspace.cpp b/code/nel/tools/pipeline/service/pipeline_workspace.cpp index dd07f3c6a..fa2901127 100644 --- a/code/nel/tools/pipeline/service/pipeline_workspace.cpp +++ b/code/nel/tools/pipeline/service/pipeline_workspace.cpp @@ -170,6 +170,17 @@ void CPipelineWorkspace::getProcessPlugins(std::vector &resu } } +CPipelineProject *CPipelineWorkspace::getProject(const std::string &project) +{ + std::map::const_iterator it = m_Projects.find(project); + if (it == m_Projects.end()) + { + nlwarning("Project '%s' does not exist", project.c_str()); + return NULL; + } + return it->second; +} + } /* namespace PIPELINE */ /* end of file */ diff --git a/code/nel/tools/pipeline/service/pipeline_workspace.h b/code/nel/tools/pipeline/service/pipeline_workspace.h index ec9a34d67..0f41626e1 100644 --- a/code/nel/tools/pipeline/service/pipeline_workspace.h +++ b/code/nel/tools/pipeline/service/pipeline_workspace.h @@ -77,7 +77,7 @@ public: virtual ~CPipelineWorkspace(); void getProcessPlugins(std::vector &result, const std::string &process); - CPipelineProject *getProject(const std::string &project) { return m_Projects[project]; } + CPipelineProject *getProject(const std::string &project); }; /* class CPipelineWorkspace */ diff --git a/code/ryzom/common/data_leveldesign/leveldesign/DFN/pipeline/pipeline_macro.dfn b/code/ryzom/common/data_leveldesign/leveldesign/DFN/pipeline/pipeline_macro.dfn new file mode 100644 index 000000000..1df3fc0b6 --- /dev/null +++ b/code/ryzom/common/data_leveldesign/leveldesign/DFN/pipeline/pipeline_macro.dfn @@ -0,0 +1,6 @@ + + + + + Sat Mar 03 13:31:21 2012 (Kaetemi) Dfn Structure = + diff --git a/code/ryzom/common/data_leveldesign/leveldesign/DFN/pipeline/pipeline_project.dfn b/code/ryzom/common/data_leveldesign/leveldesign/DFN/pipeline/pipeline_project.dfn index c7cd1f84c..1e1c22922 100644 --- a/code/ryzom/common/data_leveldesign/leveldesign/DFN/pipeline/pipeline_project.dfn +++ b/code/ryzom/common/data_leveldesign/leveldesign/DFN/pipeline/pipeline_project.dfn @@ -1,7 +1,7 @@ - + @@ -9,5 +9,6 @@ Sat Feb 18 13:36:45 2012 (Kaetemi) Dfn Structure = Sat Feb 18 13:44:45 2012 (Kaetemi) Dfn Structure = Sat Feb 18 15:28:54 2012 (Kaetemi) Dfn Structure = -Fri Mar 02 21:21:25 2012 (Kaetemi) Dfn Structure = +Fri Mar 02 21:21:25 2012 (Kaetemi) Dfn Structure = +Sat Mar 03 13:31:41 2012 (Kaetemi) Dfn Structure = diff --git a/code/ryzom/common/data_leveldesign/leveldesign/pipeline/common_interface.pipeline_project b/code/ryzom/common/data_leveldesign/leveldesign/pipeline/common_interface.pipeline_project index d9b34c144..7e9b51407 100644 --- a/code/ryzom/common/data_leveldesign/leveldesign/pipeline/common_interface.pipeline_project +++ b/code/ryzom/common/data_leveldesign/leveldesign/pipeline/common_interface.pipeline_project @@ -2,6 +2,16 @@
+ + + + + + + + + + @@ -12,19 +22,19 @@ - + - + - + @@ -34,7 +44,7 @@ - + @@ -53,7 +63,7 @@ - + @@ -63,7 +73,7 @@ - + @@ -71,5 +81,16 @@ - Sat Mar 03 12:10:45 2012 (Kaetemi) .Description = Common Interface + Sat Mar 03 12:10:45 2012 (Kaetemi) .Description = Common Interface +Sat Mar 03 13:33:24 2012 (Kaetemi) .Interface.Atlas[0].OutputFile = [&DstInterfaceAtlas]/texture_interfaces_v3.tga +Sat Mar 03 13:33:24 2012 (Kaetemi) .Macros[0].Name = DstInterfaceAtlas +Sat Mar 03 13:33:24 2012 (Kaetemi) .Macros[0].Value = [!OutputDirectory]/interface_atlas/ +Sat Mar 03 13:33:24 2012 (Kaetemi) formName Resized = 1 +Sat Mar 03 13:33:28 2012 (Kaetemi) .Interface.Atlas[1].OutputFile = [&DstInterfaceAtlas]/texture_interfaces_v3_login.tga +Sat Mar 03 13:34:02 2012 (Kaetemi) .Interface.Atlas[1].OutputFile = [&DstInterfaceAtlas]/texture_interfaces_v3_login.tga +Sat Mar 03 13:34:02 2012 (Kaetemi) .Interface.Atlas[2].OutputFile = [&DstInterfaceAtlas]/texture_interfaces_v3_outgame_ui.tga +Sat Mar 03 13:34:02 2012 (Kaetemi) .Macros[1].Name = DstInterfaceAtlasDxtc +Sat Mar 03 13:34:02 2012 (Kaetemi) .Macros[1].Value = [!OutputDirectory]/interface_atlas_dxtc/ +Sat Mar 03 13:34:02 2012 (Kaetemi) formName Resized = 2 +Sat Mar 03 13:34:32 2012 (Kaetemi) .Interface.AtlasDxtc[0].OutputFile = [&DstInterfaceAtlasDxtc]/texture_interfaces_dxtc.tga