mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 07:30:19 +00:00
Meta: Allow overriding root for local includes
Previously, we always assumed that local includes are relative to the parent directory of a file. This effectively banned style-wise multi-directory subprojects which are not libraries, since there was no way to cleanly reference local file from a different directory. This commit relaxes the restrictions by introducing LOCAL_INCLUDE_ROOT_OVERRIDES. Entry in the set changes root of the local includes to itself for all files in its subtree.
This commit is contained in:
parent
da060eedb1
commit
da30afa0c3
Notes:
sideshowbarker
2024-07-16 20:44:03 +09:00
Author: https://github.com/DanShaders Commit: https://github.com/SerenityOS/serenity/commit/da30afa0c3 Pull-request: https://github.com/SerenityOS/serenity/pull/20632 Reviewed-by: https://github.com/ADKaster ✅
1 changed files with 15 additions and 2 deletions
|
@ -58,6 +58,10 @@ INCLUDE_CHECK_EXCLUDES = {
|
||||||
"Userland/Libraries/LibCpp/Tests/preprocessor/",
|
"Userland/Libraries/LibCpp/Tests/preprocessor/",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LOCAL_INCLUDE_ROOT_OVERRIDES = {
|
||||||
|
"Meta/Lagom/Tools/CodeGenerators/JSSpecCompiler/",
|
||||||
|
}
|
||||||
|
|
||||||
LOCAL_INCLUDE_SUFFIX_EXCLUDES = [
|
LOCAL_INCLUDE_SUFFIX_EXCLUDES = [
|
||||||
# Some Qt files are required to include their .moc files, which will be located in a deep
|
# Some Qt files are required to include their .moc files, which will be located in a deep
|
||||||
# subdirectory that we won't find from here.
|
# subdirectory that we won't find from here.
|
||||||
|
@ -91,6 +95,12 @@ def is_in_prefix_list(filename, prefix_list):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def find_matching_prefix(filename, prefix_list):
|
||||||
|
matching_prefixes = [prefix for prefix in prefix_list if filename.startswith(prefix)]
|
||||||
|
assert len(matching_prefixes) <= 1
|
||||||
|
return matching_prefixes[0] if matching_prefixes else None
|
||||||
|
|
||||||
|
|
||||||
def run():
|
def run():
|
||||||
errors_license = []
|
errors_license = []
|
||||||
errors_pragma_once_bad = []
|
errors_pragma_once_bad = []
|
||||||
|
@ -124,7 +134,10 @@ def run():
|
||||||
if BAD_INCLUDE_COMPLEX.search(file_content):
|
if BAD_INCLUDE_COMPLEX.search(file_content):
|
||||||
errors_include_bad_complex.append(filename)
|
errors_include_bad_complex.append(filename)
|
||||||
if not is_in_prefix_list(filename, INCLUDE_CHECK_EXCLUDES):
|
if not is_in_prefix_list(filename, INCLUDE_CHECK_EXCLUDES):
|
||||||
file_directory = pathlib.Path(filename).parent
|
if include_root := find_matching_prefix(filename, LOCAL_INCLUDE_ROOT_OVERRIDES):
|
||||||
|
local_include_root = pathlib.Path(include_root)
|
||||||
|
else:
|
||||||
|
local_include_root = pathlib.Path(filename).parent
|
||||||
for include_line in ANY_INCLUDE_PATTERN.findall(file_content):
|
for include_line in ANY_INCLUDE_PATTERN.findall(file_content):
|
||||||
if SYSTEM_INCLUDE_PATTERN.match(include_line):
|
if SYSTEM_INCLUDE_PATTERN.match(include_line):
|
||||||
# Don't try to resolve system-style includes, as these might depend on generators.
|
# Don't try to resolve system-style includes, as these might depend on generators.
|
||||||
|
@ -137,7 +150,7 @@ def run():
|
||||||
continue
|
continue
|
||||||
|
|
||||||
relative_filename = local_match.group(1)
|
relative_filename = local_match.group(1)
|
||||||
referenced_file = file_directory.joinpath(relative_filename)
|
referenced_file = local_include_root.joinpath(relative_filename)
|
||||||
|
|
||||||
if referenced_file.suffix in LOCAL_INCLUDE_SUFFIX_EXCLUDES:
|
if referenced_file.suffix in LOCAL_INCLUDE_SUFFIX_EXCLUDES:
|
||||||
continue
|
continue
|
||||||
|
|
Loading…
Reference in a new issue