From 7f551d7f6a7afc7496cece31126464813fb1aa28 Mon Sep 17 00:00:00 2001 From: Idan Horowitz Date: Fri, 1 Oct 2021 18:01:20 +0300 Subject: [PATCH] LibWeb: Use the LibWeb source directory as the IDL #import base path This allows us to include IDL files from other base LibWeb directories wihout using relative `../foo.idl` references. --- .../CodeGenerators/LibWeb/WrapperGenerator.cpp | 16 +++++++++++----- Userland/Libraries/LibWeb/CMakeLists.txt | 2 +- Userland/Libraries/LibWeb/DOM/CustomEvent.idl | 2 +- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/Meta/Lagom/Tools/CodeGenerators/LibWeb/WrapperGenerator.cpp b/Meta/Lagom/Tools/CodeGenerators/LibWeb/WrapperGenerator.cpp index ce258404ebb..35f5172e4c3 100644 --- a/Meta/Lagom/Tools/CodeGenerators/LibWeb/WrapperGenerator.cpp +++ b/Meta/Lagom/Tools/CodeGenerators/LibWeb/WrapperGenerator.cpp @@ -185,7 +185,7 @@ struct Interface { bool is_legacy_platform_object() const { return !extended_attributes.contains("Global") && (supports_indexed_properties() || supports_named_properties()); } }; -static NonnullOwnPtr parse_interface(StringView filename, StringView input) +static NonnullOwnPtr parse_interface(StringView filename, StringView input, StringView import_base_path) { auto interface = make(); @@ -233,7 +233,7 @@ static NonnullOwnPtr parse_interface(StringView filename, StringView }; auto resolve_import = [&](auto path) { - auto include_path = LexicalPath::join(LexicalPath::dirname(filename), path).string(); + auto include_path = LexicalPath::join(import_base_path, path).string(); if (!Core::File::exists(include_path)) report_parsing_error(String::formatted("{}: No such file or directory", include_path), filename, input, lexer.tell()); @@ -242,7 +242,7 @@ static NonnullOwnPtr parse_interface(StringView filename, StringView report_parsing_error(String::formatted("Failed to open {}: {}", include_path, file_or_error.error()), filename, input, lexer.tell()); auto data = file_or_error.value()->read_all(); - return IDL::parse_interface(include_path, data); + return IDL::parse_interface(include_path, data, import_base_path); }; NonnullOwnPtrVector imports; @@ -690,7 +690,8 @@ static void generate_iterator_implementation(IDL::Interface const&); int main(int argc, char** argv) { Core::ArgsParser args_parser; - char const* path = nullptr; + StringView path = nullptr; + StringView import_base_path = nullptr; bool header_mode = false; bool implementation_mode = false; bool constructor_header_mode = false; @@ -712,6 +713,7 @@ int main(int argc, char** argv) args_parser.add_option(iterator_prototype_header_mode, "Generate the iterator prototype .h file", "iterator-prototype-header", 0); args_parser.add_option(iterator_prototype_implementation_mode, "Generate the iterator prototype .cpp file", "iterator-prototype-implementation", 0); args_parser.add_positional_argument(path, "IDL file", "idl-file"); + args_parser.add_positional_argument(import_base_path, "Import base path", "import-base-path", Core::ArgsParser::Required::No); args_parser.parse(argc, argv); auto file_or_error = Core::File::open(path, Core::OpenMode::ReadOnly); @@ -724,7 +726,11 @@ int main(int argc, char** argv) auto& namespace_ = lexical_path.parts_view().at(lexical_path.parts_view().size() - 2); auto data = file_or_error.value()->read_all(); - auto interface = IDL::parse_interface(path, data); + + if (import_base_path.is_null()) + import_base_path = lexical_path.dirname(); + + auto interface = IDL::parse_interface(path, data, import_base_path); if (namespace_.is_one_of("Crypto", "CSS", "DOM", "HTML", "UIEvents", "Geometry", "HighResolutionTime", "NavigationTiming", "RequestIdleCallback", "SVG", "XHR", "URL")) { StringBuilder builder; diff --git a/Userland/Libraries/LibWeb/CMakeLists.txt b/Userland/Libraries/LibWeb/CMakeLists.txt index 20dbec40f0d..f5c04f78c4f 100644 --- a/Userland/Libraries/LibWeb/CMakeLists.txt +++ b/Userland/Libraries/LibWeb/CMakeLists.txt @@ -323,7 +323,7 @@ function(libweb_js_wrapper class) list(GET BINDINGS_TYPES ${iter} bindings_type) add_custom_command( OUTPUT "${bindings_src}" - COMMAND "$" "--${bindings_type}" "${CMAKE_CURRENT_SOURCE_DIR}/${class}.idl" > "${bindings_src}.tmp" + COMMAND "$" "--${bindings_type}" "${CMAKE_CURRENT_SOURCE_DIR}/${class}.idl" "${CMAKE_CURRENT_SOURCE_DIR}/" > "${bindings_src}.tmp" COMMAND "${CMAKE_COMMAND}" -E copy_if_different "${bindings_src}.tmp" "${bindings_src}" COMMAND "${CMAKE_COMMAND}" -E remove "${bindings_src}.tmp" VERBATIM diff --git a/Userland/Libraries/LibWeb/DOM/CustomEvent.idl b/Userland/Libraries/LibWeb/DOM/CustomEvent.idl index 019df6ceffa..65bfc43ca75 100644 --- a/Userland/Libraries/LibWeb/DOM/CustomEvent.idl +++ b/Userland/Libraries/LibWeb/DOM/CustomEvent.idl @@ -1,4 +1,4 @@ -#import +#import [Exposed=(Window,Worker), CustomVisit] interface CustomEvent : Event {