11import clang .cindex
22import json
33
4- clang .cindex .Config .set_library_path (
5- "/Applications/Xcode.app/Contents/Developer/Toolchains/"
6- "XcodeDefault.xctoolchain/usr/lib/"
7- )
4+ clang .cindex .Config .set_library_path ("/usr/local/Cellar/llvm/16.0.4/lib/" )
85index = clang .cindex .Index .create ()
96
107
118def extract (cursor ):
9+ print (f"{ cursor .kind } : { cursor .spelling } " )
1210 data = {"Name" : cursor .spelling }
1311 if cursor .kind == clang .cindex .CursorKind .OBJC_INTERFACE_DECL :
1412 data ["Type" ] = "Interface"
@@ -29,11 +27,31 @@ def extract(cursor):
2927
3028
3129def main ():
30+ args = [
31+ "-x" , "objective-c" ,
32+ "-arch" , "arm64" ,
33+ "-fno-objc-arc" ,
34+ # "-fmodules",
35+ # "-fmodule-maps",
36+ "-ferror-limit=0" ,
37+ "-isysroot" ,
38+ "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk" ,
39+ "-I/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/include" ,
40+ "-I/usr/local/include" ,
41+ "-I/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/14.0.3/include" ,
42+ "-I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include" ,
43+ "-I/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include" ,
44+ "-I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks"
45+ ]
3246 tu = index .parse (
3347 "/Applications/Xcode.app/Contents/Developer/Platforms/"
3448 "iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/"
35- "Library/Frameworks/UIKit.framework/Headers/UIKit.h"
49+ "Library/Frameworks/UIKit.framework/Headers/UIKit.h" ,
50+ args
3651 )
52+ print (f"Translation unit: { tu .spelling } " )
53+ for diag in tu .diagnostics :
54+ print (diag )
3755 metadata = extract (tu .cursor )
3856 with open ("metadata.json" , "w" ) as f :
3957 json .dump (metadata , f , indent = 2 )
0 commit comments