From 8f389a09579cbc0bab72a66363baf00f19026587 Mon Sep 17 00:00:00 2001 From: kaetemi Date: Sat, 4 Aug 2012 14:08:52 +0200 Subject: [PATCH] Added: #1440 Utility function for running console tools --HG-- branch : build_pipeline_v3 --- .../pipeline/plugin_library/pipeline_interface.h | 1 + .../pipeline/plugin_library/pipeline_process.h | 6 ++++++ .../pipeline/plugin_nel/process_interface.cpp | 14 +++++++------- .../example_cfg/pipeline_service_default.cfg | 2 ++ .../pipeline/service/pipeline_process_impl.cpp | 16 ++++++++++++++++ .../pipeline/service/pipeline_process_impl.h | 5 +++++ .../service/pipeline_process_impl_toollog.cpp | 16 +++++++++++++++- 7 files changed, 52 insertions(+), 8 deletions(-) diff --git a/code/nel/tools/pipeline/plugin_library/pipeline_interface.h b/code/nel/tools/pipeline/plugin_library/pipeline_interface.h index c4fe4af5a..3a4bd8880 100644 --- a/code/nel/tools/pipeline/plugin_library/pipeline_interface.h +++ b/code/nel/tools/pipeline/plugin_library/pipeline_interface.h @@ -59,6 +59,7 @@ public: static IPipelineInterface *getInstance(); // ***************** PLUGIN UTILITY FUNCTIONS ***************** + // ************* DO NOT USE FROM INSIDE A PROCESS ************* /// Get the configuration file of the pipeline service. Must only be used for configuration values that may be different on different services, such as tool paths. virtual NLMISC::CConfigFile &getConfigFile() = 0; diff --git a/code/nel/tools/pipeline/plugin_library/pipeline_process.h b/code/nel/tools/pipeline/plugin_library/pipeline_process.h index 5d87f7ff3..b7c611cf6 100644 --- a/code/nel/tools/pipeline/plugin_library/pipeline_process.h +++ b/code/nel/tools/pipeline/plugin_library/pipeline_process.h @@ -84,6 +84,9 @@ public: /// Delete a directory if it's empty virtual void deleteDirectoryIfEmpty(const std::string &path) = 0; + + /// Get a value from the local service configuration. Use only to get paths to tool executables and similar installed utilities + virtual std::string getConfig(const std::string &name) = 0; /// Get a value from the currently active project configuration. If false, don't use, no need to write warnings to service log, already written, set exit state and exit if necessary virtual bool getValue(std::string &result, const std::string &name) = 0; @@ -111,6 +114,9 @@ public: /// Set the exit state, must exit the plugin immediately afterwards. Use for configuration mistakes, etc virtual void setExit(const TProcessResult exitLevel, const std::string &exitMessage) = 0; + /// Run a console tool. If failed, error state is set for you, call needsExit afterwards to check + virtual void runConsoleTool(const std::string &executablePath, const std::vector &arguments) = 0; + }; /* class IPipelineProcess */ } /* namespace PIPELINE */ diff --git a/code/nel/tools/pipeline/plugin_nel/process_interface.cpp b/code/nel/tools/pipeline/plugin_nel/process_interface.cpp index cfd434cdf..1d0c557db 100644 --- a/code/nel/tools/pipeline/plugin_nel/process_interface.cpp +++ b/code/nel/tools/pipeline/plugin_nel/process_interface.cpp @@ -54,14 +54,13 @@ CProcessInterface::~CProcessInterface() void CProcessInterface::buildAtlas(const std::string &dependLog, const std::string &errorLog, const std::vector &srcDirectories, const std::string &dstFile) { nldebug("Build atlas '%s'", dstFile.c_str()); - std::stringstream ss; - ss << "build_interface -d" << dependLog << " -e" << errorLog << " " << dstFile; + std::vector arguments; + arguments.push_back(std::string("-d") + dependLog); + arguments.push_back(std::string("-e") + errorLog); + arguments.push_back(dstFile); for (std::vector::const_iterator it = srcDirectories.begin(), end = srcDirectories.end(); it != end; ++it) - { - const std::string &path = *it; - ss << " " << path; - } - system(ss.str().c_str()); + arguments.push_back(*it); + m_PipelineProcess->runConsoleTool(m_PipelineProcess->getConfig("ToolBuildInterface"), arguments); } void CProcessInterface::build() @@ -97,6 +96,7 @@ void CProcessInterface::build() { m_PipelineProcess->makePaths(dstFiles); buildAtlas(dependLog, errorLog, srcDirectories, dstFile); + if (m_PipelineProcess->needsExit()) return; m_PipelineProcess->parseToolLog(dependLog, errorLog, false); } if (m_PipelineProcess->needsExit()) return; diff --git a/code/nel/tools/pipeline/service/example_cfg/pipeline_service_default.cfg b/code/nel/tools/pipeline/service/example_cfg/pipeline_service_default.cfg index ad9767679..961c3802b 100644 --- a/code/nel/tools/pipeline/service/example_cfg/pipeline_service_default.cfg +++ b/code/nel/tools/pipeline/service/example_cfg/pipeline_service_default.cfg @@ -40,6 +40,8 @@ PrimitivesDirectory = SharedLeveldesign + "/primitives"; // ToolDirectories = { "R:/build/dev/bin/Release", "D:/libraries/external/bin" }; // ToolSuffix = ".exe"; +ToolBuildInterface = "build_interface"; + // Ignored process plugins, like CProcessMaxShape, which should be completely ignored by the master service, even if they are configured to be used inside the process sheets. // MasterIgnoreProcessPlugins = { }; // Only used by the master service. NOT USED, USE WORKSPACE INTEAD! // MasterTerminalPassword = "MASTERCLIENTPASSWORD"; // Only used by the master service. diff --git a/code/nel/tools/pipeline/service/pipeline_process_impl.cpp b/code/nel/tools/pipeline/service/pipeline_process_impl.cpp index 3d3a94e85..95824e101 100644 --- a/code/nel/tools/pipeline/service/pipeline_process_impl.cpp +++ b/code/nel/tools/pipeline/service/pipeline_process_impl.cpp @@ -36,6 +36,7 @@ #include #include #include +#include // Project includes #include "pipeline_service.h" @@ -114,6 +115,11 @@ void CPipelineProcessImpl::deleteDirectoryIfEmpty(const std::string &path) /*}*/ } +std::string CPipelineProcessImpl::getConfig(const std::string &name) +{ + return NLNET::IService::getInstance()->ConfigFile.getVar(name).asString(0); +} + bool CPipelineProcessImpl::getValue(std::string &result, const std::string &name) { if (m_ActiveProject == NULL) @@ -169,6 +175,16 @@ void CPipelineProcessImpl::makePaths(const std::vector &outputPaths } } +void CPipelineProcessImpl::runConsoleTool(const std::string &executablePath, const std::vector &arguments) +{ + // FIXME: NOT SAFE FOR ARGUMENTS WITH SPACES + std::stringstream ss; + ss << executablePath; + for (std::vector::const_iterator it = arguments.begin(), end = arguments.end(); it != end; ++it) + ss << " " << *it; + system(ss.str().c_str()); +} + } /* namespace PIPELINE */ /* end of file */ diff --git a/code/nel/tools/pipeline/service/pipeline_process_impl.h b/code/nel/tools/pipeline/service/pipeline_process_impl.h index 58aea6c5f..fa7eae072 100644 --- a/code/nel/tools/pipeline/service/pipeline_process_impl.h +++ b/code/nel/tools/pipeline/service/pipeline_process_impl.h @@ -61,6 +61,9 @@ public: virtual std::string getOutputDirectory(); virtual std::string getTempDirectory(); virtual void deleteDirectoryIfEmpty(const std::string &path); + + virtual std::string getConfig(const std::string &name); + virtual bool getValue(std::string &result, const std::string &name); virtual bool getValues(std::vector &resultAppend, const std::string &name); virtual bool getValueNb(uint &result, const std::string &name); @@ -75,6 +78,8 @@ public: virtual bool needsExit(); virtual void setExit(const TProcessResult exitLevel, const std::string &exitMessage); + virtual void runConsoleTool(const std::string &executablePath, const std::vector &arguments); + private: CProcessPluginInfo m_ActivePlugin; diff --git a/code/nel/tools/pipeline/service/pipeline_process_impl_toollog.cpp b/code/nel/tools/pipeline/service/pipeline_process_impl_toollog.cpp index b6f9cb156..bfee76067 100644 --- a/code/nel/tools/pipeline/service/pipeline_process_impl_toollog.cpp +++ b/code/nel/tools/pipeline/service/pipeline_process_impl_toollog.cpp @@ -90,6 +90,20 @@ void CPipelineProcessImpl::parseToolLog(const std::string &dependLogFile, const { m_SubTaskResult = FINISH_NOT; + if (!NLMISC::CFile::fileExists(dependLogFile)) + { + m_SubTaskErrorMessage = "Depend log does not exist"; + m_SubTaskResult = FINISH_ERROR; + return; + } + + if (!NLMISC::CFile::fileExists(errorLogFile)) + { + m_SubTaskErrorMessage = "Error log does not exist"; + m_SubTaskResult = FINISH_ERROR; + return; + } + // Parse error log { // ... @@ -223,7 +237,7 @@ void CPipelineProcessImpl::parseToolLog(const std::string &dependLogFile, const CMetadataStorage::writeDepend(depend, CMetadataStorage::getDependPath(it->first)); } } - + NLMISC::CFile::deleteFile(dependLogFile); // m_SubTaskErrorMessage = "Log parsing not implemented, goodbye";