2024-10-02 10:19:36 +02:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
import argparse
|
|
|
|
from pathlib import Path
|
|
|
|
|
2024-10-02 10:23:23 +02:00
|
|
|
from shared.versioning import generate_version
|
2024-10-02 10:19:36 +02:00
|
|
|
|
|
|
|
TEMPLATE = """
|
2025-01-06 20:57:25 +01:00
|
|
|
const char *g_TRXVersion = "TR2X {version}";
|
2024-10-02 10:19:36 +02:00
|
|
|
""".lstrip()
|
|
|
|
|
|
|
|
|
|
|
|
def parse_args() -> argparse.Namespace:
|
|
|
|
parser = argparse.ArgumentParser()
|
|
|
|
parser.add_argument("-o", "--output", type=Path)
|
|
|
|
return parser.parse_args()
|
|
|
|
|
|
|
|
|
|
|
|
def get_init_c() -> str:
|
2024-10-02 10:23:23 +02:00
|
|
|
return TEMPLATE.format(version=generate_version(2))
|
2024-10-02 10:19:36 +02:00
|
|
|
|
|
|
|
|
|
|
|
def update_init_c(output_path: Path) -> None:
|
|
|
|
new_text = get_init_c()
|
|
|
|
if not output_path.exists() or output_path.read_text() != new_text:
|
|
|
|
output_path.write_text(new_text)
|
|
|
|
|
|
|
|
|
|
|
|
def main() -> None:
|
|
|
|
args = parse_args()
|
|
|
|
if args.output:
|
|
|
|
update_init_c(output_path=args.output)
|
|
|
|
else:
|
2024-10-02 10:23:23 +02:00
|
|
|
print(get_init_c(), end="")
|
2024-10-02 10:19:36 +02:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|