Skip to content

Commit

Permalink
Merge pull request #827 from corco/windows-fix-version
Browse files Browse the repository at this point in the history
Replaced build-version.sh with build-version.py
  • Loading branch information
hzeller authored May 20, 2021
2 parents a35c83f + 0f27aa8 commit c4deacc
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 32 deletions.
6 changes: 3 additions & 3 deletions .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
54 changes: 54 additions & 0 deletions bazel/build-version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/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
"""

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()
27 changes: 0 additions & 27 deletions bazel/build-version.sh

This file was deleted.

2 changes: 1 addition & 1 deletion common/util/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand Down
2 changes: 1 addition & 1 deletion releasing/docker-run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit c4deacc

Please sign in to comment.