Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ single_version_override(
version = "9.3.0",
)

bazel_dep(name = "rules_jvm_external", version = "6.9")
single_version_override(
module_name = "rules_jvm_external",
version = "6.9",
)

bazel_dep(name = "rules_proto", version = "6.0.0")
single_version_override(
module_name = "rules_proto",
Expand Down Expand Up @@ -306,3 +312,4 @@ use_repo(

bazel_dep(name = "rules_python", version = "1.7.0", dev_dependency = True)
bazel_dep(name = "rules_shell", version = "0.6.1", dev_dependency = True)
bazel_dep(name = "aspect_bazel_lib", version = "2.22.0", dev_dependency = True)
390 changes: 385 additions & 5 deletions MODULE.bazel.lock

Large diffs are not rendered by default.

22 changes: 22 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -152,3 +152,25 @@ load(
rules_shell_dependencies()

rules_shell_toolchains()

http_archive(
name = "aspect_bazel_lib",
sha256 = "0019dfc4b32d63c1392aa264aed2253c1e0c2fb09216f8e2cc269bbfb8bb49b5",
urls = [
"https://mirror.bazel.build/github.com/bazelbuild/aspect_bazel_lib/releases/download/2.22.0/aspect_bazel_lib-2.22.0.tar.gz",
"https://github.com/bazelbuild/aspect_bazel_lib/releases/download/2.22.0/aspect_bazel_lib-2.22.0.tar.gz",
],
)

load("@aspect_bazel_lib//lib:repositories.bzl", "aspect_bazel_lib_dependencies", "aspect_bazel_lib_register_toolchains")

aspect_bazel_lib_dependencies()

aspect_bazel_lib_register_toolchains()

load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")

maybe(
host_platform_repo,
name = "host_platform",
)
125 changes: 125 additions & 0 deletions analyze_docs_jar_nondeterminism.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
#!/usr/bin/env bash
#
# Script to analyze non-determinism in -docs.jar files generated by maven_export
# Run from the rules_scala root directory
#

set -e

TARGET="//test/scala_export:external_dep-docs"
JAR_PATH="bazel-bin/test/scala_export/external_dep-docs.jar"

echo "=== Analyzing non-determinism in $TARGET ==="
echo ""

# Create temp directories for extraction
DIR1=$(mktemp -d -t docs_jar_build1-XXXXXXXXXX)
DIR2=$(mktemp -d -t docs_jar_build2-XXXXXXXXXX)
CACHE1=$(mktemp -d -t cache1-XXXXXXXXXX)
CACHE2=$(mktemp -d -t cache2-XXXXXXXXXX)

cleanup() {
rm -rf "$DIR1" "$DIR2" "$CACHE1" "$CACHE2"
}
trap cleanup EXIT

echo ">>> Build 1"
bazel clean 2>/dev/null
bazel build --disk_cache="$CACHE1" "$TARGET" 2>/dev/null
cat "$JAR_PATH" > "$DIR1/docs.jar"
(cd "$DIR1" && unzip -o -q docs.jar && rm docs.jar)

echo ">>> Build 2 (after clean and sleep)"
bazel clean 2>/dev/null
sleep 5 # Ensure different timestamps
bazel build --disk_cache="$CACHE2" "$TARGET" 2>/dev/null
cat "$JAR_PATH" > "$DIR2/docs.jar"
(cd "$DIR2" && unzip -o -q docs.jar && rm docs.jar)

echo ""
echo "=== Comparing jar contents ==="
echo ""

# Compare file lists
echo "--- Files only in build 1:"
diff <(cd "$DIR1" && find . -type f | sort) <(cd "$DIR2" && find . -type f | sort) | grep "^<" || echo "(none)"

echo ""
echo "--- Files only in build 2:"
diff <(cd "$DIR1" && find . -type f | sort) <(cd "$DIR2" && find . -type f | sort) | grep "^>" || echo "(none)"

echo ""
echo "--- Files with different content:"
DIFF_FILES=()
while IFS= read -r file; do
if [ -f "$DIR1/$file" ] && [ -f "$DIR2/$file" ]; then
if ! cmp -s "$DIR1/$file" "$DIR2/$file"; then
DIFF_FILES+=("$file")
echo " $file"
fi
fi
done < <(cd "$DIR1" && find . -type f | sort)

echo ""
echo "=== Showing differences in changed files ==="
echo ""

for file in "${DIFF_FILES[@]}"; do
echo ">>> Diff for: $file"
echo "-------------------------------------------"

if [[ "$file" == *.zip ]]; then
# These are zip files - extract and compare
ZIPDIR1=$(mktemp -d)
ZIPDIR2=$(mktemp -d)

# Extract zip contents
unzip -o -q "$DIR1/$file" -d "$ZIPDIR1" 2>/dev/null || true
unzip -o -q "$DIR2/$file" -d "$ZIPDIR2" 2>/dev/null || true

# List what we extracted
echo " Extracted files from zip:"
(cd "$ZIPDIR1" && find . -type f) || true

# Compare extracted contents
found_diff=false
for zfile in $(cd "$ZIPDIR1" && find . -type f 2>/dev/null); do
if [ -f "$ZIPDIR1/$zfile" ] && [ -f "$ZIPDIR2/$zfile" ]; then
if ! cmp -s "$ZIPDIR1/$zfile" "$ZIPDIR2/$zfile"; then
found_diff=true
echo ""
echo " Difference in: $zfile"
diff "$ZIPDIR1/$zfile" "$ZIPDIR2/$zfile" | head -30 || true
fi
fi
done

if [ "$found_diff" = false ]; then
# Maybe the zip metadata differs, not content
echo " (zip file metadata differs, not content - showing hexdump diff)"
diff <(xxd "$DIR1/$file" | head -20) <(xxd "$DIR2/$file" | head -20) || true
fi

rm -rf "$ZIPDIR1" "$ZIPDIR2"
elif [[ "$file" == *.html ]] || [[ "$file" == *.js ]] || [[ "$file" == *.json ]] || [[ "$file" == *.css ]]; then
# For text files, show the actual diff
diff "$DIR1/$file" "$DIR2/$file" | head -50 || true
else
# For other binary files, show hexdump diff
echo "(binary file - showing hexdump diff)"
diff <(xxd "$DIR1/$file" | head -20) <(xxd "$DIR2/$file" | head -20) || true
fi
echo ""
done

echo "=== Summary ==="
echo "Total files with differences: ${#DIFF_FILES[@]}"
echo ""
echo "The hexdump shows differences in ZIP file headers at bytes 10-11 (e.g., b758 vs c758)."
echo "These bytes represent the 'last modification time' in DOS format."
echo ""
echo "The actual content (JSON files) inside the ZIPs is identical, but javadoc embeds"
echo "the current system time as file modification timestamps in the ZIP headers."
echo "This makes the -docs.jar non-deterministic even though documentation content is the same."
echo ""
echo "This is controlled by rules_jvm_external's maven_export macro, not rules_scala."
1 change: 1 addition & 0 deletions deps/latest/MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ bazel_dep(name = "platforms", version = "1.0.0")
bazel_dep(name = "protobuf", version = "33.1")
bazel_dep(name = "rules_java", version = "9.3.0")
bazel_dep(name = "rules_proto", version = "7.1.0")
bazel_dep(name = "rules_jvm_external", version = "6.9")

# https://github.com/bazelbuild/bazel/pull/25681 removed
# `bazel_tools/tools/cpp/osx_cc_wrapper.sh.tpl` in the `last_green` Bazel as of
Expand Down
Loading