]> git.notmuchmail.org Git - notmuch/blob - test/export-dirs.sh
CLI: define and use format version 5
[notmuch] / test / export-dirs.sh
1 # Source this script to set and export NOTMUCH_SRCDIR and
2 # NOTMUCH_BUILDDIR.
3 #
4 # For this to work, always have current directory somewhere within the
5 # build directory hierarchy, and run the script sourcing this script
6 # using a path (relative or absolute) to the source directory.
7
8 if [[ -z "${NOTMUCH_SRCDIR}" ]]; then
9         export NOTMUCH_SRCDIR="$(cd "$(dirname "$0")"/.. && pwd)"
10 fi
11
12 find_builddir () {
13         local dir="$1"
14
15         while [[ -n "$dir" ]] && [[ "$dir" != "/" ]]; do
16                 if [[ -x "$dir/notmuch" ]] && [[ ! -d "$dir/notmuch" ]]; then
17                         echo "$dir"
18                         break
19                 fi
20                 dir="$(dirname "$dir")"
21         done
22 }
23
24 if [[ -z "${NOTMUCH_BUILDDIR}" ]]; then
25         export NOTMUCH_BUILDDIR="$(find_builddir "$(pwd)")"
26
27         if [[ -z "${NOTMUCH_BUILDDIR}" ]]; then
28                 echo "Run tests in a subdir of built notmuch tree." >&2
29                 exit 1
30         fi
31 fi