|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +set -euo pipefail |
| 4 | + |
| 5 | +echo "=== Testing Deterministic Build for Ring Crate ===" |
| 6 | + |
| 7 | +# Define the target to test |
| 8 | +TARGET="@crates//:ring" |
| 9 | +STORE_DIR="./deterministic_test_store" |
| 10 | +BUILD1_DIR="${STORE_DIR}/build1" |
| 11 | +BUILD2_DIR="${STORE_DIR}/build2" |
| 12 | + |
| 13 | +# Clean up any previous test runs |
| 14 | +if [ -d "$STORE_DIR" ]; then |
| 15 | + echo "Cleaning up previous test store..." |
| 16 | + rm -rf "$STORE_DIR" |
| 17 | +fi |
| 18 | + |
| 19 | +# Create directories for storing build outputs |
| 20 | +mkdir -p "$BUILD1_DIR" "$BUILD2_DIR" |
| 21 | + |
| 22 | +echo "--- First Build ---" |
| 23 | +# Build the target |
| 24 | +bazel build --noremote_accept_cached "$TARGET" |
| 25 | + |
| 26 | +# Find and copy the output artifacts |
| 27 | +echo "Copying first build artifacts..." |
| 28 | +BAZEL_BIN=$(bazel info bazel-bin) |
| 29 | +find "$BAZEL_BIN" -name "*ring*" -type f -exec cp {} "$BUILD1_DIR/" \; |
| 30 | + |
| 31 | +# Also get the actual target output specifically |
| 32 | +RING_OUTPUT=$(bazel cquery --output=files "$TARGET" 2>/dev/null) |
| 33 | +if [ -n "$RING_OUTPUT" ]; then |
| 34 | + cp "$RING_OUTPUT" "$BUILD1_DIR/ring_main_output" |
| 35 | +fi |
| 36 | + |
| 37 | +echo "First build artifacts stored in: $BUILD1_DIR" |
| 38 | +ls -la "$BUILD1_DIR" |
| 39 | + |
| 40 | +echo "--- Cleaning Build ---" |
| 41 | +# Clean the build to ensure we're starting fresh |
| 42 | +bazel clean |
| 43 | + |
| 44 | +echo "--- Second Build ---" |
| 45 | +# Build again |
| 46 | +bazel build --noremote_accept_cached "$TARGET" |
| 47 | + |
| 48 | +# Copy second build artifacts |
| 49 | +echo "Copying second build artifacts..." |
| 50 | +BAZEL_BIN=$(bazel info bazel-bin) |
| 51 | +find "$BAZEL_BIN" -name "*ring*" -type f -exec cp {} "$BUILD2_DIR/" \; |
| 52 | + |
| 53 | +# Also get the actual target output specifically |
| 54 | +RING_OUTPUT=$(bazel cquery --output=files "$TARGET" 2>/dev/null) |
| 55 | +if [ -n "$RING_OUTPUT" ]; then |
| 56 | + cp "$RING_OUTPUT" "$BUILD2_DIR/ring_main_output" |
| 57 | +fi |
| 58 | + |
| 59 | +echo "Second build artifacts stored in: $BUILD2_DIR" |
| 60 | +ls -la "$BUILD2_DIR" |
| 61 | + |
| 62 | +echo "--- Comparing Build Outputs ---" |
| 63 | + |
| 64 | +# Compare the directories |
| 65 | +if diff -r "$BUILD1_DIR" "$BUILD2_DIR" > /dev/null; then |
| 66 | + echo "✅ SUCCESS: Builds are deterministic! All artifacts are identical." |
| 67 | + RESULT=0 |
| 68 | +else |
| 69 | + echo "❌ FAILURE: Builds are NOT deterministic. Differences found:" |
| 70 | + echo "" |
| 71 | + diff -r "$BUILD1_DIR" "$BUILD2_DIR" || true |
| 72 | + echo "" |
| 73 | + echo "File hashes comparison:" |
| 74 | + echo "Build 1:" |
| 75 | + find "$BUILD1_DIR" -type f -exec sha256sum {} \; |
| 76 | + echo "" |
| 77 | + echo "Build 2:" |
| 78 | + find "$BUILD2_DIR" -type f -exec sha256sum {} \; |
| 79 | + RESULT=1 |
| 80 | +fi |
| 81 | + |
| 82 | +echo "" |
| 83 | +echo "=== Test Complete ===" |
| 84 | +echo "Build artifacts stored in: $STORE_DIR" |
| 85 | + |
| 86 | +exit $RESULT |
0 commit comments