diff --git a/src/RawTemplater/RawTemplaterArguments.h b/src/RawTemplater/RawTemplaterArguments.h index a0b2696d..7ff67338 100644 --- a/src/RawTemplater/RawTemplaterArguments.h +++ b/src/RawTemplater/RawTemplaterArguments.h @@ -20,6 +20,8 @@ public: std::vector m_input_files; std::string m_output_directory; + // Generate a build log that is always written for the compiler to determine + // the last output time. std::string m_build_log_file; std::vector> m_defines; diff --git a/src/ZoneCode.lua b/src/ZoneCode.lua index 61f6694f..9d648279 100644 --- a/src/ZoneCode.lua +++ b/src/ZoneCode.lua @@ -347,6 +347,7 @@ function ZoneCode:project() .. ' -h "' .. path.join(path.getabsolute(ProjectFolder()), 'ZoneCode/Game/%{file.basename}/%{file.basename}_ZoneCode.h') .. '"' .. ' -c "' .. path.join(path.getabsolute(ProjectFolder()), 'ZoneCode/Game/%{file.basename}/%{file.basename}_Commands.txt') .. '"' .. ' -o "%{wks.location}/src/ZoneCode/Game/%{file.basename}"' + .. ' --build-log "%{wks.location}/src/ZoneCode/Game/%{file.basename}.log"' .. ' -g ZoneLoad' .. ' -g ZoneMark' .. ' -g ZoneWrite' @@ -358,6 +359,9 @@ function ZoneCode:project() path.join(ProjectFolder(), "Common/Game/%{file.basename}/%{file.basename}_Assets.h"), TargetDirectoryBuildTools .. "/" .. ExecutableByOs('ZoneCodeGenerator') } + buildoutputs { + "%{wks.location}/src/ZoneCode/Game/%{file.basename}.log" + } filter {} filter "files:**/IW3.gen" diff --git a/src/ZoneCodeGeneratorLib/Generating/CodeGenerator.cpp b/src/ZoneCodeGeneratorLib/Generating/CodeGenerator.cpp index c41877bc..71c403ea 100644 --- a/src/ZoneCodeGeneratorLib/Generating/CodeGenerator.cpp +++ b/src/ZoneCodeGeneratorLib/Generating/CodeGenerator.cpp @@ -11,6 +11,7 @@ #include #include +#include namespace fs = std::filesystem; @@ -176,7 +177,22 @@ bool CodeGenerator::GenerateCode(const IDataRepository* repository) } } const auto end = std::chrono::steady_clock::now(); - con::debug("Generating code took {}ms", std::chrono::duration_cast(end - start).count()); + const auto timeInMs = std::chrono::duration_cast(end - start).count(); + con::debug("Generating code took {}ms", timeInMs); + + if (!m_args->m_build_log_file.empty()) + { + std::ofstream buildLogFile(m_args->m_build_log_file); + if (buildLogFile.is_open()) + { + buildLogFile << "Generating code took " << timeInMs << "ms\n"; + buildLogFile.close(); + } + else + { + con::error("Failed to open build log file"); + } + } return true; } diff --git a/src/ZoneCodeGeneratorLib/ZoneCodeGenerator.cpp b/src/ZoneCodeGeneratorLib/ZoneCodeGenerator.cpp index 8039663e..c0a5e5b8 100644 --- a/src/ZoneCodeGeneratorLib/ZoneCodeGenerator.cpp +++ b/src/ZoneCodeGeneratorLib/ZoneCodeGenerator.cpp @@ -49,7 +49,7 @@ public: } private: - bool ReadHeaderData() + [[nodiscard]] bool ReadHeaderData() const { for (const auto& headerFile : m_args.m_header_paths) { @@ -62,7 +62,7 @@ private: return true; } - bool ReadCommandsData() + [[nodiscard]] bool ReadCommandsData() const { for (const auto& commandsFile : m_args.m_command_paths) { diff --git a/src/ZoneCodeGeneratorLib/ZoneCodeGeneratorArguments.cpp b/src/ZoneCodeGeneratorLib/ZoneCodeGeneratorArguments.cpp index fb5c354f..ec2d3d45 100644 --- a/src/ZoneCodeGeneratorLib/ZoneCodeGeneratorArguments.cpp +++ b/src/ZoneCodeGeneratorLib/ZoneCodeGeneratorArguments.cpp @@ -85,6 +85,13 @@ const CommandLineOption* const OPTION_GENERATE = .WithParameter("preset") .Reusable() .Build(); + +const CommandLineOption* const OPTION_BUILD_LOG = + CommandLineOption::Builder::Create() + .WithLongName("build-log") + .WithDescription("Specify a file to write a build log to.") + .WithParameter("logFilePath") + .Build(); // clang-format on const CommandLineOption* const COMMAND_LINE_OPTIONS[]{ @@ -97,6 +104,7 @@ const CommandLineOption* const COMMAND_LINE_OPTIONS[]{ OPTION_OUTPUT_FOLDER, OPTION_PRINT, OPTION_GENERATE, + OPTION_BUILD_LOG, }; namespace @@ -170,6 +178,10 @@ bool ZoneCodeGeneratorArguments::ParseArgs(const int argc, const char** argv, bo else m_output_directory = "."; + // --build-log + if (m_argument_parser.IsOptionSpecified(OPTION_BUILD_LOG)) + m_build_log_file = m_argument_parser.GetValueForOption(OPTION_BUILD_LOG); + // -h; --header if (m_argument_parser.IsOptionSpecified(OPTION_HEADER)) { diff --git a/src/ZoneCodeGeneratorLib/ZoneCodeGeneratorArguments.h b/src/ZoneCodeGeneratorLib/ZoneCodeGeneratorArguments.h index f4b21dfb..4df497ae 100644 --- a/src/ZoneCodeGeneratorLib/ZoneCodeGeneratorArguments.h +++ b/src/ZoneCodeGeneratorLib/ZoneCodeGeneratorArguments.h @@ -18,6 +18,10 @@ public: std::vector m_command_paths; std::string m_output_directory; + // Generate a build log that is always written for the compiler to determine + // the last output time. + std::string m_build_log_file; + std::vector m_template_names; private: