Skip to content

Commit b0bff04

Browse files
authored
Merge pull request #2332 from hzeller/feature-20250118-fallback-module-version
Read version from MODULE.bazel as fallback.
2 parents 85b9f84 + 4a7e73f commit b0bff04

File tree

9 files changed

+77
-77
lines changed

9 files changed

+77
-77
lines changed

.bazelrc

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,7 @@ build --define="absl=1"
77
build --enable_platform_specific_config
88

99
# Gather build version information
10-
build:linux --workspace_status_command="bazel/build-version.py"
11-
build:freebsd --workspace_status_command="bazel/build-version.py"
12-
build:openbsd --workspace_status_command="bazel/build-version.py"
13-
build:macos --workspace_status_command="bazel/build-version.py"
14-
build:windows --workspace_status_command="python bazel/build-version.py"
10+
build --workspace_status_command="bash bazel/build-version.sh"
1511

1612
# Systems with gcc or clang
1713
common:linux --cxxopt=-xc++ --host_cxxopt=-xc++ --cxxopt=-std=c++17 --host_cxxopt=-std=c++17 --client_env=BAZEL_CXXOPTS=-std=c++17

.github/workflows/verible-ci.yml

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,8 @@ jobs:
221221
if: matrix.mode == 'compile' && matrix.arch == 'x86_64'
222222
run: |
223223
bazel build -c fastbuild :install-binaries
224+
# Litmus test
225+
bazel-bin/verible/verilog/tools/syntax/verible-verilog-syntax --version
224226
.github/bin/simple-install.sh $VERIBLE_BINDIR
225227
tar cfv verible-bin.tar -C $VERIBLE_BINDIR .
226228
@@ -331,16 +333,19 @@ jobs:
331333
with:
332334
path: |
333335
/private/var/tmp/_bazel_runner
334-
key: bazelcache_macos1_${{ steps.cache_timestamp.outputs.time }}
335-
restore-keys: bazelcache_macos1_
336+
key: bazelcache_macos_${{ steps.cache_timestamp.outputs.time }}
337+
restore-keys: bazelcache_macos_
336338

337339
- name: Tests
338340
# MacOS has a broken patch utility:
339341
# //verible/verilog/tools/lint:lint-tool_test trips over a no-newline-at-end-of-file
340342
run: bazel test -c opt --noshow_progress --test_output=errors --cxxopt=-Wno-range-loop-analysis -- //... -//verible/verilog/tools/lint:lint-tool_test
341343

342344
- name: Build
343-
run: bazel build -c opt --noshow_progress --test_output=errors --cxxopt=-Wno-range-loop-analysis :install-binaries
345+
run: |
346+
bazel build -c opt --noshow_progress --test_output=errors --cxxopt=-Wno-range-loop-analysis :install-binaries
347+
# Litmus test
348+
bazel-bin/verible/verilog/tools/syntax/verible-verilog-syntax --version
344349
345350
- name: Pack up
346351
run: |
@@ -385,8 +390,8 @@ jobs:
385390
uses: actions/cache@v3
386391
with:
387392
path: "c:/users/runneradmin/_bazel_runneradmin"
388-
key: bazelcache_windows3_${{ steps.cache_timestamp.outputs.time }}
389-
restore-keys: bazelcache_windows3_
393+
key: bazelcache_windows_${{ steps.cache_timestamp.outputs.time }}
394+
restore-keys: bazelcache_windows_
390395

391396
- name: Install dependencies
392397
run: |
@@ -404,7 +409,10 @@ jobs:
404409
run: C:/ProgramData/chocolatey/lib/bazel/bazel.exe test --keep_going --noshow_progress --test_output=errors //...
405410

406411
- name: Build Verible Binaries
407-
run: C:/ProgramData/chocolatey/lib/bazel/bazel.exe build --keep_going --noshow_progress -c opt :install-binaries
412+
run: |
413+
C:/ProgramData/chocolatey/lib/bazel/bazel.exe build --keep_going --noshow_progress -c opt :install-binaries
414+
# Litmus test
415+
bazel-bin/verible/verilog/tools/syntax/verible-verilog-syntax --version
408416
409417
- name: Prepare release
410418
run: |

MODULE.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
module(
22
name = "verible",
3+
version = "head",
34
)
45

56
bazel_dep(name = "platforms", version = "0.0.10")

bazel/build-version.py

Lines changed: 0 additions & 58 deletions
This file was deleted.

bazel/build-version.sh

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/usr/bin/env bash
2+
# Copyright 2020-2025 The Verible Authors.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
# Invoke bazel with --workspace_status_command=bazel/build-version.py to get
17+
# this invoked and populate bazel-out/volatile-status.txt
18+
19+
# Get commit timestamp from git if available, otherwise attempt to get
20+
# from COMMIT_TIMESTAMP or GIT_DATE environment variable.
21+
OUTPUT_COMMIT_TIMESTAMP="$(git log -n1 --format=%cd --date=unix 2>/dev/null)"
22+
if [ -z "${OUTPUT_COMMIT_TIMESTAMP}" ]; then
23+
OUTPUT_COMMIT_TIMESTAMP="${COMMIT_TIMESTAMP}" # from environment
24+
fi
25+
26+
if [ ! -z "${OUTPUT_COMMIT_TIMESTAMP}" ]; then
27+
echo "COMMIT_TIMESTAMP ${OUTPUT_COMMIT_TIMESTAMP}"
28+
elif [ ! -z "${GIT_DATE}" ]; then # legacy environment variable only fallback
29+
echo "GIT_DATE \"${GIT_DATE}\""
30+
fi
31+
32+
OUTPUT_GIT_DESCRIBE="$(git describe 2>/dev/null)"
33+
if [ -z "${OUTPUT_GIT_DESCRIBE}" ]; then
34+
OUTPUT_GIT_DESCRIBE="${GIT_VERSION}"
35+
fi
36+
if [ ! -z "${OUTPUT_GIT_DESCRIBE}" ]; then
37+
echo "GIT_DESCRIBE \"${OUTPUT_GIT_DESCRIBE}\""
38+
fi

shell.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ verible_used_stdenv.mkDerivation {
1818

1919
# For scripts used inside bzl rules and tests
2020
gnused
21-
python3
2221

2322
# To run error-log-analyzer
23+
python3
2424
python3Packages.mdutils
2525
ripgrep
2626

verible/common/util/BUILD

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# 'util' contains generic containers, adapters, algorithms
22
# Any verible package may directly depend on this.
33

4+
load(":module-version.bzl", "get_version_define_from_module")
5+
46
package(
57
default_applicable_licenses = ["//:license"],
68
default_visibility = [
@@ -100,6 +102,7 @@ cc_library(
100102
name = "init-command-line",
101103
srcs = ["init-command-line.cc"],
102104
hdrs = ["init-command-line.h"],
105+
copts = get_version_define_from_module(),
103106
deps = [
104107
# these deps are needed by init_command_line.cc:
105108
":build-version",

verible/common/util/init-command-line.cc

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,21 +36,27 @@ namespace verible {
3636

3737
std::string GetRepositoryVersion() {
3838
#ifdef VERIBLE_GIT_DESCRIBE
39-
return VERIBLE_GIT_DESCRIBE;
39+
return VERIBLE_GIT_DESCRIBE; // from --workspace_status_command
40+
#elif defined(VERIBLE_MODULE_VERSION)
41+
return VERIBLE_MODULE_VERSION; // from MODULE.bazel via module-version.bzl
4042
#else
4143
return "<unknown repository version>";
4244
#endif
4345
}
4446

4547
// Long-form of build version, might contain multiple lines
48+
// Build a version string with as much as possible info.
4649
static std::string GetBuildVersion() {
4750
std::string result;
48-
// Build a version string with as much as possible info.
49-
#ifdef VERIBLE_GIT_DESCRIBE
50-
result.append(VERIBLE_GIT_DESCRIBE).append("\n");
51-
#endif
52-
#ifdef VERIBLE_GIT_DATE
53-
result.append("Commit\t").append(VERIBLE_GIT_DATE).append("\n");
51+
result.append("Version\t").append(GetRepositoryVersion()).append("\n");
52+
#ifdef VERIBLE_COMMIT_TIMESTAMP
53+
result.append("Commit-Timestamp\t")
54+
.append(absl::FormatTime("%Y-%m-%dT%H:%M:%SZ",
55+
absl::FromTimeT(VERIBLE_COMMIT_TIMESTAMP),
56+
absl::UTCTimeZone()))
57+
.append("\n");
58+
#elif defined(VERIBLE_GIT_DATE) // Legacy
59+
result.append("Commit-Date\t").append(VERIBLE_GIT_DATE).append("\n");
5460
#endif
5561
#ifdef VERIBLE_BUILD_TIMESTAMP
5662
result.append("Built\t")
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
def get_version_define_from_module():
2+
module_version = native.module_version()
3+
if module_version:
4+
return ['-DVERIBLE_MODULE_VERSION=\\"{0}\\"'.format(module_version)]
5+
else:
6+
return []

0 commit comments

Comments
 (0)