2015-06-10 02:40:03 +00:00
|
|
|
#ifndef CTOOL_PACKAGE
|
|
|
|
#define CTOOL_PACKAGE
|
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
#include <string>
|
|
|
|
#include "ToolBase.hpp"
|
2017-12-29 07:56:31 +00:00
|
|
|
#include <cstdio>
|
2015-06-10 02:40:03 +00:00
|
|
|
|
|
|
|
class ToolPackage final : public ToolBase
|
|
|
|
{
|
2017-10-25 07:46:32 +00:00
|
|
|
std::vector<hecl::ProjectPath> m_selectedItems;
|
|
|
|
std::unique_ptr<hecl::Database::Project> m_fallbackProj;
|
|
|
|
hecl::Database::Project* m_useProj;
|
2018-03-23 21:40:12 +00:00
|
|
|
const hecl::Database::DataSpecEntry* m_spec = nullptr;
|
2017-10-25 07:46:32 +00:00
|
|
|
bool m_fast = false;
|
|
|
|
|
|
|
|
void AddSelectedItem(const hecl::ProjectPath& path)
|
|
|
|
{
|
|
|
|
for (const hecl::ProjectPath& item : m_selectedItems)
|
|
|
|
if (item == path)
|
|
|
|
return;
|
|
|
|
m_selectedItems.push_back(path);
|
|
|
|
}
|
|
|
|
|
2017-10-27 10:10:08 +00:00
|
|
|
void CheckFile(const hecl::ProjectPath& path)
|
|
|
|
{
|
2017-11-13 06:13:53 +00:00
|
|
|
if (!hecl::StrCmp(path.getLastComponent().data(), _S("!world.blend")))
|
2017-10-27 10:10:08 +00:00
|
|
|
AddSelectedItem(path);
|
2018-04-07 20:52:35 +00:00
|
|
|
#if RUNTIME_ORIGINAL_IDS
|
2017-11-13 06:13:53 +00:00
|
|
|
else if (!hecl::StrCmp(path.getLastComponent().data(), _S("!original_ids.yaml")))
|
2017-10-27 10:10:08 +00:00
|
|
|
{
|
|
|
|
auto pathComps = path.getPathComponents();
|
|
|
|
if (pathComps.size() == 2 && pathComps[0] != _S("out"))
|
|
|
|
AddSelectedItem(path);
|
|
|
|
}
|
2018-04-07 20:52:35 +00:00
|
|
|
#endif
|
2017-10-27 10:10:08 +00:00
|
|
|
}
|
|
|
|
|
2017-10-25 07:46:32 +00:00
|
|
|
void FindSelectedItems(const hecl::ProjectPath& path, bool checkGeneral)
|
|
|
|
{
|
2017-10-27 10:10:08 +00:00
|
|
|
if (path.isFile())
|
|
|
|
{
|
|
|
|
CheckFile(path);
|
|
|
|
return;
|
|
|
|
}
|
2017-10-25 07:46:32 +00:00
|
|
|
|
2017-10-27 10:10:08 +00:00
|
|
|
size_t origSize = m_selectedItems.size();
|
2017-10-25 07:46:32 +00:00
|
|
|
hecl::DirectoryEnumerator dEnum(path.getAbsolutePath(),
|
|
|
|
hecl::DirectoryEnumerator::Mode::DirsThenFilesSorted, false, false, true);
|
|
|
|
for (const auto& ent : dEnum)
|
|
|
|
{
|
|
|
|
hecl::ProjectPath childPath(path, ent.m_name);
|
|
|
|
if (ent.m_isDir)
|
|
|
|
FindSelectedItems(childPath, checkGeneral && childPath.getPathComponents().size() <= 2);
|
2017-10-27 10:10:08 +00:00
|
|
|
else
|
|
|
|
CheckFile(childPath);
|
2017-10-25 07:46:32 +00:00
|
|
|
}
|
|
|
|
|
2018-01-12 02:31:25 +00:00
|
|
|
/* Directory with 2 components not "Shared" or macOS app bundle
|
2018-01-12 01:31:25 +00:00
|
|
|
* and no nested !world.blend files == General PAK */
|
2017-10-27 10:10:08 +00:00
|
|
|
if (checkGeneral && origSize == m_selectedItems.size())
|
2017-10-25 07:46:32 +00:00
|
|
|
{
|
|
|
|
auto pathComps = path.getPathComponents();
|
2018-01-12 01:31:25 +00:00
|
|
|
if (pathComps.size() == 2 && pathComps[0] != _S("out") &&
|
2018-01-12 02:31:25 +00:00
|
|
|
pathComps[1] != _S("Shared") && pathComps[0].find(_S(".app")) == hecl::SystemString::npos)
|
2017-10-25 07:46:32 +00:00
|
|
|
AddSelectedItem(path);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-10 02:40:03 +00:00
|
|
|
public:
|
|
|
|
ToolPackage(const ToolPassInfo& info)
|
2017-10-25 07:46:32 +00:00
|
|
|
: ToolBase(info), m_useProj(info.project)
|
2015-06-10 02:40:03 +00:00
|
|
|
{
|
2015-07-08 04:26:29 +00:00
|
|
|
if (!info.project)
|
2016-03-04 23:02:44 +00:00
|
|
|
LogModule.report(logvisor::Fatal, "hecl package must be ran within a project directory");
|
2017-10-25 07:46:32 +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());
|
|
|
|
for (const hecl::SystemString& arg : info.args)
|
|
|
|
{
|
|
|
|
if (arg.empty())
|
|
|
|
continue;
|
|
|
|
else if (!arg.compare(_S("--fast")))
|
|
|
|
{
|
|
|
|
m_fast = true;
|
|
|
|
continue;
|
|
|
|
}
|
2018-03-23 21:40:12 +00:00
|
|
|
else if (arg.size() >= 8 && !arg.compare(0, 7, _S("--spec=")))
|
|
|
|
{
|
|
|
|
hecl::SystemString specName(arg.begin() + 7, arg.end());
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!m_spec)
|
|
|
|
LogModule.report(logvisor::Fatal, "unable to find data spec '%s'", specName.c_str());
|
|
|
|
continue;
|
|
|
|
}
|
2017-10-25 07:46:32 +00:00
|
|
|
else if (arg.size() >= 2 && arg[0] == _S('-') && arg[1] == _S('-'))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
hecl::SystemString subPath;
|
|
|
|
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,
|
|
|
|
_S("hecl package 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());
|
2017-10-25 07:46:32 +00:00
|
|
|
|
|
|
|
FindSelectedItems({*m_useProj, subPath}, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!m_useProj)
|
|
|
|
LogModule.report(logvisor::Fatal,
|
|
|
|
"hecl package must be ran within a project directory or "
|
|
|
|
"provided a path within a project");
|
|
|
|
|
|
|
|
/* Default case: recursive at root */
|
|
|
|
if (m_selectedItems.empty())
|
|
|
|
FindSelectedItems({*m_useProj, _S("")}, true);
|
2015-06-10 02:40:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
~ToolPackage()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static void Help(HelpOutput& help)
|
|
|
|
{
|
|
|
|
help.secHead(_S("NAME"));
|
|
|
|
help.beginWrap();
|
2015-07-22 19:14:50 +00:00
|
|
|
help.wrap(_S("hecl-pack\n")
|
|
|
|
_S("hecl-package - Package objects within the project database\n"));
|
2015-06-10 02:40:03 +00:00
|
|
|
help.endWrap();
|
|
|
|
|
|
|
|
help.secHead(_S("SYNOPSIS"));
|
|
|
|
help.beginWrap();
|
2018-03-23 21:40:12 +00:00
|
|
|
help.wrap(_S("hecl package [--spec=<spec>] [<input-dir>]\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 packaging pass on the project database. Packaging ")
|
|
|
|
_S("is analogous to linking in software development. All objects necessary to ")
|
2017-10-25 07:46:32 +00:00
|
|
|
_S("generate a complete package are gathered, grouped, and indexed within a .upak file.\n"));
|
2015-06-10 02:40:03 +00:00
|
|
|
help.endWrap();
|
|
|
|
|
|
|
|
help.secHead(_S("OPTIONS"));
|
2018-03-23 21:40:12 +00:00
|
|
|
help.optionHead(_S("--spec=<spec>"), _S("data specification"));
|
2015-06-10 02:40:03 +00:00
|
|
|
help.beginWrap();
|
2018-03-23 21:40:12 +00:00
|
|
|
help.wrap(_S("Specifies a DataSpec to use when cooking and generating the package. ")
|
|
|
|
_S("This build of hecl supports the following values of <spec>:\n"));
|
|
|
|
for (const hecl::Database::DataSpecEntry* spec : hecl::Database::DATA_SPEC_REGISTRY)
|
|
|
|
{
|
|
|
|
if (!spec->m_factory)
|
|
|
|
continue;
|
|
|
|
help.wrap(_S(" "));
|
|
|
|
help.wrapBold(spec->m_name.data());
|
|
|
|
help.wrap(_S("\n"));
|
|
|
|
}
|
2015-06-10 02:40:03 +00:00
|
|
|
help.endWrap();
|
|
|
|
|
2018-03-23 21:40:12 +00:00
|
|
|
help.secHead(_S("OPTIONS"));
|
|
|
|
help.optionHead(_S("<input-dir>"), _S("input directory"));
|
2015-06-10 02:40:03 +00:00
|
|
|
help.beginWrap();
|
2018-03-23 21:40:12 +00:00
|
|
|
help.wrap(_S("Specifies a project subdirectory to root the resulting package from. ")
|
|
|
|
_S("If any dependent files fall outside this subdirectory, they will be implicitly ")
|
|
|
|
_S("gathered and packaged.\n"));
|
2015-06-10 02:40:03 +00:00
|
|
|
help.endWrap();
|
|
|
|
}
|
|
|
|
|
2016-03-04 23:02:44 +00:00
|
|
|
hecl::SystemString toolName() const {return _S("package");}
|
2015-06-10 02:40:03 +00:00
|
|
|
|
|
|
|
int run()
|
|
|
|
{
|
2017-10-25 07:46:32 +00:00
|
|
|
if (XTERM_COLOR)
|
|
|
|
hecl::Printf(_S("" GREEN BOLD "ABOUT TO PACKAGE:" NORMAL "\n"));
|
|
|
|
else
|
|
|
|
hecl::Printf(_S("ABOUT TO PACKAGE:\n"));
|
|
|
|
|
|
|
|
for (auto& item : m_selectedItems)
|
2018-01-12 01:31:25 +00:00
|
|
|
hecl::Printf(_S(" %s\n"), item.getRelativePath().data());
|
2018-01-21 22:03:48 +00:00
|
|
|
fflush(stdout);
|
2017-10-25 07:46:32 +00:00
|
|
|
|
|
|
|
if (continuePrompt())
|
|
|
|
{
|
2018-03-23 21:40:12 +00:00
|
|
|
hecl::MultiProgressPrinter printer(true);
|
|
|
|
hecl::ClientProcess cp(&printer, m_info.verbosityLevel);
|
2017-10-25 07:46:32 +00:00
|
|
|
for (const hecl::ProjectPath& path : m_selectedItems)
|
|
|
|
{
|
2018-03-23 21:40:12 +00:00
|
|
|
if (!m_useProj->packagePath(path, printer, m_fast, m_spec, &cp))
|
2017-11-13 06:13:53 +00:00
|
|
|
LogModule.report(logvisor::Error, _S("Unable to package %s"), path.getAbsolutePath().data());
|
2017-10-25 07:46:32 +00:00
|
|
|
}
|
|
|
|
cp.waitUntilComplete();
|
|
|
|
}
|
|
|
|
|
2015-06-10 02:40:03 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // CTOOL_PACKAGE
|