mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-09-11 13:36:13 +03: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
Notes:
sideshowbarker
2024-07-17 00:27:16 +09:00
Author: https://github.com/ADKaster Commit: https://github.com/SerenityOS/serenity/commit/f8e1544f41 Pull-request: https://github.com/SerenityOS/serenity/pull/20209
@ -69,7 +69,7 @@ function(generate_state_machine source header)
|
||||
set(output ${CMAKE_CURRENT_BINARY_DIR}/${header})
|
||||
add_custom_command(
|
||||
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 remove ${output}.tmp
|
||||
VERBATIM
|
||||
|
@ -216,10 +216,15 @@ void output_header(StateMachine const&, SourceGenerator&);
|
||||
|
||||
ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||
{
|
||||
Core::ArgsParser args_parser;
|
||||
StringView path;
|
||||
args_parser.add_positional_argument(path, "Path to parser description", "input", Core::ArgsParser::Required::Yes);
|
||||
args_parser.parse(arguments);
|
||||
StringView output_file = "-"sv;
|
||||
|
||||
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 content = TRY(file->read_until_eof());
|
||||
@ -228,7 +233,8 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||
StringBuilder builder;
|
||||
SourceGenerator generator { builder };
|
||||
output_header(*state_machine, generator);
|
||||
outln("{}", generator.as_string_view());
|
||||
|
||||
TRY(output->write_until_depleted(generator.as_string_view().bytes()));
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user