2020-03-01 23:14:37 +01:00
|
|
|
"""Functions used to generate source files during build time
|
|
|
|
|
|
|
|
All such functions are invoked in a subprocess on Windows to prevent build flakiness.
|
|
|
|
"""
|
|
|
|
|
|
|
|
from platform_methods import subprocess_main
|
|
|
|
from collections import OrderedDict
|
|
|
|
|
|
|
|
|
|
|
|
def make_default_controller_mappings(target, source, env):
|
|
|
|
dst = target[0]
|
|
|
|
g = open(dst, "w")
|
|
|
|
|
|
|
|
g.write("/* THIS FILE IS GENERATED DO NOT EDIT */\n")
|
2020-03-30 08:28:32 +02:00
|
|
|
g.write('#include "core/typedefs.h"\n')
|
|
|
|
g.write('#include "core/input/default_controller_mappings.h"\n')
|
2020-03-01 23:14:37 +01:00
|
|
|
|
|
|
|
# ensure mappings have a consistent order
|
2022-08-23 15:21:46 +02:00
|
|
|
platform_mappings: dict = OrderedDict()
|
2020-03-01 23:14:37 +01:00
|
|
|
for src_path in source:
|
|
|
|
with open(src_path, "r") as f:
|
|
|
|
# read mapping file and skip header
|
|
|
|
mapping_file_lines = f.readlines()[2:]
|
|
|
|
|
|
|
|
current_platform = None
|
|
|
|
for line in mapping_file_lines:
|
|
|
|
if not line:
|
|
|
|
continue
|
|
|
|
line = line.strip()
|
|
|
|
if len(line) == 0:
|
|
|
|
continue
|
|
|
|
if line[0] == "#":
|
|
|
|
current_platform = line[1:].strip()
|
|
|
|
if current_platform not in platform_mappings:
|
|
|
|
platform_mappings[current_platform] = {}
|
|
|
|
elif current_platform:
|
|
|
|
line_parts = line.split(",")
|
|
|
|
guid = line_parts[0]
|
|
|
|
if guid in platform_mappings[current_platform]:
|
2020-03-30 08:28:32 +02:00
|
|
|
g.write(
|
|
|
|
"// WARNING - DATABASE {} OVERWROTE PRIOR MAPPING: {} {}\n".format(
|
|
|
|
src_path, current_platform, platform_mappings[current_platform][guid]
|
|
|
|
)
|
|
|
|
)
|
2020-04-23 11:16:09 +02:00
|
|
|
platform_mappings[current_platform][guid] = line
|
2020-03-01 23:14:37 +01:00
|
|
|
|
|
|
|
platform_variables = {
|
2024-01-17 10:12:44 +01:00
|
|
|
"Linux": "#ifdef LINUXBSD_ENABLED",
|
2020-03-01 23:14:37 +01:00
|
|
|
"Windows": "#ifdef WINDOWS_ENABLED",
|
2022-07-20 08:28:22 +02:00
|
|
|
"Mac OS X": "#ifdef MACOS_ENABLED",
|
2024-01-17 10:12:44 +01:00
|
|
|
"Android": "#ifdef ANDROID_ENABLED",
|
2022-07-20 08:28:22 +02:00
|
|
|
"iOS": "#ifdef IOS_ENABLED",
|
2022-08-28 20:27:45 +02:00
|
|
|
"Web": "#ifdef WEB_ENABLED",
|
2020-03-01 23:14:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
g.write("const char* DefaultControllerMappings::mappings[] = {\n")
|
|
|
|
for platform, mappings in platform_mappings.items():
|
|
|
|
variable = platform_variables[platform]
|
|
|
|
g.write("{}\n".format(variable))
|
|
|
|
for mapping in mappings.values():
|
2020-03-30 08:28:32 +02:00
|
|
|
g.write('\t"{}",\n'.format(mapping))
|
2020-03-01 23:14:37 +01:00
|
|
|
g.write("#endif\n")
|
|
|
|
|
2020-04-02 14:41:58 +02:00
|
|
|
g.write("\tnullptr\n};\n")
|
2020-03-01 23:14:37 +01:00
|
|
|
g.close()
|
|
|
|
|
|
|
|
|
2020-03-30 08:28:32 +02:00
|
|
|
if __name__ == "__main__":
|
2020-03-01 23:14:37 +01:00
|
|
|
subprocess_main(globals())
|