diff options
author | Thaddeus Crews <repiteo@outlook.com> | 2024-05-03 09:44:57 -0500 |
---|---|---|
committer | Thaddeus Crews <repiteo@outlook.com> | 2024-05-07 15:30:45 -0500 |
commit | 34fb3f7730e93120c0f52cc86f314d50fa9d34ed (patch) | |
tree | fb86487c89433bc1b80298937efb6485649a1d3b /platform/SCsub | |
parent | 55b8724bd5188932b69a6ee484ab092cd95d4498 (diff) | |
download | redot-engine-34fb3f7730e93120c0f52cc86f314d50fa9d34ed.tar.gz |
SCons: Generate all scripts natively
Diffstat (limited to 'platform/SCsub')
-rw-r--r-- | platform/SCsub | 65 |
1 files changed, 51 insertions, 14 deletions
diff --git a/platform/SCsub b/platform/SCsub index ca282e3e68..b24c189848 100644 --- a/platform/SCsub +++ b/platform/SCsub @@ -1,27 +1,64 @@ #!/usr/bin/env python import methods +from glob import glob +from pathlib import Path Import("env") env.platform_sources = [] + +# Generate export icons +def export_icon_builder(target, source, env): + src_path = Path(str(source[0])) + src_name = src_path.stem + platform = src_path.parent.parent.stem + with open(str(source[0]), "rb") as file: + svg = "".join([f"\\{hex(x)[1:]}" for x in file.read()]) + with methods.generated_wrapper(target, prefix=platform) as file: + file.write( + f"""\ +static const char *_{platform}_{src_name}_svg = "{svg}"; +""" + ) + + +for platform in env.platform_exporters: + for path in glob(f"{platform}/export/*.svg"): + env.CommandNoCache(path.replace(".svg", "_svg.gen.h"), path, env.Run(export_icon_builder)) + + # Register platform-exclusive APIs -reg_apis_inc = '#include "register_platform_apis.h"\n' -reg_apis = "void register_platform_apis() {\n" -unreg_apis = "void unregister_platform_apis() {\n" +def register_platform_apis_builder(target, source, env): + platforms = source[0].read() + api_inc = "\n".join([f'#include "{p}/api/api.h"' for p in platforms]) + api_reg = "\n".join([f"\tregister_{p}_api();" for p in platforms]) + api_unreg = "\n".join([f"\tunregister_{p}_api();" for p in platforms]) + with methods.generated_wrapper(target) as file: + file.write( + f"""\ +#include "register_platform_apis.h" + +{api_inc} + +void register_platform_apis() {{ +{api_reg} +}} + +void unregister_platform_apis() {{ +{api_unreg} +}} +""" + ) + + +register_platform_apis = env.CommandNoCache( + "register_platform_apis.gen.cpp", env.Value(env.platform_apis), env.Run(register_platform_apis_builder) +) +env.add_source_files(env.platform_sources, register_platform_apis) for platform in env.platform_apis: - platform_dir = env.Dir(platform) - env.add_source_files(env.platform_sources, platform + "/api/api.cpp") - reg_apis += "\tregister_" + platform + "_api();\n" - unreg_apis += "\tunregister_" + platform + "_api();\n" - reg_apis_inc += '#include "' + platform + '/api/api.h"\n' -reg_apis_inc += "\n" -reg_apis += "}\n\n" -unreg_apis += "}\n" - -methods.write_file_if_needed("register_platform_apis.gen.cpp", reg_apis_inc + reg_apis + unreg_apis) -env.add_source_files(env.platform_sources, "register_platform_apis.gen.cpp") + env.add_source_files(env.platform_sources, f"{platform}/api/api.cpp") lib = env.add_library("platform", env.platform_sources) env.Prepend(LIBS=[lib]) |