anki/tools/buildinfo.py

32 lines
911 B
Python
Raw Normal View History

#!/usr/bin/env python
2021-04-13 10:45:05 +02:00
# Copyright: Ankitects Pty Ltd and contributors
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
import re
import sys
defs_file = sys.argv[1]
stamp_file = sys.argv[2]
release_mode = sys.argv[3] == "release"
version_re = re.compile('anki_version = "(.*)"')
2021-04-13 10:45:05 +02:00
2020-11-05 02:21:27 +01:00
def output(text: str) -> None:
"Add text with a '\n' to stdout; avoiding a '\r' on Windows"
sys.stdout.buffer.write(text.encode("utf8") + b"\n")
2021-04-13 10:45:05 +02:00
# extract version number from defs.bzl
for line in open(defs_file).readlines():
if ver := version_re.match(line):
2020-11-05 02:21:27 +01:00
output(f"STABLE_VERSION {ver.group(1)}")
for line in open(stamp_file).readlines():
if line.startswith("STABLE_BUILDHASH"):
if release_mode:
2020-11-05 02:21:27 +01:00
output(line.strip())
else:
# if not in release mode, map buildhash to a consistent value
2020-11-05 02:21:27 +01:00
output("STABLE_BUILDHASH dev")