Skip to content

Commit

Permalink
fix (build): Fix (hopefully) the root cause of too frequent Bazel reb…
Browse files Browse the repository at this point in the history
…uilds
  • Loading branch information
vorburger committed Jan 19, 2025
1 parent 8d0fa86 commit 125abe0
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions tools/version/version.bash
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,19 @@ set -euo pipefail

# Inspired e.g. by https://github.com/palantir/gradle-git-version

git describe --tags --always --first-parent >tools/version/VERSION
truncate -s -1 tools/version/VERSION
# It's *VERY* important that this script *ONLY* touches the tools/version/VERSION file
# when its content actually changed. This is otherwise it triggers a frequent full rebuild.
# This is because Bazel (also?) looks at the timestamp of the file to determine if it needs
# to rebuild, not ([only?] a hash of) its content.

if ! git update-index --refresh >/dev/null; then
echo -n ".dirty" >>tools/version/VERSION
NEW_VERSION=$(git describe --tags --always --first-parent)
NEW_VERSION=${NEW_VERSION%$'\n'}

# Skip this, because it still causes too frequent rebuilds during development while commiting
# if ! git update-index --refresh >/dev/null; then
# NEW_VERSION="${NEW_VERSION}.dirty"
# fi

if [ ! -f tools/version/VERSION ] || [ "$(cat tools/version/VERSION)" != "$NEW_VERSION" ]; then
echo -n "$NEW_VERSION" > tools/version/VERSION
fi

0 comments on commit 125abe0

Please sign in to comment.