26 lines
926 B
Python
26 lines
926 B
Python
"""Read the diagnostic kernel translation unit before test-only injection.
|
|
|
|
Only component module C includes are expanded. Header includes and the
|
|
amalgamation linkage switch remain for the ordinary C preprocessor to handle.
|
|
An older, unsplit kernels.c is returned unchanged.
|
|
"""
|
|
from pathlib import Path
|
|
import re
|
|
|
|
|
|
NATIVE = Path(__file__).resolve().parents[1] / "native"
|
|
_SOURCE_INCLUDE = re.compile(r'^[ \t]*#[ \t]*include[ \t]+"([^"\n]+\.c)"[ \t]*$', re.MULTILINE)
|
|
|
|
|
|
def native_kernel_source(native: Path = NATIVE) -> str:
|
|
entry = native / "components/kernels.c"
|
|
modules = (native / "components/modules").resolve()
|
|
|
|
def expand(match: re.Match[str]) -> str:
|
|
source = (entry.parent / match[1]).resolve()
|
|
if not source.is_relative_to(modules):
|
|
return match[0]
|
|
return source.read_text(encoding="utf-8")
|
|
|
|
return _SOURCE_INCLUDE.sub(expand, entry.read_text(encoding="utf-8"))
|