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,51 @@ 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 (
191
+ api_filepath , use_template_get_node , bits = "64" , precision = "single" , output_dir = "." , build_profile = {}
192
+ ):
162
193
api = None
163
194
164
195
target_dir = Path (output_dir ) / "gen"
@@ -175,7 +206,7 @@ def generate_bindings(api_filepath, use_template_get_node, bits="64", precision=
175
206
generate_global_constants (api , target_dir )
176
207
generate_global_constant_binds (api , target_dir )
177
208
generate_builtin_bindings (api , target_dir , real_t + "_" + bits )
178
- generate_engine_classes_bindings (api , target_dir , use_template_get_node )
209
+ generate_engine_classes_bindings (api , target_dir , use_template_get_node , build_profile )
179
210
generate_utility_functions (api , target_dir )
180
211
181
212
@@ -1023,7 +1054,7 @@ def generate_builtin_class_source(builtin_api, size, used_classes, fully_used_cl
1023
1054
return "\n " .join (result )
1024
1055
1025
1056
1026
- def generate_engine_classes_bindings (api , output_dir , use_template_get_node ):
1057
+ def generate_engine_classes_bindings (api , output_dir , use_template_get_node , build_profile ):
1027
1058
global engine_classes
1028
1059
global singletons
1029
1060
global native_structures
@@ -1036,6 +1067,8 @@ def generate_engine_classes_bindings(api, output_dir, use_template_get_node):
1036
1067
1037
1068
# First create map of classes and singletons.
1038
1069
for class_api in api ["classes" ]:
1070
+ if not is_class_included (class_api ["name" ], build_profile ):
1071
+ continue
1039
1072
# TODO: Properly setup this singleton since it conflicts with ClassDB in the bindings.
1040
1073
if class_api ["name" ] == "ClassDB" :
1041
1074
continue
@@ -1048,6 +1081,8 @@ def generate_engine_classes_bindings(api, output_dir, use_template_get_node):
1048
1081
singletons .append (singleton ["name" ])
1049
1082
1050
1083
for class_api in api ["classes" ]:
1084
+ if not is_class_included (class_api ["name" ], build_profile ):
1085
+ continue
1051
1086
# TODO: Properly setup this singleton since it conflicts with ClassDB in the bindings.
1052
1087
if class_api ["name" ] == "ClassDB" :
1053
1088
continue
@@ -1161,7 +1196,7 @@ def generate_engine_classes_bindings(api, output_dir, use_template_get_node):
1161
1196
1162
1197
register_engine_classes_filename = Path (output_dir ) / "src" / "register_engine_classes.cpp"
1163
1198
with register_engine_classes_filename .open ("w+" , encoding = "utf-8" ) as source_file :
1164
- source_file .write (generate_register_engine_classes_source (api ))
1199
+ source_file .write (generate_register_engine_classes_source (api , build_profile ))
1165
1200
1166
1201
for native_struct in api ["native_structures" ]:
1167
1202
struct_name = native_struct ["name" ]
@@ -1585,11 +1620,13 @@ def generate_engine_class_source(class_api, used_classes, fully_used_classes, us
1585
1620
return "\n " .join (result )
1586
1621
1587
1622
1588
- def generate_register_engine_classes_source (api ):
1623
+ def generate_register_engine_classes_source (api , build_profile ):
1589
1624
includes = []
1590
1625
registrations = []
1591
1626
1592
1627
for class_api in api ["classes" ]:
1628
+ if not is_class_included (class_api ["name" ], build_profile ):
1629
+ continue
1593
1630
if class_api ["name" ] == "ClassDB" :
1594
1631
continue
1595
1632
0 commit comments