#!/bin/sh
# Build the native libs twice and diff them, catching nondeterminism early.
# Requires the Android NDK and Go.
set -eu

root=$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd)
a=$(mktemp -d)
b=$(mktemp -d)
trap 'rm -rf "$a" "$b"' EXIT

make -C "$root" native
cp -r "$root/app/src/main/jniLibs" "$a/jniLibs"

rm -rf "$root/app/src/main/jniLibs" "$root/rsync/work" "$root/out"
make -C "$root" native
cp -r "$root/app/src/main/jniLibs" "$b/jniLibs"

if diff -r "$a/jniLibs" "$b/jniLibs"; then
	echo "verify-repro: native libs are bit-identical"
else
	echo "verify-repro: NONDETERMINISM detected" >&2
	exit 1
fi
