@@ -200,7 +200,7 @@ def generate_virtuals(target):
200200 f .write (txt )
201201
202202
203- def get_file_list (api_filepath , output_dir , headers = False , sources = False , compat = False , profile_filepath = "" ):
203+ def get_file_list (api_filepath , output_dir , headers = False , sources = False , profile_filepath = "" ):
204204 api = {}
205205 files = []
206206 with open (api_filepath , encoding = "utf-8" ) as api_file :
@@ -210,7 +210,6 @@ def get_file_list(api_filepath, output_dir, headers=False, sources=False, compat
210210
211211 core_gen_folder = Path (output_dir ) / "gen" / "include" / "godot_cpp" / "core"
212212 include_gen_folder = Path (output_dir ) / "gen" / "include" / "godot_cpp"
213- include_gen_compat_folder = Path (output_dir ) / "gen" / "include" / "godot_compat"
214213 source_gen_folder = Path (output_dir ) / "gen" / "src"
215214
216215 files .append (str ((core_gen_folder / "ext_wrappers.gen.inc" ).as_posix ()))
@@ -224,12 +223,9 @@ def get_file_list(api_filepath, output_dir, headers=False, sources=False, compat
224223 continue
225224
226225 header_filename = include_gen_folder / "variant" / (camel_to_snake (builtin_class ["name" ]) + ".hpp" )
227- header_compat_filename = include_gen_compat_folder / "variant" / (camel_to_snake (builtin_class ["name" ]) + ".hpp" )
228226 source_filename = source_gen_folder / "variant" / (camel_to_snake (builtin_class ["name" ]) + ".cpp" )
229227 if headers :
230228 files .append (str (header_filename .as_posix ()))
231- if compat :
232- files .append (str (header_compat_filename .as_posix ()))
233229 if sources :
234230 files .append (str (source_filename .as_posix ()))
235231
@@ -239,12 +235,9 @@ def get_file_list(api_filepath, output_dir, headers=False, sources=False, compat
239235 engine_class ["name" ] = "ClassDBSingleton"
240236 engine_class ["alias_for" ] = "ClassDB"
241237 header_filename = include_gen_folder / "classes" / (camel_to_snake (engine_class ["name" ]) + ".hpp" )
242- header_compat_filename = include_gen_compat_folder / "classes" / (camel_to_snake (engine_class ["name" ]) + ".hpp" )
243238 source_filename = source_gen_folder / "classes" / (camel_to_snake (engine_class ["name" ]) + ".cpp" )
244239 if headers :
245240 files .append (str (header_filename .as_posix ()))
246- if compat :
247- files .append (str (header_compat_filename .as_posix ()))
248241 if sources and is_class_included (engine_class ["name" ], build_profile ):
249242 files .append (str (source_filename .as_posix ()))
250243
@@ -255,39 +248,30 @@ def get_file_list(api_filepath, output_dir, headers=False, sources=False, compat
255248 snake_struct_name = camel_to_snake (struct_name )
256249
257250 header_filename = include_gen_folder / "classes" / (snake_struct_name + ".hpp" )
258- header_compat_filename = include_gen_compat_folder / "classes" / (snake_struct_name + ".hpp" )
259251 if headers :
260252 files .append (str (header_filename .as_posix ()))
261- if compat :
262- files .append (str (header_compat_filename .as_posix ()))
263253
264254 if headers :
265- relative_paths = [
266- ["variant" , "builtin_types.hpp" ],
267- ["variant" , "builtin_binds.hpp" ],
268- ["variant" , "utility_functions.hpp" ],
269- ["variant" , "variant_size.hpp" ],
270- ["variant" , "builtin_vararg_methods.hpp" ],
271- ["classes" , "global_constants.hpp" ],
272- ["classes" , "global_constants_binds.hpp" ],
273- ["core" , "version.hpp" ]
274- ]
275-
276- for relative_path_parts in relative_paths :
277- full_header_path = include_gen_folder .joinpath (* relative_path_parts )
278- files .append (str (full_header_path .as_posix ()))
279- if compat :
280- full_compat_path = include_gen_compat_folder .joinpath (* relative_path_parts )
281- files .append (str (full_compat_path .as_posix ()))
255+ for path in [
256+ include_gen_folder / "variant" / "builtin_types.hpp" ,
257+ include_gen_folder / "variant" / "builtin_binds.hpp" ,
258+ include_gen_folder / "variant" / "utility_functions.hpp" ,
259+ include_gen_folder / "variant" / "variant_size.hpp" ,
260+ include_gen_folder / "variant" / "builtin_vararg_methods.hpp" ,
261+ include_gen_folder / "classes" / "global_constants.hpp" ,
262+ include_gen_folder / "classes" / "global_constants_binds.hpp" ,
263+ include_gen_folder / "core" / "version.hpp" ,
264+ ]:
265+ files .append (str (path .as_posix ()))
282266 if sources :
283267 utility_functions_source_path = source_gen_folder / "variant" / "utility_functions.cpp"
284268 files .append (str (utility_functions_source_path .as_posix ()))
285269
286270 return files
287271
288272
289- def print_file_list (api_filepath , output_dir , headers = False , sources = False , compat = False , profile_filepath = "" ):
290- print (* get_file_list (api_filepath , output_dir , headers , sources , compat , profile_filepath ), sep = ";" , end = None )
273+ def print_file_list (api_filepath , output_dir , headers = False , sources = False , profile_filepath = "" ):
274+ print (* get_file_list (api_filepath , output_dir , headers , sources , profile_filepath ), sep = ";" , end = None )
291275
292276
293277def parse_build_profile (profile_filepath , api ):
@@ -384,7 +368,7 @@ def scons_emit_files(target, source, env):
384368 if profile_filepath and not Path (profile_filepath ).is_absolute ():
385369 profile_filepath = str ((Path (env .Dir ("#" ).abspath ) / profile_filepath ).as_posix ())
386370
387- files = [env .File (f ) for f in get_file_list (str (source [0 ]), target [0 ].abspath , True , True , env [ "godot_repo" ] != "" , profile_filepath )]
371+ files = [env .File (f ) for f in get_file_list (str (source [0 ]), target [0 ].abspath , True , True , profile_filepath )]
388372 env .Clean (target , files )
389373 env ["godot_cpp_gen_dir" ] = target [0 ].abspath
390374 return files , source
@@ -423,7 +407,7 @@ def generate_bindings(api_filepath, use_template_get_node, bits="64", precision=
423407 generate_engine_classes_bindings (api , target_dir , use_template_get_node )
424408 generate_utility_functions (api , target_dir )
425409 if godot_repo != "" :
426- generate_compat_includes (godot_repo , output_dir )
410+ generate_compat_includes (godot_repo , output_dir , target_dir )
427411
428412
429413CLASS_ALIASES = {
@@ -1567,40 +1551,49 @@ def generate_engine_classes_bindings(api, output_dir, use_template_get_node):
15671551 header_file .write ("\n " .join (result ))
15681552
15691553
1570- def generate_compat_includes (godot_repo : Path , output_dir : Path ):
1571- file_types_mapping_godot_cpp_gen = map_header_files (output_dir )
1554+ def generate_compat_includes (godot_repo : Path , output_dir : Path , target_dir : Path ):
1555+ target_dir = output_dir
1556+ file_types_mapping_godot_cpp_gen = map_header_files (target_dir )
15721557 file_types_mapping_godot = map_header_files (godot_repo )
15731558 # Match the headers
15741559 file_types_mapping = match_headers (file_types_mapping_godot_cpp_gen , file_types_mapping_godot )
1575-
15761560 for file_godot_cpp_name , file_godot_names in file_types_mapping .items ():
1577- file_godot_cpp_name = Path (file_godot_cpp_name ).as_posix ()
1578- header_filepath = file_godot_cpp_name .replace ("godot_cpp" , "godot_compat" )
1579- if "gen/include" not in header_filepath :
1580- header_filepath = header_filepath .replace ("include/" , "gen/include/" )
1581- Path (os .path .dirname (Path (output_dir ) / Path (header_filepath ))).mkdir (parents = True , exist_ok = True )
15821561 result = []
1583- snake_header_name = camel_to_snake (header_filepath )
1584- add_header (f"{ snake_header_name } .hpp" , result )
1562+ with (Path (target_dir ) / Path (file_godot_cpp_name )).open ("r" , encoding = "utf-8" ) as header_file :
1563+ content = header_file .readlines ()
1564+ # Find the last line (#endif guard)
1565+ last_endif_idx = len (content ) - 1
1566+ # Look for the marker for the header guard (usually #define)
1567+ marker_pos = next ((i for i , line in enumerate (content ) if line .startswith ("#define" )), - 1 )
1568+
1569+ if marker_pos != - 1 :
1570+ # Add content before the last #endif
1571+ before_marker = content [:marker_pos + 1 ] # Include up to the marker line
1572+ after_marker = content [marker_pos + 1 :last_endif_idx ] # Content excluding the final #endif
1573+
1574+ result .extend (before_marker ) # Append original content up to marker
1575+ result .append ("\n " ) # Blank line for separation
1576+
1577+ # Insert the #ifdef block
1578+ result .append (f"#ifdef GODOT_MODULE_COMPAT\n " )
1579+ if len (file_godot_names ) == 0 :
1580+ print ("No header found for" , file_godot_cpp_name )
1581+ for file_godot_name in file_godot_names :
1582+ result .append (f"#include <{ Path (file_godot_name ).as_posix ()} >\n " )
1583+ result .append (f"#else\n " )
1584+
1585+ result .extend (after_marker ) # Append the remaining content inside the guard
1586+
1587+ # Add the namespace and endif
1588+ result .append (f"#endif\n " )
1589+
1590+ # Finally, append the original final #endif line
1591+ result .append (content [last_endif_idx ].strip ())
15851592
1586- header_guard = f"GODOT_COMPAT_{ os .path .splitext (os .path .basename (header_filepath ).upper ())[0 ]} _HPP"
1587- result .append (f"#ifndef { header_guard } " )
1588- result .append (f"#define { header_guard } " )
1589- result .append ("" )
1590- result .append (f"#ifdef GODOT_MODULE_COMPAT" )
1591- for file_godot_name in file_godot_names :
1592- result .append (f"#include <{ Path (file_godot_name ).as_posix ()} >" )
1593-
1594- result .append (f"#else" )
1595- file_godot_cpp_name = file_godot_cpp_name .replace ("gen/include/" , "" )
1596- file_godot_cpp_name = file_godot_cpp_name .replace ("include/" , "" )
1597- result .append (f"#include <{ file_godot_cpp_name } >" )
1598- result .append (f"using namespace godot;" )
1599- result .append (f"#endif" )
1600- result .append ("" )
1601- result .append (f"#endif // ! { header_guard } " )
1602- with (Path (output_dir ) / Path (header_filepath )).open ("w+" , encoding = "utf-8" ) as header_file :
1603- header_file .write ("\n " .join (result ))
1593+ else :
1594+ print (f"Marker not found in { file_godot_cpp_name } " )
1595+ with (Path (target_dir ) / Path (file_godot_cpp_name )).open ("w+" , encoding = "utf-8" ) as header_file :
1596+ header_file .write ("" .join (result ))
16041597
16051598
16061599def generate_engine_class_header (class_api , used_classes , fully_used_classes , use_template_get_node ):
0 commit comments