mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-21 12:05:15 +00:00
IPCCompiler: Add option to pass output file path
Instead of requiring the caller to redirect stdout, let's be nice citizens and add an option for the output file.
This commit is contained in:
parent
5338eba39a
commit
aa329cb2f8
Notes:
sideshowbarker
2024-07-17 02:37:08 +09:00
Author: https://github.com/ADKaster Commit: https://github.com/SerenityOS/serenity/commit/aa329cb2f8 Pull-request: https://github.com/SerenityOS/serenity/pull/19799 Reviewed-by: https://github.com/nico ✅ Reviewed-by: https://github.com/trflynn89 ✅
2 changed files with 13 additions and 7 deletions
|
@ -24,7 +24,7 @@ function(compile_ipc source output)
|
|||
endif()
|
||||
add_custom_command(
|
||||
OUTPUT ${output}
|
||||
COMMAND $<TARGET_FILE:Lagom::IPCCompiler> ${source} > ${output}.tmp
|
||||
COMMAND $<TARGET_FILE:Lagom::IPCCompiler> ${source} -o ${output}.tmp
|
||||
COMMAND "${CMAKE_COMMAND}" -E copy_if_different ${output}.tmp ${output}
|
||||
COMMAND "${CMAKE_COMMAND}" -E remove ${output}.tmp
|
||||
VERBATIM
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
#include <AK/HashMap.h>
|
||||
#include <AK/SourceGenerator.h>
|
||||
#include <AK/StringBuilder.h>
|
||||
#include <LibCore/ArgsParser.h>
|
||||
#include <LibCore/File.h>
|
||||
#include <LibMain/Main.h>
|
||||
#include <ctype.h>
|
||||
|
@ -795,12 +796,17 @@ void build(StringBuilder& builder, Vector<Endpoint> const& endpoints)
|
|||
|
||||
ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||
{
|
||||
if (arguments.argc != 2) {
|
||||
outln("usage: {} <IPC endpoint definition file>", arguments.strings[0]);
|
||||
return 1;
|
||||
}
|
||||
StringView ipc_file;
|
||||
StringView output_file = "-"sv;
|
||||
|
||||
auto file = TRY(Core::File::open(arguments.strings[1], Core::File::OpenMode::Read));
|
||||
Core::ArgsParser parser;
|
||||
parser.add_positional_argument(ipc_file, "IPC endpoint definition file", "input");
|
||||
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(ipc_file, Core::File::OpenMode::Read));
|
||||
|
||||
auto file_contents = TRY(file->read_until_eof());
|
||||
|
||||
|
@ -809,7 +815,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
StringBuilder builder;
|
||||
build(builder, endpoints);
|
||||
|
||||
outln("{}", builder.string_view());
|
||||
TRY(output->write_until_depleted(builder.string_view().bytes()));
|
||||
|
||||
if constexpr (GENERATE_DEBUG) {
|
||||
for (auto& endpoint : endpoints) {
|
||||
|
|
Loading…
Add table
Reference in a new issue