mirror of
https://github.com/RGBCube/serenity
synced 2025-08-01 11:47:35 +00:00
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.
This commit is contained in:
parent
9ba386a7bb
commit
8669b25cea
8 changed files with 184 additions and 6 deletions
|
@ -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
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
add_subdirectory(IPCCompiler)
|
||||
add_subdirectory(LibTimeZone)
|
||||
add_subdirectory(LibUnicode)
|
||||
add_subdirectory(LibWeb)
|
||||
add_subdirectory(StateMachineGenerator)
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
lagom_tool(GenerateTimeZoneData SOURCES GenerateTimeZoneData.cpp LIBS LagomMain)
|
|
@ -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;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue