From b8ab8ae4e2f1b59fb318a60b5cd38ed8373a240a Mon Sep 17 00:00:00 2001 From: Jonathan Drolet Date: Wed, 19 May 2021 21:17:22 -0400 Subject: [PATCH 1/2] Replaced build-version.sh with build-version.py --- .bazelrc | 6 +++--- bazel/build-version.py | 41 +++++++++++++++++++++++++++++++++++++++++ bazel/build-version.sh | 27 --------------------------- common/util/BUILD | 2 +- releasing/docker-run.sh | 2 +- 5 files changed, 46 insertions(+), 32 deletions(-) create mode 100755 bazel/build-version.py delete mode 100755 bazel/build-version.sh diff --git a/.bazelrc b/.bazelrc index b3ba09e01..a83c44119 100644 --- a/.bazelrc +++ b/.bazelrc @@ -5,9 +5,9 @@ test --define="absl=1" # Cannot use 'common' because 'bazel version' fails with this. # Gather build version information -build --workspace_status_command=bazel/build-version.sh -run --workspace_status_command=bazel/build-version.sh -test --workspace_status_command=bazel/build-version.sh +build --workspace_status_command=bazel/build-version.py +run --workspace_status_command=bazel/build-version.py +test --workspace_status_command=bazel/build-version.py build --enable_platform_specific_config diff --git a/bazel/build-version.py b/bazel/build-version.py new file mode 100755 index 000000000..e1340a05e --- /dev/null +++ b/bazel/build-version.py @@ -0,0 +1,41 @@ +#!/usr/bin/env python3 +""" +Invoke bazel with --workspace_status_command=bazel/build-version.py to +get this invoked and populate bazel-out/volatile-status.txt +""" + +import os + +from subprocess import Popen, PIPE + + +def run(*cmd): + process = Popen(cmd, stdout=PIPE) + output, _ = process.communicate() + + return output.strip().decode() + + +def main(): + try: + date = run("git", "log", "-n1", "--date=short", "--format=%cd") + except: + date = "" + + try: + version = run("git", "describe") + except: + version = "" + + if not date: + date = os.environ["GIT_DATE"] + + if not version: + version = os.environ["GIT_VERSION"] + + print("GIT_DATE", '"{}"'.format(date)) + print("GIT_DESCRIBE", '"{}"'.format(version)) + + +if __name__ == "__main__": + main() diff --git a/bazel/build-version.sh b/bazel/build-version.sh deleted file mode 100755 index 1a50193dd..000000000 --- a/bazel/build-version.sh +++ /dev/null @@ -1,27 +0,0 @@ -#!/bin/bash -# Copyright 2020 The Verible Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Invoke bazel with --workspace_status_command=bazel/build-version.sh to -# get this invoked and populate bazel-out/volatile-status.sh -LOCAL_GIT_DATE="$(git log -n1 --date=short --format='%cd' 2>/dev/null)" -LOCAL_GIT_VERSION="$(git describe 2>/dev/null)" - -# If we get these values above, overwrite potentially set environment variables. -test -z "$LOCAL_GIT_DATE" || GIT_DATE="$LOCAL_GIT_DATE" -test -z "$LOCAL_GIT_VERSION" || GIT_VERSION="$LOCAL_GIT_VERSION" - -test -z "$GIT_DATE" || echo "GIT_DATE \"$GIT_DATE\"" -test -z "$GIT_VERSION" || echo "GIT_DESCRIBE \"$GIT_VERSION\"" - diff --git a/common/util/BUILD b/common/util/BUILD index 5e0860dd1..a967e7bcd 100644 --- a/common/util/BUILD +++ b/common/util/BUILD @@ -70,7 +70,7 @@ cc_library( # offers. # https://docs.bazel.build/versions/master/user-manual.html#workspace_status # to contain a proper git timestamp, bazel has to be invoked with -# bazel build --workspace_status_command=bazel/build-version.sh +# bazel build --workspace_status_command=bazel/build-version.py genrule( name = "version_header", outs = ["generated_verible_build_version.h"], diff --git a/releasing/docker-run.sh b/releasing/docker-run.sh index ae3029c63..72be66ab0 100755 --- a/releasing/docker-run.sh +++ b/releasing/docker-run.sh @@ -100,7 +100,7 @@ RUN bazel --version ADD verible-$GIT_VERSION.tar.gz /src/verible WORKDIR /src/verible/verible-$GIT_VERSION -RUN bazel build --workspace_status_command=bazel/build-version.sh $BAZEL_OPTS //... +RUN bazel build --workspace_status_command=bazel/build-version.py $BAZEL_OPTS //... EOF (cd .. ; git archive --prefix verible-$GIT_VERSION/ --output releasing/$TARGET/verible-$GIT_VERSION.tar.gz HEAD) From 0f27aa8d881ce4562716f1ead94923988952352b Mon Sep 17 00:00:00 2001 From: Jonathan Drolet Date: Wed, 19 May 2021 22:15:52 -0400 Subject: [PATCH 2/2] Added missing license header in build-version.py --- bazel/build-version.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/bazel/build-version.py b/bazel/build-version.py index e1340a05e..efcd3c53f 100755 --- a/bazel/build-version.py +++ b/bazel/build-version.py @@ -1,4 +1,17 @@ #!/usr/bin/env python3 +# Copyright 2020-2021 The Verible Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. """ Invoke bazel with --workspace_status_command=bazel/build-version.py to get this invoked and populate bazel-out/volatile-status.txt