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