3
3
import json
4
4
import re
5
5
import shutil
6
+ import sys
6
7
from pathlib import Path
7
8
8
9
10
+ def is_class_included (class_name , build_profile ):
11
+ if "enabled_classes" in build_profile :
12
+ return class_name in build_profile ["enabled_classes" ]
13
+ if "disabled_classes" in build_profile :
14
+ return class_name not in build_profile ["disabled_classes" ]
15
+ return True
16
+
17
+
9
18
def generate_mod_version (argcount , const = False , returns = False ):
10
19
s = """
11
20
#define MODBIND$VER($RETTYPE m_name$ARG) \\
@@ -70,7 +79,7 @@ def generate_wrappers(target):
70
79
f .write (txt )
71
80
72
81
73
- def get_file_list (api_filepath , output_dir , headers = False , sources = False ):
82
+ def get_file_list (api_filepath , output_dir , headers = False , sources = False , build_profile = {} ):
74
83
api = {}
75
84
files = []
76
85
with open (api_filepath , encoding = "utf-8" ) as api_file :
@@ -97,6 +106,8 @@ def get_file_list(api_filepath, output_dir, headers=False, sources=False):
97
106
files .append (str (source_filename .as_posix ()))
98
107
99
108
for engine_class in api ["classes" ]:
109
+ if not is_class_included (engine_class ["name" ], build_profile ):
110
+ continue
100
111
# TODO: Properly setup this singleton since it conflicts with ClassDB in the bindings.
101
112
if engine_class ["name" ] == "ClassDB" :
102
113
continue
@@ -134,31 +145,49 @@ def get_file_list(api_filepath, output_dir, headers=False, sources=False):
134
145
return files
135
146
136
147
137
- def print_file_list (api_filepath , output_dir , headers = False , sources = False ):
148
+ def print_file_list (api_filepath , output_dir , headers = False , sources = False , build_profile = {} ):
138
149
end = ";"
139
- for f in get_file_list (api_filepath , output_dir , headers , sources ):
150
+ for f in get_file_list (api_filepath , output_dir , headers , sources , build_profile ):
140
151
print (f , end = end )
141
152
142
153
154
+ def scons_parse_build_profile (env ):
155
+ if env ["build_profile" ] != "" :
156
+ print ("Using feature build profile: " + env ["build_profile" ])
157
+ import json
158
+
159
+ path = env .File (env ["build_profile" ]).abspath
160
+ try :
161
+ ft = json .load (open (path ))
162
+ return ft
163
+ except :
164
+ print ("Error opening feature build profile: " + path )
165
+ sys .exit (255 )
166
+ return {}
167
+
168
+
143
169
def scons_emit_files (target , source , env ):
144
- files = [env .File (f ) for f in get_file_list (str (source [0 ]), target [0 ].abspath , True , True )]
170
+ build_profile = scons_parse_build_profile (env )
171
+ files = [env .File (f ) for f in get_file_list (str (source [0 ]), target [0 ].abspath , True , True , build_profile )]
145
172
env .Clean (target , files )
146
173
env ["godot_cpp_gen_dir" ] = target [0 ].abspath
147
174
return files , source
148
175
149
176
150
177
def scons_generate_bindings (target , source , env ):
178
+ build_profile = scons_parse_build_profile (env )
151
179
generate_bindings (
152
180
str (source [0 ]),
153
181
env ["generate_template_get_node" ],
154
182
"32" if "32" in env ["arch" ] else "64" ,
155
183
env ["precision" ],
156
184
env ["godot_cpp_gen_dir" ],
185
+ build_profile ,
157
186
)
158
187
return None
159
188
160
189
161
- def generate_bindings (api_filepath , use_template_get_node , bits = "64" , precision = "single" , output_dir = "." ):
190
+ def generate_bindings (api_filepath , use_template_get_node , bits = "64" , precision = "single" , output_dir = "." , build_profile = {} ):
162
191
api = None
163
192
164
193
target_dir = Path (output_dir ) / "gen"
@@ -175,7 +204,7 @@ def generate_bindings(api_filepath, use_template_get_node, bits="64", precision=
175
204
generate_global_constants (api , target_dir )
176
205
generate_global_constant_binds (api , target_dir )
177
206
generate_builtin_bindings (api , target_dir , real_t + "_" + bits )
178
- generate_engine_classes_bindings (api , target_dir , use_template_get_node )
207
+ generate_engine_classes_bindings (api , target_dir , use_template_get_node , build_profile )
179
208
generate_utility_functions (api , target_dir )
180
209
181
210
@@ -1023,7 +1052,7 @@ def generate_builtin_class_source(builtin_api, size, used_classes, fully_used_cl
1023
1052
return "\n " .join (result )
1024
1053
1025
1054
1026
- def generate_engine_classes_bindings (api , output_dir , use_template_get_node ):
1055
+ def generate_engine_classes_bindings (api , output_dir , use_template_get_node , build_profile ):
1027
1056
global engine_classes
1028
1057
global singletons
1029
1058
global native_structures
@@ -1036,6 +1065,8 @@ def generate_engine_classes_bindings(api, output_dir, use_template_get_node):
1036
1065
1037
1066
# First create map of classes and singletons.
1038
1067
for class_api in api ["classes" ]:
1068
+ if not is_class_included (class_api ["name" ], build_profile ):
1069
+ continue
1039
1070
# TODO: Properly setup this singleton since it conflicts with ClassDB in the bindings.
1040
1071
if class_api ["name" ] == "ClassDB" :
1041
1072
continue
@@ -1048,6 +1079,8 @@ def generate_engine_classes_bindings(api, output_dir, use_template_get_node):
1048
1079
singletons .append (singleton ["name" ])
1049
1080
1050
1081
for class_api in api ["classes" ]:
1082
+ if not is_class_included (class_api ["name" ], build_profile ):
1083
+ continue
1051
1084
# TODO: Properly setup this singleton since it conflicts with ClassDB in the bindings.
1052
1085
if class_api ["name" ] == "ClassDB" :
1053
1086
continue
@@ -1161,7 +1194,7 @@ def generate_engine_classes_bindings(api, output_dir, use_template_get_node):
1161
1194
1162
1195
register_engine_classes_filename = Path (output_dir ) / "src" / "register_engine_classes.cpp"
1163
1196
with register_engine_classes_filename .open ("w+" , encoding = "utf-8" ) as source_file :
1164
- source_file .write (generate_register_engine_classes_source (api ))
1197
+ source_file .write (generate_register_engine_classes_source (api , build_profile ))
1165
1198
1166
1199
for native_struct in api ["native_structures" ]:
1167
1200
struct_name = native_struct ["name" ]
@@ -1585,11 +1618,13 @@ def generate_engine_class_source(class_api, used_classes, fully_used_classes, us
1585
1618
return "\n " .join (result )
1586
1619
1587
1620
1588
- def generate_register_engine_classes_source (api ):
1621
+ def generate_register_engine_classes_source (api , build_profile ):
1589
1622
includes = []
1590
1623
registrations = []
1591
1624
1592
1625
for class_api in api ["classes" ]:
1626
+ if not is_class_included (class_api ["name" ], build_profile ):
1627
+ continue
1593
1628
if class_api ["name" ] == "ClassDB" :
1594
1629
continue
1595
1630
0 commit comments