mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 03:48:13 +00:00
StateMachineGenerator: Pass output file as an argument
This allows us to avoid shell redirection to create output files, and will help with the GN build.
This commit is contained in:
parent
f87a488b22
commit
f8e1544f41
2 changed files with 11 additions and 5 deletions
|
@ -69,7 +69,7 @@ function(generate_state_machine source header)
|
||||||
set(output ${CMAKE_CURRENT_BINARY_DIR}/${header})
|
set(output ${CMAKE_CURRENT_BINARY_DIR}/${header})
|
||||||
add_custom_command(
|
add_custom_command(
|
||||||
OUTPUT ${output}
|
OUTPUT ${output}
|
||||||
COMMAND $<TARGET_FILE:Lagom::StateMachineGenerator> ${source} > ${output}.tmp
|
COMMAND $<TARGET_FILE:Lagom::StateMachineGenerator> ${source} -o ${output}.tmp
|
||||||
COMMAND "${CMAKE_COMMAND}" -E copy_if_different ${output}.tmp ${output}
|
COMMAND "${CMAKE_COMMAND}" -E copy_if_different ${output}.tmp ${output}
|
||||||
COMMAND "${CMAKE_COMMAND}" -E remove ${output}.tmp
|
COMMAND "${CMAKE_COMMAND}" -E remove ${output}.tmp
|
||||||
VERBATIM
|
VERBATIM
|
||||||
|
|
|
@ -216,10 +216,15 @@ void output_header(StateMachine const&, SourceGenerator&);
|
||||||
|
|
||||||
ErrorOr<int> serenity_main(Main::Arguments arguments)
|
ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||||
{
|
{
|
||||||
Core::ArgsParser args_parser;
|
|
||||||
StringView path;
|
StringView path;
|
||||||
args_parser.add_positional_argument(path, "Path to parser description", "input", Core::ArgsParser::Required::Yes);
|
StringView output_file = "-"sv;
|
||||||
args_parser.parse(arguments);
|
|
||||||
|
Core::ArgsParser parser;
|
||||||
|
parser.add_positional_argument(path, "Path to parser description", "input", Core::ArgsParser::Required::Yes);
|
||||||
|
parser.add_option(output_file, "Place to write file", "output", 'o', "output-file");
|
||||||
|
parser.parse(arguments);
|
||||||
|
|
||||||
|
auto output = TRY(Core::File::open_file_or_standard_stream(output_file, Core::File::OpenMode::Write));
|
||||||
|
|
||||||
auto file = TRY(Core::File::open(path, Core::File::OpenMode::Read));
|
auto file = TRY(Core::File::open(path, Core::File::OpenMode::Read));
|
||||||
auto content = TRY(file->read_until_eof());
|
auto content = TRY(file->read_until_eof());
|
||||||
|
@ -228,7 +233,8 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||||
StringBuilder builder;
|
StringBuilder builder;
|
||||||
SourceGenerator generator { builder };
|
SourceGenerator generator { builder };
|
||||||
output_header(*state_machine, generator);
|
output_header(*state_machine, generator);
|
||||||
outln("{}", generator.as_string_view());
|
|
||||||
|
TRY(output->write_until_depleted(generator.as_string_view().bytes()));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue