Maxwell Henderson | 80bec32 | 2024-01-09 15:48:44 -0800 | [diff] [blame^] | 1 | #!/usr/bin/env python3 |
| 2 | |
| 3 | # Copyright (c) FIRST and other WPILib contributors. |
| 4 | # Open Source Software; you can modify and/or share it under the terms of |
| 5 | # the WPILib BSD license file in the root directory of this project. |
| 6 | import pathlib |
| 7 | |
| 8 | |
| 9 | def main(): |
| 10 | # Gets the folder this script is in (the hal/ directory) |
| 11 | HAL_ROOT = pathlib.Path(__file__).parent |
| 12 | java_package = "edu/wpi/first/hal" |
| 13 | (HAL_ROOT/"src/generated/main/native/include/hal").mkdir(parents=True, exist_ok=True) |
| 14 | (HAL_ROOT/f"src/generated/main/java/{java_package}").mkdir(parents=True, exist_ok=True) |
| 15 | usage_reporting_types_cpp = [] |
| 16 | usage_reporting_instances_cpp = [] |
| 17 | usage_reporting_types = [] |
| 18 | usage_reporting_instances = [] |
| 19 | with open(HAL_ROOT/"src/generate/Instances.txt") as instances: |
| 20 | for instance in instances: |
| 21 | usage_reporting_instances_cpp.append(f" {instance.strip()},") |
| 22 | usage_reporting_instances.append( |
| 23 | f" /** {instance.strip()}. */\n" |
| 24 | f" public static final int {instance.strip()};") |
| 25 | |
| 26 | with open(HAL_ROOT/"src/generate/ResourceType.txt") as resource_types: |
| 27 | for resource_type in resource_types: |
| 28 | usage_reporting_types_cpp.append(f" {resource_type.strip()},") |
| 29 | usage_reporting_types.append( |
| 30 | f" /** {resource_type.strip()}. */\n" |
| 31 | f" public static final int {resource_type.strip()};") |
| 32 | |
| 33 | with open(HAL_ROOT/"src/generate/FRCNetComm.java.in") as java_usage_reporting: |
| 34 | contents = (java_usage_reporting.read() |
| 35 | .replace(r"${usage_reporting_types}", "\n".join(usage_reporting_types)) |
| 36 | .replace(r"${usage_reporting_instances}", "\n".join(usage_reporting_instances))) |
| 37 | |
| 38 | with open(HAL_ROOT/f"src/generated/main/java/{java_package}/FRCNetComm.java", "w") as java_out: |
| 39 | java_out.write(contents) |
| 40 | |
| 41 | with open(HAL_ROOT/"src/generate/FRCUsageReporting.h.in") as cpp_usage_reporting: |
| 42 | contents = (cpp_usage_reporting.read() |
| 43 | .replace(r"${usage_reporting_types_cpp}", "\n".join(usage_reporting_types_cpp)) |
| 44 | .replace(r"${usage_reporting_instances_cpp}", "\n".join(usage_reporting_instances_cpp))) |
| 45 | |
| 46 | with open(HAL_ROOT/"src/generated/main/native/include/hal/FRCUsageReporting.h", "w") as cpp_out: |
| 47 | cpp_out.write(contents) |
| 48 | |
| 49 | |
| 50 | if __name__ == "__main__": |
| 51 | main() |