input_builders.py 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. """Functions used to generate source files during build time"""
  2. from collections import OrderedDict
  3. import methods
  4. def make_default_controller_mappings(target, source, env):
  5. with methods.generated_wrapper(str(target[0])) as file:
  6. file.write("""\
  7. #include "core/input/default_controller_mappings.h"
  8. #include "core/typedefs.h"
  9. """)
  10. # ensure mappings have a consistent order
  11. platform_mappings = OrderedDict()
  12. for src_path in map(str, source):
  13. with open(src_path, "r", encoding="utf-8") as f:
  14. # read mapping file and skip header
  15. mapping_file_lines = f.readlines()[2:]
  16. current_platform = None
  17. for line in mapping_file_lines:
  18. if not line:
  19. continue
  20. line = line.strip()
  21. if len(line) == 0:
  22. continue
  23. if line[0] == "#":
  24. current_platform = line[1:].strip()
  25. if current_platform not in platform_mappings:
  26. platform_mappings[current_platform] = {}
  27. elif current_platform:
  28. line_parts = line.split(",")
  29. guid = line_parts[0]
  30. if guid in platform_mappings[current_platform]:
  31. file.write(
  32. "// WARNING: DATABASE {} OVERWROTE PRIOR MAPPING: {} {}\n".format(
  33. src_path, current_platform, platform_mappings[current_platform][guid]
  34. )
  35. )
  36. platform_mappings[current_platform][guid] = line
  37. PLATFORM_VARIABLES = {
  38. "Linux": "LINUXBSD",
  39. "Windows": "WINDOWS",
  40. "Mac OS X": "MACOS",
  41. "Android": "ANDROID",
  42. "iOS": "APPLE_EMBEDDED",
  43. "Web": "WEB",
  44. }
  45. file.write("const char *DefaultControllerMappings::mappings[] = {\n")
  46. for platform, mappings in platform_mappings.items():
  47. variable = PLATFORM_VARIABLES[platform]
  48. file.write(f"#ifdef {variable}_ENABLED\n")
  49. for mapping in mappings.values():
  50. file.write(f'\t"{mapping}",\n')
  51. file.write(f"#endif // {variable}_ENABLED\n")
  52. file.write("\tnullptr\n};\n")