[Scons] Use builder to track bindings regeneration.

Using a scons Builder we now regenerate the bindings automatically
when the Godot API json or header has changed.

The option to force bindings regeneration (generate_bindings=yes) is
retained.
This commit is contained in:
Fabio Alessandrelli
2022-04-30 15:49:51 +02:00
parent 1ad24f1d5d
commit fa698ddd12
2 changed files with 40 additions and 38 deletions

View File

@@ -6,9 +6,9 @@ import shutil
from pathlib import Path
def print_file_list(api_filepath, output_dir, headers=False, sources=False):
def get_file_list(api_filepath, output_dir, headers=False, sources=False):
api = {}
end = ";"
files = []
with open(api_filepath) as api_file:
api = json.load(api_file)
@@ -25,9 +25,9 @@ def print_file_list(api_filepath, output_dir, headers=False, sources=False):
header_filename = include_gen_folder / "variant" / (camel_to_snake(builtin_class["name"]) + ".hpp")
source_filename = source_gen_folder / "variant" / (camel_to_snake(builtin_class["name"]) + ".cpp")
if headers:
print(str(header_filename.as_posix()), end=end)
files.append(str(header_filename.as_posix()))
if sources:
print(str(source_filename.as_posix()), end=end)
files.append(str(source_filename.as_posix()))
for engine_class in api["classes"]:
# TODO: Properly setup this singleton since it conflicts with ClassDB in the bindings.
@@ -36,18 +36,36 @@ def print_file_list(api_filepath, output_dir, headers=False, sources=False):
header_filename = include_gen_folder / "classes" / (camel_to_snake(engine_class["name"]) + ".hpp")
source_filename = source_gen_folder / "classes" / (camel_to_snake(engine_class["name"]) + ".cpp")
if headers:
print(str(header_filename.as_posix()), end=end)
files.append(str(header_filename.as_posix()))
if sources:
print(str(source_filename.as_posix()), end=end)
files.append(str(source_filename.as_posix()))
utility_functions_header_path = include_gen_folder / "variant" / "utility_functions.hpp"
utility_functions_source_path = source_gen_folder / "variant" / "utility_functions.cpp"
global_constants_header_path = include_gen_folder / "classes" / "global_constants.hpp"
if headers:
print(str(utility_functions_header_path.as_posix()), end=end)
print(str(global_constants_header_path.as_posix()), end=end)
files.append(str(utility_functions_header_path.as_posix()))
files.append(str(global_constants_header_path.as_posix()))
if sources:
print(str(utility_functions_source_path.as_posix()), end=end)
files.append(str(utility_functions_source_path.as_posix()))
return files
def print_file_list(api_filepath, output_dir, headers=False, sources=False):
end = ";"
for f in get_file_list(api_filepath, output_dir, headers, sources):
print(f, end=end)
def scons_emit_files(target, source, env):
files = [env.File(f) for f in get_file_list(str(source[0]), target[0].abspath, True, True)]
env.Clean(files, target)
return [target[0]] + files, source
def scons_generate_bindings(target, source, env):
generate_bindings(str(source[0]), env["generate_template_get_node"], target[0].abspath)
return None
def generate_bindings(api_filepath, use_template_get_node, output_dir="."):