Skip to content

Commit 65d0179

Browse files
committed
Add metadata generator
1 parent 18b0865 commit 65d0179

File tree

3 files changed

+44
-0
lines changed

3 files changed

+44
-0
lines changed

libs/metadata_generators/__init__.py

Whitespace-only changes.
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import clang.cindex
2+
import json
3+
4+
clang.cindex.Config.set_library_path(
5+
"/Applications/Xcode.app/Contents/Developer/Toolchains/"
6+
"XcodeDefault.xctoolchain/usr/lib/"
7+
)
8+
index = clang.cindex.Index.create()
9+
10+
11+
def extract(cursor):
12+
data = {"Name": cursor.spelling}
13+
if cursor.kind == clang.cindex.CursorKind.OBJC_INTERFACE_DECL:
14+
data["Type"] = "Interface"
15+
elif cursor.kind in [
16+
clang.cindex.CursorKind.OBJC_INSTANCE_METHOD_DECL,
17+
clang.cindex.CursorKind.OBJC_CLASS_METHOD_DECL,
18+
]:
19+
data["Type"] = "Method"
20+
elif cursor.kind == clang.cindex.CursorKind.OBJC_PROPERTY_DECL:
21+
data["Type"] = "Property"
22+
else:
23+
return None
24+
children = [extract(c) for c in cursor.get_children()]
25+
children = [c for c in children if c is not None]
26+
if children:
27+
data["Children"] = children
28+
return data
29+
30+
31+
def main():
32+
tu = index.parse(
33+
"/Applications/Xcode.app/Contents/Developer/Platforms/"
34+
"iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/"
35+
"Library/Frameworks/UIKit.framework/Headers/UIKit.h"
36+
)
37+
metadata = extract(tu.cursor)
38+
with open("metadata.json", "w") as f:
39+
json.dump(metadata, f, indent=2)
40+
41+
42+
if __name__ == "__main__":
43+
main()

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ build==0.10.0
77
certifi==2023.5.7
88
chardet==5.1.0
99
charset-normalizer==3.1.0
10+
clang==16.0.1.1
1011
click==8.1.3
1112
contourpy==1.0.7
1213
cookiecutter==2.1.1

0 commit comments

Comments
 (0)