X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=test%2Fexport-dirs.sh;fp=test%2Fexport-dirs.sh;h=0578b1e50194d308d42f782556c951630a702bf1;hb=1f3c114f08ed636fb43adb6b7c00b4cbb7c3ab1b;hp=0000000000000000000000000000000000000000;hpb=e1bd4f23634a88a49256c74e0780dd1dcdb852cd;p=notmuch diff --git a/test/export-dirs.sh b/test/export-dirs.sh new file mode 100644 index 00000000..0578b1e5 --- /dev/null +++ b/test/export-dirs.sh @@ -0,0 +1,32 @@ +# Source this script to set and export NOTMUCH_SRCDIR and +# NOTMUCH_BUILDDIR. +# +# For this to work, always have current directory somewhere within the +# build directory hierarchy, and run the script sourcing this script +# using a path (relative or absolute) to the source directory. + +if [[ -z "${NOTMUCH_SRCDIR}" ]]; then + export NOTMUCH_SRCDIR="$(cd "$(dirname "$0")"/.. && pwd)" +fi + +find_builddir() +{ + local dir="$1" + + while [[ -n "$dir" ]] && [[ "$dir" != "/" ]]; do + if [[ -x "$dir/notmuch" ]] && [[ ! -d "$dir/notmuch" ]]; then + echo "$dir" + break + fi + dir="$(dirname "$dir")" + done +} + +if [[ -z "${NOTMUCH_BUILDDIR}" ]]; then + export NOTMUCH_BUILDDIR="$(find_builddir "$(pwd)")" + + if [[ -z "${NOTMUCH_BUILDDIR}" ]]; then + echo "Run tests in a subdir of built notmuch tree." >&2 + exit 1 + fi +fi