input_builders.py 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. """Functions used to generate source files during build time
  2. All such functions are invoked in a subprocess on Windows to prevent build flakiness.
  3. """
  4. from platform_methods import subprocess_main
  5. from collections import OrderedDict
  6. def make_default_controller_mappings(target, source, env):
  7. dst = target[0]
  8. g = open(dst, "w")
  9. g.write("/* THIS FILE IS GENERATED DO NOT EDIT */\n")
  10. g.write('#include "core/typedefs.h"\n')
  11. g.write('#include "core/input/default_controller_mappings.h"\n')
  12. # ensure mappings have a consistent order
  13. platform_mappings: dict = OrderedDict()
  14. for src_path in source:
  15. with open(src_path, "r") as f:
  16. # read mapping file and skip header
  17. mapping_file_lines = f.readlines()[2:]
  18. current_platform = None
  19. for line in mapping_file_lines:
  20. if not line:
  21. continue
  22. line = line.strip()
  23. if len(line) == 0:
  24. continue
  25. if line[0] == "#":
  26. current_platform = line[1:].strip()
  27. if current_platform not in platform_mappings:
  28. platform_mappings[current_platform] = {}
  29. elif current_platform:
  30. line_parts = line.split(",")
  31. guid = line_parts[0]
  32. if guid in platform_mappings[current_platform]:
  33. g.write(
  34. "// WARNING - DATABASE {} OVERWROTE PRIOR MAPPING: {} {}\n".format(
  35. src_path, current_platform, platform_mappings[current_platform][guid]
  36. )
  37. )
  38. platform_mappings[current_platform][guid] = line
  39. platform_variables = {
  40. "Linux": "#if LINUXBSD_ENABLED",
  41. "Windows": "#ifdef WINDOWS_ENABLED",
  42. "Mac OS X": "#ifdef MACOS_ENABLED",
  43. "Android": "#if defined(__ANDROID__)",
  44. "iOS": "#ifdef IOS_ENABLED",
  45. "Web": "#ifdef WEB_ENABLED",
  46. "UWP": "#ifdef UWP_ENABLED",
  47. }
  48. g.write("const char* DefaultControllerMappings::mappings[] = {\n")
  49. for platform, mappings in platform_mappings.items():
  50. variable = platform_variables[platform]
  51. g.write("{}\n".format(variable))
  52. for mapping in mappings.values():
  53. g.write('\t"{}",\n'.format(mapping))
  54. g.write("#endif\n")
  55. g.write("\tnullptr\n};\n")
  56. g.close()
  57. if __name__ == "__main__":
  58. subprocess_main(globals())