#!/usr/bin/env python3 """Generate the Blender 5.2 RNA data-block type inventory from the pinned runtime.""" import hashlib import json import pathlib import sys import bpy def decode(value): return value.decode("utf-8", errors="replace") if isinstance(value, bytes) else str(value) def binary_sha256(path): digest = hashlib.sha256() with open(path, "rb") as handle: for block in iter(lambda: handle.read(1024 * 1024), b""): digest.update(block) return digest.hexdigest() def main(): if "--" not in sys.argv or len(sys.argv[sys.argv.index("--") + 1:]) != 1: raise SystemExit("usage: blender --background --factory-startup --python generate-blender-rna-datablock-inventory.py -- OUTPUT.json") output = pathlib.Path(sys.argv[sys.argv.index("--") + 1]).resolve() version = tuple(int(value) for value in bpy.app.version) if version != (5, 2, 0): raise RuntimeError(f"expected Blender 5.2.0, got {version}") binary_path = pathlib.Path(bpy.app.binary_path).resolve() entries = [] for cls in bpy.types.ID.__subclasses__(): rna = getattr(cls, "bl_rna", None) identifier = getattr(rna, "identifier", "") if rna else "" if not identifier: raise RuntimeError(f"RNA ID type {cls.__name__} has no identifier") entries.append({ "parityId": f"BLENDER52_RNA_ID_{identifier.upper()}", "rnaIdentifier": identifier, "typeName": cls.__name__, "baseType": "ID", "sourceAnchor": "blender-5.2.0/source/blender/makesrna", }) entries.sort(key=lambda entry: (entry["rnaIdentifier"], entry["typeName"])) identifiers = [entry["rnaIdentifier"] for entry in entries] if len(identifiers) != len(set(identifiers)): raise RuntimeError("duplicate RNA data-block identifier") inventory = { "schemaVersion": 1, "task": "M15-01A", "operation": "BLENDER_RNA_DATABLOCK_INVENTORY", "sourceAnchor": "blender-5.2.0/source/blender/makesrna", "runtime": { "blenderVersion": decode(bpy.app.version_string), "versionTuple": list(version), "buildHash": decode(bpy.app.build_hash), "buildBranch": decode(bpy.app.build_branch), "buildPlatform": decode(bpy.app.build_platform), "buildType": decode(bpy.app.build_type), "buildDate": decode(bpy.app.build_date), "buildTime": decode(bpy.app.build_time), "binarySha256": binary_sha256(binary_path), }, "summary": {"count": len(entries), "baseType": "ID"}, "dataBlockTypes": entries, "nextTask": "M15-01B", } output.parent.mkdir(parents=True, exist_ok=True) output.write_text(json.dumps(inventory, indent=2, sort_keys=True) + "\n", encoding="utf-8") print(f"blender-rna-datablock-inventory-generated count={len(entries)} blender={bpy.app.version_string} output={output}") if __name__ == "__main__": main()