#!/bin/sh
#
# Test that it works to build from a source archive exported by "git archive"
# outside a Git repository.

set -eux

# Unset CI variable to trigger ccache user build mode.
unset CI

# Ninja builds with relative paths so that ccache can be used to cache the build
# without resorting to setting base_dir.
export CMAKE_GENERATOR=Ninja

tmp_dir=$(mktemp -d)
trap "rm -rf $tmp_dir" EXIT

git archive --prefix=ccache/ -o $tmp_dir/ccache.tar.gz HEAD
cd $tmp_dir
tar xf ccache.tar.gz
cd ccache
mkdir build
cd build
cmake ..
ninja -v
jobs=$(getconf _NPROCESSORS_ONLN 2>/dev/null || echo 1)
ctest --output-on-failure -j $jobs
