metaforce/hecl/driver/ToolCook.hpp

152 lines
6.3 KiB
C++
Raw Normal View History

2015-06-10 02:40:03 +00:00
#ifndef CTOOL_COOK
#define CTOOL_COOK
#include "ToolBase.hpp"
2017-12-29 07:56:31 +00:00
#include <cstdio>
2017-10-25 07:46:32 +00:00
#include "hecl/ClientProcess.hpp"
2015-06-10 02:40:03 +00:00
class ToolCook final : public ToolBase
{
2016-03-04 23:02:44 +00:00
std::vector<hecl::ProjectPath> m_selectedItems;
std::unique_ptr<hecl::Database::Project> m_fallbackProj;
hecl::Database::Project* m_useProj;
2015-09-30 06:23:07 +00:00
bool m_recursive = false;
2015-10-22 02:01:08 +00:00
bool m_fast = false;
2015-06-10 02:40:03 +00:00
public:
ToolCook(const ToolPassInfo& info)
2015-09-30 06:23:07 +00:00
: ToolBase(info), m_useProj(info.project)
2015-06-10 02:40:03 +00:00
{
2015-10-16 00:34:47 +00:00
/* Check for recursive flag */
2016-03-04 23:02:44 +00:00
for (hecl::SystemChar arg : info.flags)
2015-10-16 00:34:47 +00:00
if (arg == _S('r'))
m_recursive = true;
2015-09-30 06:23:07 +00:00
/* Scan args */
if (info.args.size())
{
/* See if project path is supplied via args and use that over the getcwd one */
2015-10-04 04:35:18 +00:00
m_selectedItems.reserve(info.args.size());
2016-03-04 23:02:44 +00:00
for (const hecl::SystemString& arg : info.args)
2015-09-30 06:23:07 +00:00
{
if (arg.empty())
continue;
2015-11-10 20:11:38 +00:00
else if (!arg.compare(_S("--fast")))
2015-10-22 02:01:08 +00:00
{
m_fast = true;
continue;
}
else if (arg.size() >= 2 && arg[0] == _S('-') && arg[1] == _S('-'))
continue;
2016-03-04 23:02:44 +00:00
hecl::SystemString subPath;
hecl::ProjectRootPath root = hecl::SearchForProject(MakePathArgAbsolute(arg, info.cwd), subPath);
2015-09-30 06:23:07 +00:00
if (root)
{
if (!m_fallbackProj)
{
2016-03-04 23:02:44 +00:00
m_fallbackProj.reset(new hecl::Database::Project(root));
2015-09-30 06:23:07 +00:00
m_useProj = m_fallbackProj.get();
}
else if (m_fallbackProj->getProjectRootPath() != root)
2016-03-04 23:02:44 +00:00
LogModule.report(logvisor::Fatal,
2015-09-30 06:23:07 +00:00
_S("hecl cook can only process multiple items in the same project; ")
_S("'%s' and '%s' are different projects"),
2017-11-13 06:13:53 +00:00
m_fallbackProj->getProjectRootPath().getAbsolutePath().data(),
root.getAbsolutePath().data());
2015-09-30 06:23:07 +00:00
m_selectedItems.emplace_back(*m_useProj, subPath);
}
}
}
if (!m_useProj)
2016-03-04 23:02:44 +00:00
LogModule.report(logvisor::Fatal,
2015-09-30 06:23:07 +00:00
"hecl cook must be ran within a project directory or "
"provided a path within a project");
2015-06-10 02:40:03 +00:00
2015-09-30 06:23:07 +00:00
/* Default case: recursive at root */
if (m_selectedItems.empty())
2015-10-04 04:35:18 +00:00
{
m_selectedItems.reserve(1);
2016-03-04 23:02:44 +00:00
m_selectedItems.push_back({hecl::ProjectPath(*m_useProj, _S(""))});
2015-10-04 04:35:18 +00:00
m_recursive = true;
}
2015-06-10 02:40:03 +00:00
}
static void Help(HelpOutput& help)
{
help.secHead(_S("NAME"));
help.beginWrap();
help.wrap(_S("hecl-cook - Cook objects within the project database\n"));
help.endWrap();
help.secHead(_S("SYNOPSIS"));
help.beginWrap();
2015-10-22 02:01:08 +00:00
help.wrap(_S("hecl cook [-rf] [--fast] [<pathspec>...]\n"));
2015-06-10 02:40:03 +00:00
help.endWrap();
help.secHead(_S("DESCRIPTION"));
help.beginWrap();
2015-07-22 19:14:50 +00:00
help.wrap(_S("This command initiates a cooking pass on the project database. Cooking ")
_S("is analogous to compiling in software development. The resulting object buffers ")
_S("are cached within the project database. HECL performs the following ")
_S("tasks for each object during the cook process:\n\n"));
2015-06-10 02:40:03 +00:00
help.wrapBold(_S("- Object Gather: "));
help.wrap(_S("Files added with "));
help.wrapBold(_S("hecl add"));
help.wrap(_S(" are queried for their dependent files (e.g. "));
help.wrapBold(_S(".blend"));
help.wrap(_S(" files return any linked "));
help.wrapBold(_S(".png"));
help.wrap(_S(" images). If the dependent files are unable to be found, the cook process aborts.\n\n"));
help.wrapBold(_S("- Modtime Comparison: "));
2015-07-22 19:14:50 +00:00
help.wrap(_S("Files that have previously finished a cook pass are inspected for their time of ")
_S("last modification. If the file hasn't changed since its previous cook-pass, the ")
_S("process is skipped. If the file has been moved or deleted, the object is automatically ")
_S("removed from the project database.\n\n"));
2015-06-10 02:40:03 +00:00
help.wrapBold(_S("- Cook: "));
2015-07-22 19:14:50 +00:00
help.wrap(_S("A type-specific procedure compiles the file's contents into an efficient format ")
_S("for use by the runtime. A data-buffer is provided to HECL.\n\n"));
2015-06-10 02:40:03 +00:00
help.wrapBold(_S("- Hash and Compress: "));
help.wrap(_S("The data-buffer is hashed and compressed before being cached in the object database.\n\n"));
help.endWrap();
help.secHead(_S("OPTIONS"));
help.optionHead(_S("<pathspec>..."), _S("input file(s)"));
help.beginWrap();
2015-07-22 19:14:50 +00:00
help.wrap(_S("Specifies working file(s) containing production data to be cooked by HECL. ")
_S("Glob-strings may be specified (e.g. "));
2015-06-10 02:40:03 +00:00
help.wrapBold(_S("*.blend"));
2015-07-22 19:14:50 +00:00
help.wrap(_S(") to automatically cook all matching current-directory files in the project database. ")
_S("If no path specified, all files in the project database are cooked.\n"));
2015-06-10 02:40:03 +00:00
help.endWrap();
help.optionHead(_S("-r"), _S("recursion"));
help.beginWrap();
help.wrap(_S("Enables recursive file-matching for cooking entire directories of working files.\n"));
help.endWrap();
2015-10-16 00:34:47 +00:00
help.optionHead(_S("-f"), _S("force"));
help.beginWrap();
help.wrap(_S("Forces cooking of all matched files, ignoring timestamp differences.\n"));
help.endWrap();
2015-10-22 02:01:08 +00:00
help.optionHead(_S("--fast"), _S("fast cook"));
help.beginWrap();
help.wrap(_S("Performs draft-optimization cooking for supported data types.\n"));
help.endWrap();
2015-06-10 02:40:03 +00:00
}
2016-03-04 23:02:44 +00:00
hecl::SystemString toolName() const {return _S("cook");}
2015-06-10 02:40:03 +00:00
int run()
{
2017-10-25 07:46:32 +00:00
hecl::ClientProcess cp(m_info.verbosityLevel, m_fast, m_info.force);
2016-03-04 23:02:44 +00:00
for (const hecl::ProjectPath& path : m_selectedItems)
2015-09-30 06:23:07 +00:00
{
int lineIdx = 0;
2017-10-25 07:46:32 +00:00
m_useProj->cookPath(path, {}, m_recursive, m_info.force, m_fast, &cp);
2015-09-30 06:23:07 +00:00
}
2017-10-25 07:46:32 +00:00
cp.waitUntilComplete();
2015-06-10 02:40:03 +00:00
return 0;
}
};
#endif // CTOOL_COOK