diff options
author | Timothy Flynn <trflynn89@pm.me> | 2021-12-22 16:33:38 -0500 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2022-01-08 12:45:34 +0100 |
commit | 8669b25cea5be5f88caf8a1d6b1c89d3ff29f041 (patch) | |
tree | 624fb537d06d721f022de70912df6c2444db5671 /Meta/Lagom | |
parent | 9ba386a7bbe978702174df45e19e0a4fd14e77b9 (diff) | |
download | serenity-8669b25cea5be5f88caf8a1d6b1c89d3ff29f041.zip |
LibTimeZone+Meta: Add plumbing for an IANA Time Zone Database generator
The IANA Time Zone Database contains data needed, at least, for various
JavaScript objects. This adds plumbing for a parser and code generator
for this data. The generated data will be made available by LibTimeZone,
much like how UCD and CLDR data is available through LibUnicode.
Diffstat (limited to 'Meta/Lagom')
4 files changed, 86 insertions, 6 deletions
diff --git a/Meta/Lagom/CMakeLists.txt b/Meta/Lagom/CMakeLists.txt index 66b39722e4..b8ef9cc400 100644 --- a/Meta/Lagom/CMakeLists.txt +++ b/Meta/Lagom/CMakeLists.txt @@ -216,6 +216,11 @@ function(lagom_test source) ) endfunction() +if (NOT TARGET all_generated) + # Meta target to run all code-gen steps in the build. + add_custom_target(all_generated) +endif() + # AK/Core # Note: AK is included in LagomCore for the host build instead of LibC per the target build file(GLOB AK_SOURCES CONFIGURE_DEPENDS "../../AK/*.cpp") @@ -240,6 +245,19 @@ if (APPLE) target_link_options(LagomMain PRIVATE -undefined dynamic_lookup) endif() +# TimeZone +# This is needed even if Lagom is not enabled because it is depended upon by code generators. +if (NOT ENABLE_OSS_FUZZ AND NOT ENABLE_FUZZER_SANITIZER) + include(time_zone_data) +else() + set(ENABLE_TIME_ZONE_DATABASE_DOWNLOAD OFF) +endif() +file(GLOB LIBTIMEZONE_SOURCES CONFIGURE_DEPENDS "../../Userland/Libraries/LibTimeZone/*.cpp") +lagom_lib(TimeZone timezone + SOURCES ${LIBTIMEZONE_SOURCES} ${TIME_ZONE_DATA_SOURCES} +) +target_compile_definitions(LagomTimeZone PRIVATE ENABLE_TIME_ZONE_DATA=$<BOOL:${ENABLE_TIME_ZONE_DATABASE_DOWNLOAD}>) + # Manually install AK headers install( DIRECTORY "${SERENITY_PROJECT_ROOT}/AK" @@ -255,12 +273,6 @@ if (NOT ENABLE_OSS_FUZZ AND NOT ENABLE_FUZZER_SANITIZER) endif() if (BUILD_LAGOM) - - if (NOT TARGET all_generated) - # Meta target to run all code-gen steps in the build. - add_custom_target(all_generated) - endif() - # Lagom Libraries # Archive diff --git a/Meta/Lagom/Tools/CodeGenerators/CMakeLists.txt b/Meta/Lagom/Tools/CodeGenerators/CMakeLists.txt index f5b0b36493..66d33a0599 100644 --- a/Meta/Lagom/Tools/CodeGenerators/CMakeLists.txt +++ b/Meta/Lagom/Tools/CodeGenerators/CMakeLists.txt @@ -1,4 +1,5 @@ add_subdirectory(IPCCompiler) +add_subdirectory(LibTimeZone) add_subdirectory(LibUnicode) add_subdirectory(LibWeb) add_subdirectory(StateMachineGenerator) diff --git a/Meta/Lagom/Tools/CodeGenerators/LibTimeZone/CMakeLists.txt b/Meta/Lagom/Tools/CodeGenerators/LibTimeZone/CMakeLists.txt new file mode 100644 index 0000000000..585526d535 --- /dev/null +++ b/Meta/Lagom/Tools/CodeGenerators/LibTimeZone/CMakeLists.txt @@ -0,0 +1 @@ +lagom_tool(GenerateTimeZoneData SOURCES GenerateTimeZoneData.cpp LIBS LagomMain) diff --git a/Meta/Lagom/Tools/CodeGenerators/LibTimeZone/GenerateTimeZoneData.cpp b/Meta/Lagom/Tools/CodeGenerators/LibTimeZone/GenerateTimeZoneData.cpp new file mode 100644 index 0000000000..27e304af35 --- /dev/null +++ b/Meta/Lagom/Tools/CodeGenerators/LibTimeZone/GenerateTimeZoneData.cpp @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2022, Tim Flynn <trflynn89@pm.me> + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include <AK/SourceGenerator.h> +#include <AK/String.h> +#include <AK/StringBuilder.h> +#include <AK/Vector.h> +#include <LibCore/ArgsParser.h> +#include <LibCore/File.h> + +static void generate_time_zone_data_header(Core::File& file) +{ + StringBuilder builder; + SourceGenerator generator { builder }; + + generator.append(R"~~~( +#pragma once +)~~~"); + + VERIFY(file.write(generator.as_string_view())); +} + +static void generate_time_zone_data_implementation(Core::File& file) +{ + StringBuilder builder; + SourceGenerator generator { builder }; + + generator.append(R"~~~( +#include <LibTimeZone/TimeZoneData.h> +)~~~"); + + VERIFY(file.write(generator.as_string_view())); +} + +ErrorOr<int> serenity_main(Main::Arguments arguments) +{ + StringView generated_header_path; + StringView generated_implementation_path; + Vector<StringView> time_zone_paths; + + Core::ArgsParser args_parser; + args_parser.add_option(generated_header_path, "Path to the time zone data header file to generate", "generated-header-path", 'h', "generated-header-path"); + args_parser.add_option(generated_implementation_path, "Path to the time zone data implementation file to generate", "generated-implementation-path", 'c', "generated-implementation-path"); + args_parser.add_positional_argument(time_zone_paths, "Paths to the time zone database files", "time-zone-paths"); + args_parser.parse(arguments); + + auto open_file = [&](StringView path) -> ErrorOr<NonnullRefPtr<Core::File>> { + if (path.is_empty()) { + args_parser.print_usage(stderr, arguments.argv[0]); + return Error::from_string_literal("Must provide all command line options"sv); + } + + return Core::File::open(path, Core::OpenMode::ReadWrite); + }; + + auto generated_header_file = TRY(open_file(generated_header_path)); + auto generated_implementation_file = TRY(open_file(generated_implementation_path)); + + generate_time_zone_data_header(generated_header_file); + generate_time_zone_data_implementation(generated_implementation_file); + + return 0; +} |