Repository navigation
Expand file tree
/
Copy pathverify_layer_boundaries.py
More file actions
57 lines (51 loc) · 2.39 KB
/
Copy pathverify_layer_boundaries.py
File metadata and controls
57 lines (51 loc) · 2.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/usr/bin/env python3
"""Check compiled runtime symbols and generated CMake kernel dependencies."""
import argparse
import re
import subprocess
from pathlib import Path
EXPECTED = {
"teaql_core": {"teaql::memory"},
"teaql_memory": {"Threads::Threads"},
"teaql_data_service": {"teaql::core", "teaql::async", "Threads::Threads"},
"teaql_sql": {"teaql::data_service"},
"teaql_runtime": {"teaql::sql"},
}
def main():
parser = argparse.ArgumentParser()
parser.add_argument("--runtime", required=True, type=Path)
parser.add_argument("--nm", required=True)
parser.add_argument("--metadata", type=Path)
args = parser.parse_args()
symbols = subprocess.run([args.nm, "-u", str(args.runtime)],
text=True, capture_output=True, check=True).stdout
native = sorted(set(re.findall(r"\bsqlite3_\w+\b", symbols)))
if native:
raise RuntimeError("Runtime calls the SQLite C API: " + ", ".join(native))
if args.metadata:
sections = {}
current = None
for line in args.metadata.read_text().splitlines():
if line.startswith("[") and line.endswith("]"):
current = line[1:-1]
sections[current] = {}
elif line and current:
key, value = line.split("=", 1)
sections[current][key] = value
if sections.keys() != EXPECTED.keys():
raise RuntimeError("Incomplete generated kernel dependency metadata")
for target, allowed in EXPECTED.items():
for property_name in ["LINK", "INTERFACE"]:
value = sections[target][property_name]
if re.search(r"sqlite3|legacy_sqlite|provider_sqlite", value, re.I):
raise RuntimeError(f"{target} retains a backend dependency: {value}")
dependencies = set(filter(None, value.split(";")))
if dependencies != allowed:
raise RuntimeError(f"Unreviewed {target} {property_name}: {value}")
if re.search(r"(?:^|[/;])(?:sqlite|legacy_sqlite_compiler)\.cpp(?:;|$)",
sections[target]["SOURCES"]):
raise RuntimeError(f"{target} compiles the compatibility SQLite path")
print("Verified kernel layers retain their independent dependencies")
print("Verified compiled runtime has no SQLite C API calls")
if __name__ == "__main__":
main()