Skip to content

Truly independent web browser

Meta: Keep the fetch engine from including the rest of LibWeb

Luke Wilde95519f3c9f29
diff --git a/Meta/Linters/check_fetch_engine_includes.py b/Meta/Linters/check_fetch_engine_includes.py
index 061bca0fd2b..029be38248e 100755
--- a/Meta/Linters/check_fetch_engine_includes.py
+++ b/Meta/Linters/check_fetch_engine_includes.py
@@ -6,24 +6,34 @@ import sys
REPO_ROOT = pathlib.Path(__file__).resolve().parents[2]
ENGINE_ROOT = pathlib.Path("Libraries/LibWeb/Fetch/Engine")
-FORBIDDEN_INCLUDE = re.compile(r'^\s*#\s*include\s*[<"](LibJS|LibGC)/')
+INCLUDE = re.compile(r'^\s*#\s*include\s*[<"]([^>"]+)[>"]')
+FORBIDDEN_PREFIXES = ("LibJS/", "LibGC/", "LibWeb/")
+ALLOWED_PREFIXES = ("LibWeb/Fetch/Engine/", "LibWeb/Export.h")
CHECKED_SUFFIXES = {".cpp", ".h"}
+def is_forbidden(included_path: str) -> bool:
+ return included_path.startswith(FORBIDDEN_PREFIXES) and not included_path.startswith(ALLOWED_PREFIXES)
+
+
def main() -> int:
offenders = []
for path in sorted((REPO_ROOT / ENGINE_ROOT).rglob("*")):
if path.suffix not in CHECKED_SUFFIXES:
continue
for line_number, line in enumerate(path.read_text(encoding="utf-8").splitlines(), start=1):
- if FORBIDDEN_INCLUDE.match(line):
+ match = INCLUDE.match(line)
+ if match and is_forbidden(match.group(1)):
offenders.append(f"{path.relative_to(REPO_ROOT)}:{line_number}: {line.strip()}")
if not offenders:
return 0
- print(f"{ENGINE_ROOT} must not include LibJS or LibGC:", file=sys.stderr)
+ print(
+ f"{ENGINE_ROOT} must not include LibJS, LibGC, or LibWeb outside {ENGINE_ROOT} and LibWeb/Export.h:",
+ file=sys.stderr,
+ )
for offender in offenders:
print(f" {offender}", file=sys.stderr)
return 1