Skip to content

isAPILoaded to the beginning of the file and BUILD-INFO validation script #840

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
104 changes: 49 additions & 55 deletions tools/nsc/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,42 @@ class ShaderCompiler final : public system::IApplicationFramework
const auto argc = argv.size();
const bool insufficientArguments = argc < 2;

if (not insufficientArguments)
if (not isAPILoaded())
{
// 1) NOTE: imo each example should be able to dump build info & have such mode, maybe it could go straight to IApplicationFramework main
// 2) TODO: this whole "serialize" logic should go to the GitInfo struct and be static or something, it should be standardized
std::cerr << "Could not load Nabla API, terminating!";
return false;
}

if (argv[1] == "--dump-build-info")
{
json j;
if (system)
m_system = std::move(system);
else
m_system = system::IApplicationFramework::createSystem();

auto& modules = j["modules"];
if (!m_system)
return false;

auto serialize = [&](const gtml::GitInfo& info, std::string_view target) -> void
m_logger = make_smart_refctd_ptr<CStdoutLogger>(core::bitflag(ILogger::ELL_DEBUG) | ILogger::ELL_INFO | ILogger::ELL_WARNING | ILogger::ELL_PERFORMANCE | ILogger::ELL_ERROR);

if (insufficientArguments)
{
m_logger->log("Insufficient arguments.", ILogger::ELL_ERROR);
return false;
}

m_arguments = std::vector<std::string>(argv.begin()+1, argv.end()); // turn argv into vector for convenience

if (std::find(m_arguments.begin(), m_arguments.end(), "--dump-build-info") != m_arguments.end())
{
json j;

auto& modules = j["modules"];

auto serialize = [&](const gtml::GitInfo& info, std::string_view target) -> void
{
auto& s = modules[target.data()];

s["isPopulated"] = info.isPopulated;
if (info.hasUncommittedChanges.has_value())
if (info.hasUncommittedChanges.has_value())
s["hasUncommittedChanges"] = info.hasUncommittedChanges.value();
else
s["hasUncommittedChanges"] = "UNKNOWN, BUILT WITHOUT DIRTY-CHANGES CAPTURE";
Expand All @@ -60,60 +79,35 @@ class ShaderCompiler final : public system::IApplicationFramework
s["latestTagName"] = info.latestTagName;
};

serialize(gtml::nabla_git_info, "nabla");
serialize(gtml::dxc_git_info, "dxc");

const auto pretty = j.dump(4);
std::cout << pretty << std::endl;
serialize(gtml::nabla_git_info, "nabla");
serialize(gtml::dxc_git_info, "dxc");

std::filesystem::path oPath = "build-info.json";
const auto pretty = j.dump(4);
m_logger->log(pretty, ILogger::ELL_INFO);

// TOOD: use argparse for it
if (argc > 3 && argv[2] == "--file")
oPath = argv[3];
std::filesystem::path oPath = "build-info.json";

std::ofstream outFile(oPath);
if (outFile.is_open())
{
outFile << pretty;
outFile.close();
printf("Saved \"%s\"\n", oPath.string().c_str());
}
else
{
printf("Failed to open \"%s\" for writing\n", oPath.string().c_str());
exit(-1);
}
// TOOD: use argparse for it
if (argc > 3 && argv[2] == "--file")
oPath = argv[3];

// in this mode terminate with 0 if all good
exit(0);
std::ofstream outFile(oPath);
if (outFile.is_open())
{
outFile << pretty;
outFile.close();
m_logger->log("Saved \"%s\"", ILogger::ELL_INFO, oPath.string().c_str());
}
else
{
m_logger->log("Failed to open \"%s\" for writing", ILogger::ELL_ERROR, oPath.string().c_str());
exit(-1);
}
}

if (not isAPILoaded())
{
std::cerr << "Could not load Nabla API, terminating!";
return false;
}

if (system)
m_system = std::move(system);
else
m_system = system::IApplicationFramework::createSystem();

if (!m_system)
return false;

m_logger = make_smart_refctd_ptr<CStdoutLogger>(core::bitflag(ILogger::ELL_DEBUG) | ILogger::ELL_INFO | ILogger::ELL_WARNING | ILogger::ELL_PERFORMANCE | ILogger::ELL_ERROR);

if (insufficientArguments)
{
m_logger->log("Insufficient arguments.", ILogger::ELL_ERROR);
return false;
// in this mode terminate with 0 if all good
exit(0);
}

m_arguments = std::vector<std::string>(argv.begin() + 1, argv.end()-1); // turn argv into vector for convenience

std::string file_to_compile = argv.back();

if (!m_system->exists(file_to_compile, IFileBase::ECF_READ)) {
Expand Down