From c179a2b45bfc350db0c43dc9b7d2f707e7572080 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Wed, 4 Nov 2020 14:02:08 +1000 Subject: [PATCH] extract version from defs.bzl; gate buildhash on optimized build --- .bazelrc | 2 -- BUILD.bazel | 21 +++++++++++++++++++-- scripts/BUILD.bazel | 7 +++++++ scripts/buildinfo.py | 23 +++++++++++++++++++++++ scripts/status.sh | 7 +------ 5 files changed, 50 insertions(+), 10 deletions(-) create mode 100644 scripts/BUILD.bazel create mode 100644 scripts/buildinfo.py diff --git a/.bazelrc b/.bazelrc index fe585947c..eadbb9fb9 100644 --- a/.bazelrc +++ b/.bazelrc @@ -1,7 +1,5 @@ common --enable_platform_specific_config common --experimental_repository_cache_hardlinks -#common --symlink_prefix=.bazel/ -#common --experimental_no_product_name_out_symlink # specify python path on Windows for pyo3 compile build:windows --action_env="PYTHON_SYS_EXECUTABLE=c:\\python\\python.exe" diff --git a/BUILD.bazel b/BUILD.bazel index f23816c95..41dce3e70 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -1,8 +1,22 @@ +config_setting( + name = "release", + values = { + "compilation_mode": "opt", + }, +) + genrule( - name = "buildinfo_gen", + name = "buildinfo", + srcs = ["//:defs.bzl"], outs = ["buildinfo.txt"], - cmd = "grep STABLE_ bazel-out/stable-status.txt > $@", + cmd = select({ + "release": "$(location //scripts:buildinfo) $(location //:defs.bzl) bazel-out/stable-status.txt release > $@", + "//conditions:default": "$(location //scripts:buildinfo) $(location //:defs.bzl) bazel-out/stable-status.txt devel > $@", + }), stamp = 1, + tools = [ + "//scripts:buildinfo", + ], visibility = ["//visibility:public"], ) @@ -11,3 +25,6 @@ alias( actual = "//ts:tsconfig.json", visibility = ["//visibility:public"], ) + +# for version info +exports_files(["defs.bzl"]) diff --git a/scripts/BUILD.bazel b/scripts/BUILD.bazel new file mode 100644 index 000000000..464420f10 --- /dev/null +++ b/scripts/BUILD.bazel @@ -0,0 +1,7 @@ +py_binary( + name = "buildinfo", + srcs = ["buildinfo.py"], + data = ["//:defs.bzl"], + stamp = 1, + visibility = ["//visibility:public"], +) diff --git a/scripts/buildinfo.py b/scripts/buildinfo.py new file mode 100644 index 000000000..61ee66336 --- /dev/null +++ b/scripts/buildinfo.py @@ -0,0 +1,23 @@ +#!/usr/bin/env python + +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 = "(.*)"') + +# extract version number from defs.bzl +for line in open(defs_file).readlines(): + if ver := version_re.match(line): + print(f"STABLE_VERSION {ver.group(1)}") + +for line in open(stamp_file).readlines(): + if line.startswith("STABLE_BUILDHASH"): + if release_mode: + print(line.strip()) + else: + # if not in release mode, map buildhash to a consistent value + print("STABLE_BUILDHASH dev") diff --git a/scripts/status.sh b/scripts/status.sh index d6aaaab1f..e02172a2a 100755 --- a/scripts/status.sh +++ b/scripts/status.sh @@ -1,8 +1,3 @@ #!/bin/bash -echo "STABLE_VERSION 2.1.36" -if [ "$ANKI_RELEASE" != "" ]; then - echo "STABLE_BUILDHASH $(git rev-parse --short=8 HEAD || echo nogit)" -else - echo "STABLE_BUILDHASH dev" -fi +echo "STABLE_BUILDHASH $(git rev-parse --short=8 HEAD || echo nogit)"