LibIDL: Support multiple import base paths for resolving imports

This allows us to specify multiple base paths to look for imported IDL
files in. This will allow us to import IDL files from sources and from
the Build directory (i.e. for generated IDL files).
This commit is contained in:
Luke Wilde 2024-11-14 16:13:44 +00:00 committed by Andreas Kling
commit 300f212044
Notes: github-actions[bot] 2024-11-14 18:51:33 +00:00
4 changed files with 49 additions and 21 deletions

View file

@ -21,7 +21,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
{
Core::ArgsParser args_parser;
StringView path;
StringView import_base_path;
Vector<StringView> import_base_paths;
StringView output_path = "-"sv;
StringView depfile_path;
StringView depfile_prefix;
@ -41,7 +41,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
args_parser.add_option(depfile_path, "Path to write dependency file to", "depfile", 'd', "depfile-path");
args_parser.add_option(depfile_prefix, "Prefix to prepend to relative paths in dependency file", "depfile-prefix", 'p', "depfile-prefix");
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.add_positional_argument(import_base_paths, "Import base path", "import-base-path", Core::ArgsParser::Required::No);
args_parser.parse(arguments);
auto idl_file = TRY(Core::File::open(path, Core::File::OpenMode::Read));
@ -51,10 +51,10 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
auto data = TRY(idl_file->read_until_eof());
if (import_base_path.is_null())
import_base_path = lexical_path.dirname();
if (import_base_paths.is_empty())
import_base_paths.append(lexical_path.dirname());
IDL::Parser parser(path, data, import_base_path);
IDL::Parser parser(path, data, move(import_base_paths));
auto& interface = parser.parse();
// If the interface name is the same as its namespace, qualify the name in the generated code.