Added: #1440 Utility function for running console tools

--HG--
branch : build_pipeline_v3
hg/feature/build_pipeline_v3
kaetemi 12 years ago
parent f9bddebfd8
commit 8f389a0957

@ -59,6 +59,7 @@ public:
static IPipelineInterface *getInstance(); static IPipelineInterface *getInstance();
// ***************** PLUGIN UTILITY FUNCTIONS ***************** // ***************** 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. /// 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; virtual NLMISC::CConfigFile &getConfigFile() = 0;

@ -85,6 +85,9 @@ public:
/// Delete a directory if it's empty /// Delete a directory if it's empty
virtual void deleteDirectoryIfEmpty(const std::string &path) = 0; 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 /// 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; virtual bool getValue(std::string &result, const std::string &name) = 0;
virtual bool getValues(std::vector<std::string> &resultAppend, const std::string &name) = 0; virtual bool getValues(std::vector<std::string> &resultAppend, 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 /// 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; 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<std::string> &arguments) = 0;
}; /* class IPipelineProcess */ }; /* class IPipelineProcess */
} /* namespace PIPELINE */ } /* namespace PIPELINE */

@ -54,14 +54,13 @@ CProcessInterface::~CProcessInterface()
void CProcessInterface::buildAtlas(const std::string &dependLog, const std::string &errorLog, const std::vector<std::string> &srcDirectories, const std::string &dstFile) void CProcessInterface::buildAtlas(const std::string &dependLog, const std::string &errorLog, const std::vector<std::string> &srcDirectories, const std::string &dstFile)
{ {
nldebug("Build atlas '%s'", dstFile.c_str()); nldebug("Build atlas '%s'", dstFile.c_str());
std::stringstream ss; std::vector<std::string> arguments;
ss << "build_interface -d" << dependLog << " -e" << errorLog << " " << dstFile; arguments.push_back(std::string("-d") + dependLog);
arguments.push_back(std::string("-e") + errorLog);
arguments.push_back(dstFile);
for (std::vector<std::string>::const_iterator it = srcDirectories.begin(), end = srcDirectories.end(); it != end; ++it) for (std::vector<std::string>::const_iterator it = srcDirectories.begin(), end = srcDirectories.end(); it != end; ++it)
{ arguments.push_back(*it);
const std::string &path = *it; m_PipelineProcess->runConsoleTool(m_PipelineProcess->getConfig("ToolBuildInterface"), arguments);
ss << " " << path;
}
system(ss.str().c_str());
} }
void CProcessInterface::build() void CProcessInterface::build()
@ -97,6 +96,7 @@ void CProcessInterface::build()
{ {
m_PipelineProcess->makePaths(dstFiles); m_PipelineProcess->makePaths(dstFiles);
buildAtlas(dependLog, errorLog, srcDirectories, dstFile); buildAtlas(dependLog, errorLog, srcDirectories, dstFile);
if (m_PipelineProcess->needsExit()) return;
m_PipelineProcess->parseToolLog(dependLog, errorLog, false); m_PipelineProcess->parseToolLog(dependLog, errorLog, false);
} }
if (m_PipelineProcess->needsExit()) return; if (m_PipelineProcess->needsExit()) return;

@ -40,6 +40,8 @@ PrimitivesDirectory = SharedLeveldesign + "/primitives";
// ToolDirectories = { "R:/build/dev/bin/Release", "D:/libraries/external/bin" }; // ToolDirectories = { "R:/build/dev/bin/Release", "D:/libraries/external/bin" };
// ToolSuffix = ".exe"; // 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. // 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! // MasterIgnoreProcessPlugins = { }; // Only used by the master service. NOT USED, USE WORKSPACE INTEAD!
// MasterTerminalPassword = "MASTERCLIENTPASSWORD"; // Only used by the master service. // MasterTerminalPassword = "MASTERCLIENTPASSWORD"; // Only used by the master service.

@ -36,6 +36,7 @@
#include <nel/misc/app_context.h> #include <nel/misc/app_context.h>
#include <nel/misc/debug.h> #include <nel/misc/debug.h>
#include <nel/misc/path.h> #include <nel/misc/path.h>
#include <nel/net/service.h>
// Project includes // Project includes
#include "pipeline_service.h" #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) bool CPipelineProcessImpl::getValue(std::string &result, const std::string &name)
{ {
if (m_ActiveProject == NULL) if (m_ActiveProject == NULL)
@ -169,6 +175,16 @@ void CPipelineProcessImpl::makePaths(const std::vector<std::string> &outputPaths
} }
} }
void CPipelineProcessImpl::runConsoleTool(const std::string &executablePath, const std::vector<std::string> &arguments)
{
// FIXME: NOT SAFE FOR ARGUMENTS WITH SPACES
std::stringstream ss;
ss << executablePath;
for (std::vector<std::string>::const_iterator it = arguments.begin(), end = arguments.end(); it != end; ++it)
ss << " " << *it;
system(ss.str().c_str());
}
} /* namespace PIPELINE */ } /* namespace PIPELINE */
/* end of file */ /* end of file */

@ -61,6 +61,9 @@ public:
virtual std::string getOutputDirectory(); virtual std::string getOutputDirectory();
virtual std::string getTempDirectory(); virtual std::string getTempDirectory();
virtual void deleteDirectoryIfEmpty(const std::string &path); 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 getValue(std::string &result, const std::string &name);
virtual bool getValues(std::vector<std::string> &resultAppend, const std::string &name); virtual bool getValues(std::vector<std::string> &resultAppend, const std::string &name);
virtual bool getValueNb(uint &result, const std::string &name); virtual bool getValueNb(uint &result, const std::string &name);
@ -75,6 +78,8 @@ public:
virtual bool needsExit(); virtual bool needsExit();
virtual void setExit(const TProcessResult exitLevel, const std::string &exitMessage); virtual void setExit(const TProcessResult exitLevel, const std::string &exitMessage);
virtual void runConsoleTool(const std::string &executablePath, const std::vector<std::string> &arguments);
private: private:
CProcessPluginInfo m_ActivePlugin; CProcessPluginInfo m_ActivePlugin;

@ -90,6 +90,20 @@ void CPipelineProcessImpl::parseToolLog(const std::string &dependLogFile, const
{ {
m_SubTaskResult = FINISH_NOT; 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 // Parse error log
{ {
// ... // ...

Loading…
Cancel
Save