diff --git a/tools/nsc/main.cpp b/tools/nsc/main.cpp index e6edd6b740..c33896f68c 100644 --- a/tools/nsc/main.cpp +++ b/tools/nsc/main.cpp @@ -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(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(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"; @@ -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(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(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)) {