2018-10-07 03:38:44 +00:00
|
|
|
#pragma once
|
2015-06-10 02:40:03 +00:00
|
|
|
|
|
|
|
#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
|
|
|
|
2018-12-08 05:18:42 +00:00
|
|
|
class ToolCook final : public ToolBase {
|
|
|
|
std::vector<hecl::ProjectPath> m_selectedItems;
|
|
|
|
std::unique_ptr<hecl::Database::Project> m_fallbackProj;
|
|
|
|
hecl::Database::Project* m_useProj;
|
|
|
|
const hecl::Database::DataSpecEntry* m_spec = nullptr;
|
|
|
|
bool m_recursive = false;
|
|
|
|
bool m_fast = false;
|
2015-10-16 00:34:47 +00:00
|
|
|
|
2018-12-08 05:18:42 +00:00
|
|
|
public:
|
2019-08-20 02:49:24 +00:00
|
|
|
explicit ToolCook(const ToolPassInfo& info) : ToolBase(info), m_useProj(info.project) {
|
2018-12-08 05:18:42 +00:00
|
|
|
/* Check for recursive flag */
|
2021-06-30 18:20:45 +00:00
|
|
|
for (char arg : info.flags)
|
|
|
|
if (arg == 'r')
|
2018-12-08 05:18:42 +00:00
|
|
|
m_recursive = true;
|
2015-10-22 02:01:08 +00:00
|
|
|
|
2018-12-08 05:18:42 +00:00
|
|
|
/* Scan args */
|
|
|
|
if (info.args.size()) {
|
|
|
|
/* See if project path is supplied via args and use that over the getcwd one */
|
|
|
|
m_selectedItems.reserve(info.args.size());
|
2021-06-30 18:20:45 +00:00
|
|
|
for (const std::string& arg : info.args) {
|
2018-12-08 05:18:42 +00:00
|
|
|
if (arg.empty())
|
|
|
|
continue;
|
2021-06-30 18:20:45 +00:00
|
|
|
else if (arg == "--fast") {
|
2018-12-08 05:18:42 +00:00
|
|
|
m_fast = true;
|
|
|
|
continue;
|
2021-06-30 18:20:45 +00:00
|
|
|
} else if (arg.size() >= 8 && !arg.compare(0, 7, "--spec=")) {
|
|
|
|
std::string specName(arg.begin() + 7, arg.end());
|
2018-12-08 05:18:42 +00:00
|
|
|
for (const hecl::Database::DataSpecEntry* spec : hecl::Database::DATA_SPEC_REGISTRY) {
|
|
|
|
if (!hecl::StrCaseCmp(spec->m_name.data(), specName.c_str())) {
|
|
|
|
m_spec = spec;
|
|
|
|
break;
|
2015-09-30 06:23:07 +00:00
|
|
|
}
|
2018-12-08 05:18:42 +00:00
|
|
|
}
|
|
|
|
if (!m_spec)
|
2021-06-30 18:20:45 +00:00
|
|
|
LogModule.report(logvisor::Fatal, FMT_STRING("unable to find data spec '{}'"), specName);
|
2018-12-08 05:18:42 +00:00
|
|
|
continue;
|
2021-06-30 18:20:45 +00:00
|
|
|
} else if (arg.size() >= 2 && arg[0] == '-' && arg[1] == '-')
|
2018-12-08 05:18:42 +00:00
|
|
|
continue;
|
2015-06-10 02:40:03 +00:00
|
|
|
|
2021-06-30 18:20:45 +00:00
|
|
|
std::string subPath;
|
2018-12-08 05:18:42 +00:00
|
|
|
hecl::ProjectRootPath root = hecl::SearchForProject(MakePathArgAbsolute(arg, info.cwd), subPath);
|
|
|
|
if (root) {
|
|
|
|
if (!m_fallbackProj) {
|
|
|
|
m_fallbackProj.reset(new hecl::Database::Project(root));
|
|
|
|
m_useProj = m_fallbackProj.get();
|
|
|
|
} else if (m_fallbackProj->getProjectRootPath() != root)
|
|
|
|
LogModule.report(logvisor::Fatal,
|
2021-06-30 18:20:45 +00:00
|
|
|
FMT_STRING("hecl cook can only process multiple items in the same project; "
|
|
|
|
"'{}' and '{}' are different projects"),
|
2019-07-20 04:22:58 +00:00
|
|
|
m_fallbackProj->getProjectRootPath().getAbsolutePath(),
|
|
|
|
root.getAbsolutePath());
|
2018-12-08 05:18:42 +00:00
|
|
|
m_selectedItems.emplace_back(*m_useProj, subPath);
|
2015-10-04 04:35:18 +00:00
|
|
|
}
|
2018-12-08 05:18:42 +00:00
|
|
|
}
|
2015-06-10 02:40:03 +00:00
|
|
|
}
|
2018-12-08 05:18:42 +00:00
|
|
|
if (!m_useProj)
|
|
|
|
LogModule.report(logvisor::Fatal,
|
2020-04-11 22:48:11 +00:00
|
|
|
FMT_STRING("hecl cook must be ran within a project directory or "
|
2019-07-20 04:22:58 +00:00
|
|
|
"provided a path within a project"));
|
2015-06-10 02:40:03 +00:00
|
|
|
|
2018-12-08 05:18:42 +00:00
|
|
|
/* Default case: recursive at root */
|
|
|
|
if (m_selectedItems.empty()) {
|
|
|
|
m_selectedItems.reserve(1);
|
2021-06-30 18:20:45 +00:00
|
|
|
m_selectedItems.push_back({hecl::ProjectPath(*m_useProj, "")});
|
2018-12-08 05:18:42 +00:00
|
|
|
m_recursive = true;
|
|
|
|
}
|
|
|
|
}
|
2015-06-10 02:40:03 +00:00
|
|
|
|
2018-12-08 05:18:42 +00:00
|
|
|
static void Help(HelpOutput& help) {
|
2021-06-30 18:20:45 +00:00
|
|
|
help.secHead("NAME");
|
2018-12-08 05:18:42 +00:00
|
|
|
help.beginWrap();
|
2021-06-30 18:20:45 +00:00
|
|
|
help.wrap("hecl-cook - Cook objects within the project database\n");
|
2018-12-08 05:18:42 +00:00
|
|
|
help.endWrap();
|
2015-06-10 02:40:03 +00:00
|
|
|
|
2021-06-30 18:20:45 +00:00
|
|
|
help.secHead("SYNOPSIS");
|
2018-12-08 05:18:42 +00:00
|
|
|
help.beginWrap();
|
2021-06-30 18:20:45 +00:00
|
|
|
help.wrap("hecl cook [-rf] [--fast] [--spec=<spec>] [<pathspec>...]\n");
|
2018-12-08 05:18:42 +00:00
|
|
|
help.endWrap();
|
|
|
|
|
2021-06-30 18:20:45 +00:00
|
|
|
help.secHead("DESCRIPTION");
|
2018-12-08 05:18:42 +00:00
|
|
|
help.beginWrap();
|
2021-06-30 18:20:45 +00:00
|
|
|
help.wrap(
|
|
|
|
"This command initiates a cooking pass on the project database. Cooking "
|
|
|
|
"is analogous to compiling in software development. The resulting object buffers "
|
|
|
|
"are cached within the project database. HECL performs the following "
|
|
|
|
"tasks for each object during the cook process:\n\n");
|
|
|
|
help.wrapBold("- Object Gather: ");
|
|
|
|
help.wrap("Files added with ");
|
|
|
|
help.wrapBold("hecl add");
|
|
|
|
help.wrap(" are queried for their dependent files (e.g. ");
|
|
|
|
help.wrapBold(".blend");
|
|
|
|
help.wrap(" files return any linked ");
|
|
|
|
help.wrapBold(".png");
|
|
|
|
help.wrap(" images). If the dependent files are unable to be found, the cook process aborts.\n\n");
|
|
|
|
help.wrapBold("- Modtime Comparison: ");
|
|
|
|
help.wrap(
|
|
|
|
"Files that have previously finished a cook pass are inspected for their time of "
|
|
|
|
"last modification. If the file hasn't changed since its previous cook-pass, the "
|
|
|
|
"process is skipped. If the file has been moved or deleted, the object is automatically "
|
|
|
|
"removed from the project database.\n\n");
|
|
|
|
help.wrapBold("- Cook: ");
|
|
|
|
help.wrap(
|
|
|
|
"A type-specific procedure compiles the file's contents into an efficient format "
|
|
|
|
"for use by the runtime. A data-buffer is provided to HECL.\n\n");
|
|
|
|
help.wrapBold("- Hash and Compress: ");
|
|
|
|
help.wrap("The data-buffer is hashed and compressed before being cached in the object database.\n\n");
|
2018-12-08 05:18:42 +00:00
|
|
|
help.endWrap();
|
2015-06-10 02:40:03 +00:00
|
|
|
|
2021-06-30 18:20:45 +00:00
|
|
|
help.secHead("OPTIONS");
|
|
|
|
help.optionHead("<pathspec>...", "input file(s)");
|
2018-12-08 05:18:42 +00:00
|
|
|
help.beginWrap();
|
2021-06-30 18:20:45 +00:00
|
|
|
help.wrap(
|
|
|
|
"Specifies working file(s) containing production data to be cooked by HECL. "
|
|
|
|
"Glob-strings may be specified (e.g. ");
|
|
|
|
help.wrapBold("*.blend");
|
|
|
|
help.wrap(
|
|
|
|
") to automatically cook all matching current-directory files in the project database. "
|
|
|
|
"If no path specified, all files in the project database are cooked.\n");
|
2018-12-08 05:18:42 +00:00
|
|
|
help.endWrap();
|
2015-06-10 02:40:03 +00:00
|
|
|
|
2021-06-30 18:20:45 +00:00
|
|
|
help.optionHead("-r", "recursion");
|
2018-12-08 05:18:42 +00:00
|
|
|
help.beginWrap();
|
2021-06-30 18:20:45 +00:00
|
|
|
help.wrap("Enables recursive file-matching for cooking entire directories of working files.\n");
|
2018-12-08 05:18:42 +00:00
|
|
|
help.endWrap();
|
2021-06-30 18:20:45 +00:00
|
|
|
help.optionHead("-f", "force");
|
2018-12-08 05:18:42 +00:00
|
|
|
help.beginWrap();
|
2021-06-30 18:20:45 +00:00
|
|
|
help.wrap("Forces cooking of all matched files, ignoring timestamp differences.\n");
|
2018-12-08 05:18:42 +00:00
|
|
|
help.endWrap();
|
2021-06-30 18:20:45 +00:00
|
|
|
help.optionHead("--fast", "fast cook");
|
2018-12-08 05:18:42 +00:00
|
|
|
help.beginWrap();
|
2021-06-30 18:20:45 +00:00
|
|
|
help.wrap("Performs draft-optimization cooking for supported data types.\n");
|
2018-12-08 05:18:42 +00:00
|
|
|
help.endWrap();
|
2018-03-23 21:40:12 +00:00
|
|
|
|
2021-06-30 18:20:45 +00:00
|
|
|
help.optionHead("--spec=<spec>", "data specification");
|
2018-12-08 05:18:42 +00:00
|
|
|
help.beginWrap();
|
2021-06-30 18:20:45 +00:00
|
|
|
help.wrap(
|
|
|
|
"Specifies a DataSpec to use when cooking. "
|
|
|
|
"This build of hecl supports the following values of <spec>:\n");
|
2018-12-08 05:18:42 +00:00
|
|
|
for (const hecl::Database::DataSpecEntry* spec : hecl::Database::DATA_SPEC_REGISTRY) {
|
|
|
|
if (!spec->m_factory)
|
|
|
|
continue;
|
2021-06-30 18:20:45 +00:00
|
|
|
help.wrap(" ");
|
2018-12-08 05:18:42 +00:00
|
|
|
help.wrapBold(spec->m_name.data());
|
2021-06-30 18:20:45 +00:00
|
|
|
help.wrap("\n");
|
2015-06-10 02:40:03 +00:00
|
|
|
}
|
2018-12-08 05:18:42 +00:00
|
|
|
}
|
2015-06-10 02:40:03 +00:00
|
|
|
|
2021-06-30 18:20:45 +00:00
|
|
|
std::string_view toolName() const override { return "cook"sv; }
|
2015-06-10 02:40:03 +00:00
|
|
|
|
2019-08-20 02:34:12 +00:00
|
|
|
int run() override {
|
2018-12-08 05:18:42 +00:00
|
|
|
hecl::MultiProgressPrinter printer(true);
|
|
|
|
hecl::ClientProcess cp(&printer);
|
|
|
|
for (const hecl::ProjectPath& path : m_selectedItems)
|
|
|
|
m_useProj->cookPath(path, printer, m_recursive, m_info.force, m_fast, m_spec, &cp);
|
|
|
|
cp.waitUntilComplete();
|
|
|
|
return 0;
|
|
|
|
}
|
2018-05-26 03:07:04 +00:00
|
|
|
|
2019-08-20 02:34:12 +00:00
|
|
|
void cancel() override { m_useProj->interruptCook(); }
|
2015-06-10 02:40:03 +00:00
|
|
|
};
|