|
| 1 | +#!/usr/bin/env python3 |
| 2 | +"""Remove compiler-artifact symbols from DocC symbol graph JSON files. |
| 3 | +
|
| 4 | +Newer Swift compilers (Xcode 16.3+) import `char8_t` from auto-generated |
| 5 | +-Swift.h bridging headers as a public typealias. When the dependency module |
| 6 | +is re-exported (via @_exported import), these symbols leak into the |
| 7 | +MapboxMaps documentation. This script strips them from the symbol graphs |
| 8 | +before DocC processes them. |
| 9 | +""" |
| 10 | + |
| 11 | +import json |
| 12 | +import os |
| 13 | +import sys |
| 14 | + |
| 15 | +# Symbols that are compiler artifacts and should not appear in public docs. |
| 16 | +ARTIFACTS = {"char8_t"} |
| 17 | + |
| 18 | + |
| 19 | +def strip(path): |
| 20 | + with open(path) as f: |
| 21 | + sg = json.load(f) |
| 22 | + |
| 23 | + artifact_ids = set() |
| 24 | + filtered_symbols = [] |
| 25 | + for sym in sg.get("symbols", []): |
| 26 | + if sym["names"]["title"] in ARTIFACTS: |
| 27 | + artifact_ids.add(sym["identifier"]["precise"]) |
| 28 | + else: |
| 29 | + filtered_symbols.append(sym) |
| 30 | + |
| 31 | + if not artifact_ids: |
| 32 | + return |
| 33 | + |
| 34 | + sg["symbols"] = filtered_symbols |
| 35 | + sg["relationships"] = [ |
| 36 | + r for r in sg.get("relationships", []) if r["source"] not in artifact_ids and r["target"] not in artifact_ids |
| 37 | + ] |
| 38 | + |
| 39 | + with open(path, "w") as f: |
| 40 | + json.dump(sg, f) |
| 41 | + |
| 42 | + basepath = os.path.relpath(path, sys.argv[1]) |
| 43 | + print(f" Stripped {artifact_ids} from {basepath}") |
| 44 | + |
| 45 | + |
| 46 | +def main(): |
| 47 | + symbol_graph_dir = sys.argv[1] |
| 48 | + print(f"Stripping compiler artifacts from symbol graphs in {symbol_graph_dir}") |
| 49 | + for root, _, files in os.walk(symbol_graph_dir): |
| 50 | + for name in files: |
| 51 | + if name.endswith(".symbols.json"): |
| 52 | + strip(os.path.join(root, name)) |
| 53 | + |
| 54 | + |
| 55 | +if __name__ == "__main__": |
| 56 | + main() |
0 commit comments