Skip to content

Commit

Permalink
Merge pull request #2332 from hzeller/feature-20250118-fallback-modul…
Browse files Browse the repository at this point in the history
…e-version

Read version from MODULE.bazel as fallback.
  • Loading branch information
hzeller authored Jan 18, 2025
2 parents 85b9f84 + 4a7e73f commit b0bff04
Show file tree
Hide file tree
Showing 9 changed files with 77 additions and 77 deletions.
6 changes: 1 addition & 5 deletions .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,7 @@ build --define="absl=1"
build --enable_platform_specific_config

# Gather build version information
build:linux --workspace_status_command="bazel/build-version.py"
build:freebsd --workspace_status_command="bazel/build-version.py"
build:openbsd --workspace_status_command="bazel/build-version.py"
build:macos --workspace_status_command="bazel/build-version.py"
build:windows --workspace_status_command="python bazel/build-version.py"
build --workspace_status_command="bash bazel/build-version.sh"

# Systems with gcc or clang
common:linux --cxxopt=-xc++ --host_cxxopt=-xc++ --cxxopt=-std=c++17 --host_cxxopt=-std=c++17 --client_env=BAZEL_CXXOPTS=-std=c++17
Expand Down
20 changes: 14 additions & 6 deletions .github/workflows/verible-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,8 @@ jobs:
if: matrix.mode == 'compile' && matrix.arch == 'x86_64'
run: |
bazel build -c fastbuild :install-binaries
# Litmus test
bazel-bin/verible/verilog/tools/syntax/verible-verilog-syntax --version
.github/bin/simple-install.sh $VERIBLE_BINDIR
tar cfv verible-bin.tar -C $VERIBLE_BINDIR .
Expand Down Expand Up @@ -331,16 +333,19 @@ jobs:
with:
path: |
/private/var/tmp/_bazel_runner
key: bazelcache_macos1_${{ steps.cache_timestamp.outputs.time }}
restore-keys: bazelcache_macos1_
key: bazelcache_macos_${{ steps.cache_timestamp.outputs.time }}
restore-keys: bazelcache_macos_

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

- name: Build
run: bazel build -c opt --noshow_progress --test_output=errors --cxxopt=-Wno-range-loop-analysis :install-binaries
run: |
bazel build -c opt --noshow_progress --test_output=errors --cxxopt=-Wno-range-loop-analysis :install-binaries
# Litmus test
bazel-bin/verible/verilog/tools/syntax/verible-verilog-syntax --version
- name: Pack up
run: |
Expand Down Expand Up @@ -385,8 +390,8 @@ jobs:
uses: actions/cache@v3
with:
path: "c:/users/runneradmin/_bazel_runneradmin"
key: bazelcache_windows3_${{ steps.cache_timestamp.outputs.time }}
restore-keys: bazelcache_windows3_
key: bazelcache_windows_${{ steps.cache_timestamp.outputs.time }}
restore-keys: bazelcache_windows_

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

- name: Build Verible Binaries
run: C:/ProgramData/chocolatey/lib/bazel/bazel.exe build --keep_going --noshow_progress -c opt :install-binaries
run: |
C:/ProgramData/chocolatey/lib/bazel/bazel.exe build --keep_going --noshow_progress -c opt :install-binaries
# Litmus test
bazel-bin/verible/verilog/tools/syntax/verible-verilog-syntax --version
- name: Prepare release
run: |
Expand Down
1 change: 1 addition & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
module(
name = "verible",
version = "head",
)

bazel_dep(name = "platforms", version = "0.0.10")
Expand Down
58 changes: 0 additions & 58 deletions bazel/build-version.py

This file was deleted.

38 changes: 38 additions & 0 deletions bazel/build-version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/usr/bin/env bash
# Copyright 2020-2025 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

# Get commit timestamp from git if available, otherwise attempt to get
# from COMMIT_TIMESTAMP or GIT_DATE environment variable.
OUTPUT_COMMIT_TIMESTAMP="$(git log -n1 --format=%cd --date=unix 2>/dev/null)"
if [ -z "${OUTPUT_COMMIT_TIMESTAMP}" ]; then
OUTPUT_COMMIT_TIMESTAMP="${COMMIT_TIMESTAMP}" # from environment
fi

if [ ! -z "${OUTPUT_COMMIT_TIMESTAMP}" ]; then
echo "COMMIT_TIMESTAMP ${OUTPUT_COMMIT_TIMESTAMP}"
elif [ ! -z "${GIT_DATE}" ]; then # legacy environment variable only fallback
echo "GIT_DATE \"${GIT_DATE}\""
fi

OUTPUT_GIT_DESCRIBE="$(git describe 2>/dev/null)"
if [ -z "${OUTPUT_GIT_DESCRIBE}" ]; then
OUTPUT_GIT_DESCRIBE="${GIT_VERSION}"
fi
if [ ! -z "${OUTPUT_GIT_DESCRIBE}" ]; then
echo "GIT_DESCRIBE \"${OUTPUT_GIT_DESCRIBE}\""
fi
2 changes: 1 addition & 1 deletion shell.nix
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ verible_used_stdenv.mkDerivation {

# For scripts used inside bzl rules and tests
gnused
python3

# To run error-log-analyzer
python3
python3Packages.mdutils
ripgrep

Expand Down
3 changes: 3 additions & 0 deletions verible/common/util/BUILD
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# 'util' contains generic containers, adapters, algorithms
# Any verible package may directly depend on this.

load(":module-version.bzl", "get_version_define_from_module")

package(
default_applicable_licenses = ["//:license"],
default_visibility = [
Expand Down Expand Up @@ -100,6 +102,7 @@ cc_library(
name = "init-command-line",
srcs = ["init-command-line.cc"],
hdrs = ["init-command-line.h"],
copts = get_version_define_from_module(),
deps = [
# these deps are needed by init_command_line.cc:
":build-version",
Expand Down
20 changes: 13 additions & 7 deletions verible/common/util/init-command-line.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,21 +36,27 @@ namespace verible {

std::string GetRepositoryVersion() {
#ifdef VERIBLE_GIT_DESCRIBE
return VERIBLE_GIT_DESCRIBE;
return VERIBLE_GIT_DESCRIBE; // from --workspace_status_command
#elif defined(VERIBLE_MODULE_VERSION)
return VERIBLE_MODULE_VERSION; // from MODULE.bazel via module-version.bzl
#else
return "<unknown repository version>";
#endif
}

// Long-form of build version, might contain multiple lines
// Build a version string with as much as possible info.
static std::string GetBuildVersion() {
std::string result;
// Build a version string with as much as possible info.
#ifdef VERIBLE_GIT_DESCRIBE
result.append(VERIBLE_GIT_DESCRIBE).append("\n");
#endif
#ifdef VERIBLE_GIT_DATE
result.append("Commit\t").append(VERIBLE_GIT_DATE).append("\n");
result.append("Version\t").append(GetRepositoryVersion()).append("\n");
#ifdef VERIBLE_COMMIT_TIMESTAMP
result.append("Commit-Timestamp\t")
.append(absl::FormatTime("%Y-%m-%dT%H:%M:%SZ",
absl::FromTimeT(VERIBLE_COMMIT_TIMESTAMP),
absl::UTCTimeZone()))
.append("\n");
#elif defined(VERIBLE_GIT_DATE) // Legacy
result.append("Commit-Date\t").append(VERIBLE_GIT_DATE).append("\n");
#endif
#ifdef VERIBLE_BUILD_TIMESTAMP
result.append("Built\t")
Expand Down
6 changes: 6 additions & 0 deletions verible/common/util/module-version.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
def get_version_define_from_module():
module_version = native.module_version()
if module_version:
return ['-DVERIBLE_MODULE_VERSION=\\"{0}\\"'.format(module_version)]
else:
return []

0 comments on commit b0bff04

Please sign in to comment.