1+ #! /bin/bash -e
2+ . " $( dirname " $0 " ) " /../common.sh
3+
4+ # Test that verifies TASTy files can be generated deterministically
5+ echo " Testing TASTy file generation with Scala 3..."
6+
7+ # Build the Scala 3 target, explicitly using Scala 3 toolchain
8+ echo " Building target with Scala 3 toolchain..."
9+ bazel build --@rules_scala_annex//rules/scala:scala-toolchain=test_zinc_3 --keep_going --remote_executor= --remote_cache= --disk_cache= :tasty_test_lib
10+
11+ # Get the generated jar file
12+ bazel_bin=$( bazel info bazel-bin)
13+ jar_file=" $bazel_bin /determinism/tasty_test_lib.jar"
14+
15+ echo " Extracting TASTy files from build..."
16+ temp_dir=$( mktemp -d)
17+
18+ cleanup () {
19+ exit_code=$?
20+ for dir in " ${temp_dirs[@]} " ; do
21+ rm -r " $dir " 2> /dev/null || true
22+ done
23+ finish $exit_code
24+ }
25+ trap cleanup EXIT
26+
27+ # Extract all .tasty files from the jar
28+ unzip -j " $jar_file " " *.tasty" -d " $temp_dir " 2> /dev/null || {
29+ echo " No .tasty files found in jar, checking if they exist at all..."
30+ unzip -l " $jar_file " | grep -i tasty || {
31+ echo " ERROR: No TASTy files found in the generated jar"
32+ echo " Jar contents:"
33+ unzip -l " $jar_file "
34+ exit 1
35+ }
36+ }
37+
38+ # Verify TASTy files were generated
39+ tasty_files=$( find " $temp_dir " -name " *.tasty" | wc -l)
40+ if [ " $tasty_files " -eq 0 ]; then
41+ echo " ERROR: No TASTy files were extracted"
42+ exit 1
43+ fi
44+
45+ echo " SUCCESS: Found $tasty_files TASTy file(s) generated by Scala 3 compiler"
46+
47+ # Show what files were found
48+ echo " Generated TASTy files:"
49+ find " $temp_dir " -name " *.tasty" -exec basename {} \;
50+
51+ # Test determinism by rebuilding multiple times
52+ echo " Testing determinism by rebuilding 5 times..."
53+
54+ # Array to store temp directories for each build
55+ temp_dirs=(" $temp_dir " )
56+
57+ # Perform 4 additional builds (we already have one)
58+ for i in $( seq 2 5) ; do
59+ echo " Build $i /5..."
60+ bazel clean
61+ bazel build --@rules_scala_annex//rules/scala:scala-toolchain=test_zinc_3 --remote_executor= --remote_cache= --disk_cache= :tasty_test_lib
62+
63+ # Create temp directory for this build
64+ temp_dir_n=$( mktemp -d)
65+ temp_dirs+=(" $temp_dir_n " )
66+
67+ # Extract TASTy files from this build
68+ unzip -j " $jar_file " " *.tasty" -d " $temp_dir_n " 2> /dev/null || {
69+ echo " ERROR: Failed to extract TASTy files from build $i "
70+ exit 1
71+ }
72+ done
73+
74+ # Compare all builds against the first one
75+ echo " Comparing TASTy files across all 5 builds for determinism..."
76+ all_identical=true
77+
78+ for i in $( seq 2 5) ; do
79+ build_num=$(( i- 1 ))
80+ echo " Comparing build 1 with build $i ..."
81+ diff_output=$( diff -r " ${temp_dirs[0]} " " ${temp_dirs[$build_num]} " 2>&1 )
82+ if [ $? -ne 0 ]; then
83+ echo " ERROR: TASTy files differ between build 1 and build $i - not deterministic"
84+ echo " Differences found:"
85+ echo " $diff_output "
86+ all_identical=false
87+ fi
88+ done
89+
90+ if [ " $all_identical " = true ]; then
91+ echo " SUCCESS: TASTy files are identical across all 5 builds - build is deterministic!"
92+ else
93+ echo " ERROR: TASTy files differ between builds - not deterministic"
94+ exit 1
95+ fi
0 commit comments