1#!/bin/bash
2
3# This script makes sure that the meta crate deterministically generate files
4# with a high probability.
5# The current directory must be set to the repository's root.
6#
7# We set SKIP_ISLE=1 to skip ISLE generation, because it depends on files
8# in-tree (cranelift/codegen/.../*.isle) but these are not available when we
9# switch to different working directories during this test.
10
11set -e
12
13BUILD_SCRIPT=$(find -wholename "./target/debug/build/cranelift-codegen-*/build-script-build")
14
15# First, run the script to generate a reference comparison.
16rm -rf /tmp/reference
17mkdir /tmp/reference
18SKIP_ISLE=1 OUT_DIR=/tmp/reference TARGET=x86_64 CARGO_PKG_VERSION=0.1.0 CARGO_MANIFEST_DIR=/tmp $BUILD_SCRIPT
19
20# To make sure the build script doesn't depend on the current directory, we'll
21# change the current working directory on every iteration. Make this easy to
22# reproduce this locally by first copying the target/ directory into an initial
23# temporary directory (and not move and lose the local clone's content).
24rm -rf /tmp/src0
25mkdir /tmp/src0
26
27echo Copying target directory...
28cp -r ./target /tmp/src0/target
29cd /tmp/src0
30echo "Done, starting loop."
31
32# Then, repeatedly make sure that the output is the same.
33for i in {1..20}
34do
35    # Move to a different directory, as explained above.
36    rm -rf /tmp/src$i
37    mkdir /tmp/src$i
38    mv ./* /tmp/src$i
39    cd /tmp/src$i
40
41    rm -rf /tmp/try
42    mkdir /tmp/try
43    SKIP_ISLE=1 OUT_DIR=/tmp/try TARGET=x86_64 CARGO_PKG_VERSION=0.1.0 CARGO_MANIFEST_DIR=/tmp/src$i $BUILD_SCRIPT
44    diff -qr /tmp/reference /tmp/try
45done
46