1
+ #!/usr/bin/env python
2
+
3
+ import os
4
+ import re
5
+ import json
6
+
7
+ SOURCE_DIRS = [
8
+ '../../common' ,
9
+ '../../godotopenxrkhronos' ,
10
+ '../../godotopenxrlynx' ,
11
+ '../../godotopenxrmeta' ,
12
+ '../../godotopenxrpico' ,
13
+ ]
14
+
15
+ GODOT_CPP_HEADERS = "../godot-cpp/gen/include/godot_cpp/classes"
16
+ #GODOT_CPP_SOURCES = "../godot-cpp/gen/src/classes"
17
+
18
+ INCLUDE_PATTERN = re .compile (r'#include <godot_cpp/classes/(\w+)\.hpp>' )
19
+ CLASS_PATTERN = re .compile (r'class\s+(\w+)\s*:\s*public' )
20
+
21
+ processed_files = {}
22
+ class_list = []
23
+
24
+ def find_includes (file_path ):
25
+ """
26
+ Finds all the includes in a given file and returns the list of CLASS names.
27
+ """
28
+ includes = []
29
+ try :
30
+ with open (file_path , 'r' ) as file :
31
+ content = file .read ()
32
+ includes = INCLUDE_PATTERN .findall (content )
33
+ except FileNotFoundError :
34
+ print (f"File not found: { file_path } " )
35
+ return includes
36
+
37
+ def find_primary_class (file_path ):
38
+ """
39
+ Finds the primary class name in a given .hpp file by looking for 'class ClassName : public'.
40
+ """
41
+ try :
42
+ with open (file_path , 'r' ) as file :
43
+ for line in file :
44
+ match = CLASS_PATTERN .search (line )
45
+ if match :
46
+ return match .group (1 )
47
+ except FileNotFoundError :
48
+ print (f"File not found: { file_path } " )
49
+ return None
50
+
51
+ def process_file (file_path , top_level = False ):
52
+ """
53
+ Processes a given file for includes and processes the included files recursively.
54
+ """
55
+ if file_path in processed_files :
56
+ return
57
+
58
+ processed_files [file_path ] = True
59
+
60
+ if not top_level and file_path .endswith ('.hpp' ):
61
+ primary_class = find_primary_class (file_path )
62
+ if primary_class and primary_class not in class_list :
63
+ class_list .append (primary_class )
64
+
65
+ includes = find_includes (file_path )
66
+ for include_name in includes :
67
+ hpp_file = f"{ GODOT_CPP_HEADERS } /{ include_name } .hpp"
68
+ #cpp_file = f"{GODOT_CPP_SOURCES}/{include_name}.cpp"
69
+
70
+ if os .path .exists (hpp_file ):
71
+ process_file (hpp_file )
72
+ #if os.path.exists(cpp_file):
73
+ # process_file(cpp_file)
74
+
75
+ def main ():
76
+ for dir in SOURCE_DIRS :
77
+ for root , _ , files in os .walk (dir ):
78
+ for file in files :
79
+ if file .endswith ('.cpp' ) or file .endswith ('.h' ):
80
+ file_path = os .path .join (root , file )
81
+ process_file (file_path , True )
82
+
83
+ class_list .sort ()
84
+
85
+ build_profile = {
86
+ "enabled_classes" : class_list
87
+ }
88
+
89
+ with open ("build_profile.json" , "wt" ) as file :
90
+ json .dump (build_profile , file , indent = 4 )
91
+
92
+ if __name__ == "__main__" :
93
+ main ()
0 commit comments