#!/usr/bin/env python3 """Extract exact full C bodies and bind offsets/full-file SHA/slice SHA.""" import argparse, hashlib, json, pathlib, re ap=argparse.ArgumentParser();ap.add_argument("--sources",type=pathlib.Path,required=True);ap.add_argument("--output",type=pathlib.Path,required=True);args=ap.parse_args() if not args.output.absolute().is_relative_to(pathlib.Path("/var/tmp")) or args.output.absolute().resolve()!=args.output.absolute(): raise ValueError("Explicit private /var/tmp output required") args.output.mkdir(parents=True,exist_ok=True) bindings=[] def extract(component,relative,name): path=args.sources/component/relative;raw=path.read_bytes() # Definitions have their opening brace before the next semicolon. found=[] for match in re.finditer(rb"^(?:static )?(?:struct [A-Za-z_0-9]+ \*|bool |void |int )"+name.encode()+rb"\(",raw,re.M): a=match.start();opening=raw.index(b"{",match.end());semi=raw.find(b";",match.end()) if semi>=0 and semiscene_tree)",a) piece=raw[a:b] bindings.append(dict(component="mosaic",path="sway/desktop/xdg_shell.c",symbol="exact primary popup diagnostic callsite",fullfile_sha256=hashlib.sha256(raw).hexdigest(),start_byte=a,end_byte_exclusive=b,slice_sha256=hashlib.sha256(piece).hexdigest())) (args.output/"callsite.c").write_bytes(b"#define WLR_USE_UNSTABLE\n#include \n#include \nstruct adapter_popup {struct wlr_scene_tree *scene_tree;};\nextern struct wlr_scene_tree *smx_oom_popup_tree_create(struct wlr_scene_tree *, const char *, const void *, const void *);\nvoid test_callsite(struct adapter_popup *popup, struct wlr_scene_tree *parent, struct wlr_xdg_popup *wlr_popup, struct wlr_xdg_surface *xdg_surface) {\n"+piece+b"\n}\n") (args.output/"bindings.json").write_text(json.dumps(bindings,indent=2)+"\n")