platform_builders.py 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. """Functions used to generate source files during build time"""
  2. from pathlib import Path
  3. import methods
  4. def export_icon_builder(target, source, env):
  5. src_path = Path(str(source[0]))
  6. src_name = src_path.stem
  7. platform = src_path.parent.parent.stem
  8. with open(str(source[0]), "r") as file:
  9. svg = file.read()
  10. with methods.generated_wrapper(str(target[0])) as file:
  11. file.write(
  12. f"""\
  13. inline constexpr const char *_{platform}_{src_name}_svg = {methods.to_raw_cstring(svg)};
  14. """
  15. )
  16. def register_platform_apis_builder(target, source, env):
  17. platforms = source[0].read()
  18. api_inc = "\n".join([f'#include "{p}/api/api.h"' for p in platforms])
  19. api_reg = "\n\t".join([f"register_{p}_api();" for p in platforms])
  20. api_unreg = "\n\t".join([f"unregister_{p}_api();" for p in platforms])
  21. with methods.generated_wrapper(str(target[0])) as file:
  22. file.write(
  23. f"""\
  24. #include "register_platform_apis.h"
  25. {api_inc}
  26. void register_platform_apis() {{
  27. {api_reg}
  28. }}
  29. void unregister_platform_apis() {{
  30. {api_unreg}
  31. }}
  32. """
  33. )