mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-04-19 15:52:53 +00:00
Add build log to templater
This commit is contained in:
parent
6a45031c96
commit
379aabebd6
@ -13,9 +13,12 @@ class RawTemplater::Impl
|
|||||||
{
|
{
|
||||||
RawTemplaterArguments m_args;
|
RawTemplaterArguments m_args;
|
||||||
|
|
||||||
_NODISCARD bool GenerateCode(const std::string& filename) const
|
bool m_write_build_log;
|
||||||
|
std::ofstream m_build_log_file;
|
||||||
|
|
||||||
|
_NODISCARD bool GenerateCode(const std::string& filename)
|
||||||
{
|
{
|
||||||
std::ifstream file(filename);
|
std::ifstream file(filename, std::ios::in | std::ios::binary);
|
||||||
if (!file.is_open())
|
if (!file.is_open())
|
||||||
{
|
{
|
||||||
std::cerr << "Failed to open file \"" << filename << "\"\n";
|
std::cerr << "Failed to open file \"" << filename << "\"\n";
|
||||||
@ -23,6 +26,8 @@ class RawTemplater::Impl
|
|||||||
}
|
}
|
||||||
|
|
||||||
templating::Templater templater(file, filename);
|
templating::Templater templater(file, filename);
|
||||||
|
if (m_write_build_log)
|
||||||
|
templater.SetBuildLogFile(&m_build_log_file);
|
||||||
if (!m_args.m_output_directory.empty())
|
if (!m_args.m_output_directory.empty())
|
||||||
return templater.TemplateToDirectory(m_args.m_output_directory);
|
return templater.TemplateToDirectory(m_args.m_output_directory);
|
||||||
|
|
||||||
@ -34,14 +39,27 @@ class RawTemplater::Impl
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
Impl()
|
Impl()
|
||||||
= default;
|
: m_write_build_log(false)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
int Run(const int argc, const char** argv)
|
int Run(const int argc, const char** argv)
|
||||||
{
|
{
|
||||||
if (!m_args.Parse(argc, argv))
|
if (!m_args.Parse(argc, argv))
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
for(const auto& inputFile : m_args.m_input_files)
|
if (!m_args.m_build_log_file.empty())
|
||||||
|
{
|
||||||
|
m_build_log_file = std::ofstream(m_args.m_build_log_file, std::ios::out | std::ios::binary);
|
||||||
|
if (!m_build_log_file.is_open())
|
||||||
|
{
|
||||||
|
std::cerr << "Failed to open build log file \"" << m_args.m_build_log_file << "\"\n";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
m_write_build_log = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const auto& inputFile : m_args.m_input_files)
|
||||||
{
|
{
|
||||||
if (!GenerateCode(inputFile))
|
if (!GenerateCode(inputFile))
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -22,6 +22,12 @@ const CommandLineOption* const OPTION_OUTPUT_FOLDER = CommandLineOption::Builder
|
|||||||
.WithParameter("outputPath")
|
.WithParameter("outputPath")
|
||||||
.Build();
|
.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();
|
||||||
|
|
||||||
const CommandLineOption* const OPTION_DEFINE = CommandLineOption::Builder::Create()
|
const CommandLineOption* const OPTION_DEFINE = CommandLineOption::Builder::Create()
|
||||||
.WithShortName("d")
|
.WithShortName("d")
|
||||||
.WithLongName("define")
|
.WithLongName("define")
|
||||||
@ -35,6 +41,7 @@ const CommandLineOption* const COMMAND_LINE_OPTIONS[]
|
|||||||
OPTION_HELP,
|
OPTION_HELP,
|
||||||
OPTION_VERBOSE,
|
OPTION_VERBOSE,
|
||||||
OPTION_OUTPUT_FOLDER,
|
OPTION_OUTPUT_FOLDER,
|
||||||
|
OPTION_BUILD_LOG,
|
||||||
OPTION_DEFINE
|
OPTION_DEFINE
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -87,6 +94,10 @@ bool RawTemplaterArguments::Parse(const int argc, const char** argv)
|
|||||||
else
|
else
|
||||||
m_output_directory = ".";
|
m_output_directory = ".";
|
||||||
|
|
||||||
|
// --build-log
|
||||||
|
if (m_argument_parser.IsOptionSpecified(OPTION_BUILD_LOG))
|
||||||
|
m_build_log_file = m_argument_parser.GetValueForOption(OPTION_BUILD_LOG);
|
||||||
|
|
||||||
// -d; --define
|
// -d; --define
|
||||||
if (m_argument_parser.IsOptionSpecified(OPTION_DEFINE))
|
if (m_argument_parser.IsOptionSpecified(OPTION_DEFINE))
|
||||||
{
|
{
|
||||||
|
@ -21,6 +21,8 @@ public:
|
|||||||
std::vector<std::string> m_input_files;
|
std::vector<std::string> m_input_files;
|
||||||
std::string m_output_directory;
|
std::string m_output_directory;
|
||||||
|
|
||||||
|
std::string m_build_log_file;
|
||||||
|
|
||||||
std::vector<std::pair<std::string, std::string>> m_defines;
|
std::vector<std::pair<std::string, std::string>> m_defines;
|
||||||
|
|
||||||
RawTemplaterArguments();
|
RawTemplaterArguments();
|
||||||
|
@ -172,7 +172,7 @@ namespace templating
|
|||||||
m_default_output_file = (m_output_directory / filenamePath.replace_extension()).string();
|
m_default_output_file = (m_output_directory / filenamePath.replace_extension()).string();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RunNextPass()
|
bool RunNextPass(std::ostream* buildLogFile)
|
||||||
{
|
{
|
||||||
m_stream.clear();
|
m_stream.clear();
|
||||||
m_stream.seekg(0, std::ios::beg);
|
m_stream.seekg(0, std::ios::beg);
|
||||||
@ -209,7 +209,7 @@ namespace templating
|
|||||||
|
|
||||||
if (!m_write_output_to_file)
|
if (!m_write_output_to_file)
|
||||||
{
|
{
|
||||||
m_output_stream = std::ofstream(m_output_file);
|
m_output_stream = std::ofstream(m_output_file, std::ios::out | std::ios::binary);
|
||||||
if (!m_output_stream.is_open())
|
if (!m_output_stream.is_open())
|
||||||
{
|
{
|
||||||
std::cerr << "Failed to open output file \"" << m_output_file << "\"\n";
|
std::cerr << "Failed to open output file \"" << m_output_file << "\"\n";
|
||||||
@ -223,6 +223,9 @@ namespace templating
|
|||||||
|
|
||||||
std::cout << "Templated file \"" << m_output_file << "\"\n";
|
std::cout << "Templated file \"" << m_output_file << "\"\n";
|
||||||
|
|
||||||
|
if(buildLogFile)
|
||||||
|
*buildLogFile << "Templated file \"" << m_output_file << "\"\n";
|
||||||
|
|
||||||
m_first_line = true;
|
m_first_line = true;
|
||||||
m_write_output_to_file = false;
|
m_write_output_to_file = false;
|
||||||
m_output_cache.clear();
|
m_output_cache.clear();
|
||||||
@ -289,7 +292,7 @@ namespace templating
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
m_output_file = (m_output_directory / fileName).string();
|
m_output_file = (m_output_directory / fileName).string();
|
||||||
m_output_stream = std::ofstream(m_output_file);
|
m_output_stream = std::ofstream(m_output_file, std::ios::out | std::ios::binary);
|
||||||
if (!m_output_stream.is_open())
|
if (!m_output_stream.is_open())
|
||||||
{
|
{
|
||||||
std::cerr << "Failed to open output file \"" << m_output_file << "\"\n";
|
std::cerr << "Failed to open output file \"" << m_output_file << "\"\n";
|
||||||
@ -326,23 +329,29 @@ namespace templating
|
|||||||
|
|
||||||
Templater::Templater(std::istream& stream, std::string fileName)
|
Templater::Templater(std::istream& stream, std::string fileName)
|
||||||
: m_stream(stream),
|
: m_stream(stream),
|
||||||
|
m_build_log(nullptr),
|
||||||
m_file_name(std::move(fileName))
|
m_file_name(std::move(fileName))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Templater::SetBuildLogFile(std::ostream* buildLogFile)
|
||||||
|
{
|
||||||
|
m_build_log = buildLogFile;
|
||||||
|
}
|
||||||
|
|
||||||
bool Templater::TemplateToDirectory(const std::string& outputDirectory) const
|
bool Templater::TemplateToDirectory(const std::string& outputDirectory) const
|
||||||
{
|
{
|
||||||
TemplaterControlImpl control(m_stream, m_file_name, outputDirectory);
|
TemplaterControlImpl control(m_stream, m_file_name, outputDirectory);
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (!control.RunNextPass())
|
if (!control.RunNextPass(m_build_log))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
control.AdvanceActiveVariations();
|
control.AdvanceActiveVariations();
|
||||||
while (control.HasActiveVariations())
|
while (control.HasActiveVariations())
|
||||||
{
|
{
|
||||||
if (!control.RunNextPass())
|
if (!control.RunNextPass(m_build_log))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
control.AdvanceActiveVariations();
|
control.AdvanceActiveVariations();
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
#include "Utils/ClassUtils.h"
|
||||||
#include "Parsing/IParserLineStream.h"
|
#include "Parsing/IParserLineStream.h"
|
||||||
|
|
||||||
namespace templating
|
namespace templating
|
||||||
@ -10,10 +11,12 @@ namespace templating
|
|||||||
public:
|
public:
|
||||||
Templater(std::istream& stream, std::string fileName);
|
Templater(std::istream& stream, std::string fileName);
|
||||||
|
|
||||||
bool TemplateToDirectory(const std::string& outputDirectory) const;
|
void SetBuildLogFile(std::ostream* buildLogFile);
|
||||||
|
_NODISCARD bool TemplateToDirectory(const std::string& outputDirectory) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::istream& m_stream;
|
std::istream& m_stream;
|
||||||
|
std::ostream* m_build_log;
|
||||||
std::string m_file_name;
|
std::string m_file_name;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -39,6 +39,8 @@ function Raw:project()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RawTemplater:use()
|
||||||
|
|
||||||
filter "files:not **/*.template"
|
filter "files:not **/*.template"
|
||||||
buildmessage 'Copying rawfile %{file.relpath}'
|
buildmessage 'Copying rawfile %{file.relpath}'
|
||||||
buildcommands {
|
buildcommands {
|
||||||
@ -59,10 +61,11 @@ function Raw:project()
|
|||||||
buildcommands {
|
buildcommands {
|
||||||
'"' .. TargetDirectoryBin .. '/' .. ExecutableByOs('RawTemplater') .. '"'
|
'"' .. TargetDirectoryBin .. '/' .. ExecutableByOs('RawTemplater') .. '"'
|
||||||
.. " -o %{cfg.targetdir}/build/raw/%{file.reldirectory}"
|
.. " -o %{cfg.targetdir}/build/raw/%{file.reldirectory}"
|
||||||
|
.. " --build-log \"%{prj.location}/build/%{file.relpath}.log\""
|
||||||
.. " %{file.relpath}"
|
.. " %{file.relpath}"
|
||||||
}
|
}
|
||||||
buildoutputs {
|
buildoutputs {
|
||||||
"%{cfg.targetdir}/build/raw/%{file.relpath}"
|
"%{prj.location}/build/%{file.relpath}.log"
|
||||||
}
|
}
|
||||||
filter {}
|
filter {}
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user