Entry point for this script.
56 """!
57 @brief Entry point for this script.
58 @return Value returned by `main()`.
59 """
60 parser = argparse.ArgumentParser(
61 description=(
62 "Scan PETSc option ingress in src/setup.c and src/io.c, then compare "
63 "against scripts/audit_ingress_manifest.json."
64 ),
65 formatter_class=argparse.RawDescriptionHelpFormatter,
66 epilog=(
67 "Examples:\n"
68 " python3 scripts/audit_ingress.py\n"
69 " python3 scripts/audit_ingress.py --show-scanned\n"
70 " python3 scripts/audit_ingress.py --manifest scripts/audit_ingress_manifest.json\n"
71 ),
72 )
73 parser.add_argument(
74 "--manifest",
75 default="scripts/audit_ingress_manifest.json",
76 help=(
77 "Manifest JSON path, relative to repository root unless absolute "
78 "(default: scripts/audit_ingress_manifest.json)."
79 ),
80 )
81 parser.add_argument(
82 "--show-scanned",
83 action="store_true",
84 help="Print discovered PETSc options before drift comparison.",
85 )
86 args = parser.parse_args()
87
88 repo_root = pathlib.Path(__file__).resolve().parents[1]
89 manifest_path = (repo_root / args.manifest).resolve()
90 scan_paths = [repo_root / "src/setup.c", repo_root / "src/io.c"]
91
92 if not manifest_path.exists():
93 print(f"[ERROR] Manifest not found: {manifest_path}", file=sys.stderr)
94 return 2
95
96 scanned = scan_petsc_options(scan_paths)
97 expected = load_manifest(manifest_path)
98
99 missing_in_manifest = sorted(scanned - expected)
100 stale_in_manifest = sorted(expected - scanned)
101
102 if args.show_scanned:
103 print("[INFO] Scanned PETSc options:")
104 for flag in sorted(scanned):
105 print(flag)
106 print("")
107
108 print(f"[INFO] Scanned options: {len(scanned)}")
109 print(f"[INFO] Manifest options: {len(expected)}")
110
111 if missing_in_manifest:
112 print("[ERROR] New PETSc ingress options missing in manifest:")
113 for flag in missing_in_manifest:
114 print(f" - {flag}")
115
116 if stale_in_manifest:
117 print("[ERROR] Manifest options no longer present in setup/io scan:")
118 for flag in stale_in_manifest:
119 print(f" - {flag}")
120
121 if missing_in_manifest or stale_in_manifest:
122 print(
123 "[FAIL] Ingress drift detected. Update scripts/audit_ingress_manifest.json and docs mapping.",
124 file=sys.stderr,
125 )
126 return 1
127
128 print("[OK] Ingress manifest matches setup/io PETSc option scan.")
129 return 0
130
131
int main(int argc, char **argv)
Entry point for the postprocessor executable.