Created
March 6, 2026 14:37
-
-
Save nmattia/dc8a1d4f3bc36c9c0133d15f06acc74e to your computer and use it in GitHub Desktop.
Hunt down bazel build reproducibility issues
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| # usage: ./hunt //my-target [n_runs] | |
| set -euo pipefail | |
| filter='map | |
| (reduce . as $target | |
| ([]; . + | |
| $target.actualOutputs | |
| ) | |
| ) | flatten' | |
| target="$1" | |
| n_runs="${2:-2}" | |
| run_build() { | |
| local run_n="$1" | |
| echo "$(date) Running build $run_n/$n_runs" | |
| output_base="$PWD/,output-base-$run_n" | |
| for i in $(seq 1 "$run_n"); do | |
| output_base="$output_base/nest-$i" | |
| done | |
| echo "using output base '$output_base'" | |
| rm -rf "$output_base" | |
| # add extra startup_options if necessary | |
| startup_options=( --output_base="$output_base" ) | |
| mkdir -p target # arbitrary dir where execlogs should be placed | |
| bazel \ | |
| "${startup_options[@]}" | |
| build \ | |
| "--execution_log_json_file=target/exec$run_n.json" \ | |
| "$target" | |
| } | |
| compare_runs() { | |
| local run_a="$1" | |
| local run_b="$2" | |
| res=$(jq --slurp '(.[0] - .[1])' \ | |
| <(jq -Mr <"target/exec$run_a.json" --slurp "$filter") \ | |
| <(jq -Mr <"target/exec$run_b.json" --slurp "$filter") | |
| ) | |
| if [ "$res" != "[]" ]; then | |
| echo "$(date) mismatch" | |
| echo "$res" | |
| exit 1 | |
| fi | |
| echo "$(date) builds $run_a - $run_b: no diff 👌" | |
| } | |
| for run_n in $(seq 1 "$n_runs"); do | |
| run_build "$run_n" | |
| if [[ $run_n != "1" ]]; then | |
| compare_runs "1" "$run_n" | |
| fi | |
| done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment