main_builders.py 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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 compat import byte_to_str
  6. from collections import OrderedDict
  7. def make_splash(target, source, env):
  8. src = source[0]
  9. dst = target[0]
  10. with open(src, "rb") as f:
  11. buf = f.read()
  12. with open(dst, "w") as g:
  13. g.write("/* THIS FILE IS GENERATED DO NOT EDIT */\n")
  14. g.write("#ifndef BOOT_SPLASH_H\n")
  15. g.write("#define BOOT_SPLASH_H\n")
  16. # Use a neutral gray color to better fit various kinds of projects.
  17. g.write("static const Color boot_splash_bg_color = Color(0.14, 0.14, 0.14);\n")
  18. g.write("static const unsigned char boot_splash_png[] = {\n")
  19. for i in range(len(buf)):
  20. g.write(byte_to_str(buf[i]) + ",\n")
  21. g.write("};\n")
  22. g.write("#endif")
  23. def make_splash_editor(target, source, env):
  24. src = source[0]
  25. dst = target[0]
  26. with open(src, "rb") as f:
  27. buf = f.read()
  28. with open(dst, "w") as g:
  29. g.write("/* THIS FILE IS GENERATED DO NOT EDIT */\n")
  30. g.write("#ifndef BOOT_SPLASH_EDITOR_H\n")
  31. g.write("#define BOOT_SPLASH_EDITOR_H\n")
  32. # The editor splash background color is taken from the default editor theme's background color.
  33. # This helps achieve a visually "smoother" transition between the splash screen and the editor.
  34. g.write("static const Color boot_splash_editor_bg_color = Color(0.125, 0.145, 0.192);\n")
  35. g.write("static const unsigned char boot_splash_editor_png[] = {\n")
  36. for i in range(len(buf)):
  37. g.write(byte_to_str(buf[i]) + ",\n")
  38. g.write("};\n")
  39. g.write("#endif")
  40. def make_app_icon(target, source, env):
  41. src = source[0]
  42. dst = target[0]
  43. with open(src, "rb") as f:
  44. buf = f.read()
  45. with open(dst, "w") as g:
  46. g.write("/* THIS FILE IS GENERATED DO NOT EDIT */\n")
  47. g.write("#ifndef APP_ICON_H\n")
  48. g.write("#define APP_ICON_H\n")
  49. g.write("static const unsigned char app_icon_png[] = {\n")
  50. for i in range(len(buf)):
  51. g.write(byte_to_str(buf[i]) + ",\n")
  52. g.write("};\n")
  53. g.write("#endif")
  54. def make_default_controller_mappings(target, source, env):
  55. dst = target[0]
  56. g = open(dst, "w")
  57. g.write("/* THIS FILE IS GENERATED DO NOT EDIT */\n")
  58. g.write('#include "core/typedefs.h"\n')
  59. g.write('#include "main/default_controller_mappings.h"\n')
  60. # ensure mappings have a consistent order
  61. platform_mappings = OrderedDict()
  62. for src_path in source:
  63. with open(src_path, "r") as f:
  64. # read mapping file and skip header
  65. mapping_file_lines = f.readlines()[2:]
  66. current_platform = None
  67. for line in mapping_file_lines:
  68. if not line:
  69. continue
  70. line = line.strip()
  71. if len(line) == 0:
  72. continue
  73. if line[0] == "#":
  74. current_platform = line[1:].strip()
  75. if current_platform not in platform_mappings:
  76. platform_mappings[current_platform] = {}
  77. elif current_platform:
  78. line_parts = line.split(",")
  79. guid = line_parts[0]
  80. if guid in platform_mappings[current_platform]:
  81. g.write(
  82. "// WARNING - DATABASE {} OVERWROTE PRIOR MAPPING: {} {}\n".format(
  83. src_path, current_platform, platform_mappings[current_platform][guid]
  84. )
  85. )
  86. platform_mappings[current_platform][guid] = line
  87. platform_variables = {
  88. "Linux": "#if X11_ENABLED",
  89. "Windows": "#ifdef WINDOWS_ENABLED",
  90. "Mac OS X": "#ifdef OSX_ENABLED",
  91. "Android": "#if defined(__ANDROID__)",
  92. "iOS": "#ifdef IPHONE_ENABLED",
  93. "Javascript": "#ifdef JAVASCRIPT_ENABLED",
  94. "UWP": "#ifdef UWP_ENABLED",
  95. }
  96. g.write("const char* DefaultControllerMappings::mappings[] = {\n")
  97. for platform, mappings in platform_mappings.items():
  98. variable = platform_variables[platform]
  99. g.write("{}\n".format(variable))
  100. for mapping in mappings.values():
  101. g.write('\t"{}",\n'.format(mapping))
  102. g.write("#endif\n")
  103. g.write("\tNULL\n};\n")
  104. g.close()
  105. if __name__ == "__main__":
  106. subprocess_main(globals())