74 lines
3.2 KiB
C++
74 lines
3.2 KiB
C++
#include "MetaCoreDelivery/MetaCoreBuildPipeline.h"
|
|
|
|
#include <filesystem>
|
|
#include <iostream>
|
|
#include <string_view>
|
|
|
|
namespace {
|
|
|
|
void PrintIssue(const MetaCore::MetaCoreBuildIssue& issue) {
|
|
std::cerr << MetaCore::MetaCoreBuildErrorCodeName(issue.Code) << ": " << issue.Message;
|
|
if (!issue.Path.empty()) std::cerr << " path=" << issue.Path.generic_string();
|
|
if (!issue.Expected.empty()) std::cerr << " expected=" << issue.Expected;
|
|
if (!issue.Actual.empty()) std::cerr << " actual=" << issue.Actual;
|
|
std::cerr << '\n';
|
|
}
|
|
|
|
[[nodiscard]] const char* NextValue(int& index, int argc, char* argv[]) {
|
|
if (index + 1 >= argc) return nullptr;
|
|
return argv[++index];
|
|
}
|
|
|
|
void PrintUsage() {
|
|
std::cerr
|
|
<< "Usage:\n"
|
|
<< " MetaCoreBuildTool build --project <path> --profile <path> --engine-build <path> [--clean] [--skip-build]\n"
|
|
<< " MetaCoreBuildTool validate --package <path>\n";
|
|
}
|
|
|
|
} // namespace
|
|
|
|
int main(int argc, char* argv[]) {
|
|
if (argc < 2) { PrintUsage(); return 2; }
|
|
const std::string_view command(argv[1]);
|
|
if (command == "validate") {
|
|
std::filesystem::path package;
|
|
for (int index = 2; index < argc; ++index) {
|
|
if (std::string_view(argv[index]) == "--package") {
|
|
const char* value = NextValue(index, argc, argv);
|
|
if (value != nullptr) package = value;
|
|
}
|
|
}
|
|
if (package.empty()) { PrintUsage(); return 2; }
|
|
const auto issues = MetaCore::MetaCoreValidateReleasePackage(package);
|
|
for (const auto& issue : issues) PrintIssue(issue);
|
|
if (!issues.empty()) return 1;
|
|
std::cout << "MetaCore release package is valid: " << package.generic_string() << '\n';
|
|
return 0;
|
|
}
|
|
if (command != "build") { PrintUsage(); return 2; }
|
|
|
|
MetaCore::MetaCoreBuildRequest request;
|
|
for (int index = 2; index < argc; ++index) {
|
|
const std::string_view argument(argv[index]);
|
|
if (argument == "--project") {
|
|
const char* value = NextValue(index, argc, argv); if (value != nullptr) request.ProjectRoot = value;
|
|
} else if (argument == "--profile") {
|
|
const char* value = NextValue(index, argc, argv); if (value != nullptr) request.ProfilePath = value;
|
|
} else if (argument == "--engine-build") {
|
|
const char* value = NextValue(index, argc, argv); if (value != nullptr) request.EngineBuildRoot = value;
|
|
} else if (argument == "--clean") request.Clean = true;
|
|
else if (argument == "--skip-build") request.SkipBuild = true;
|
|
}
|
|
MetaCore::MetaCoreBuildPipeline pipeline;
|
|
const auto result = pipeline.Run(request, [](MetaCore::MetaCoreBuildStage stage, std::string_view message) {
|
|
std::cout << '[' << MetaCore::MetaCoreBuildStageName(stage) << "] " << message << '\n';
|
|
});
|
|
for (const auto& issue : result.Issues) PrintIssue(issue);
|
|
if (!result.Success) return 1;
|
|
std::cout << "package=" << result.PackageDirectory.generic_string() << '\n'
|
|
<< "archive=" << result.ArchivePath.generic_string() << '\n';
|
|
if (!result.SymbolsArchivePath.empty()) std::cout << "symbols=" << result.SymbolsArchivePath.generic_string() << '\n';
|
|
return 0;
|
|
}
|