test: fill in srcdir/builddir when not set in the environment

Makes this test easier to run from the commandline. Where either of top_srcdir
or top_builddir isn't set, fill them in from the CWD or fail otherwise.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
master
Peter Hutterer 2021-01-22 08:05:09 +10:00 committed by Ran Benita
parent 44df69c928
commit d5e3695ea2
1 changed files with 13 additions and 2 deletions

View File

@ -31,8 +31,19 @@ import tempfile
import unittest
top_builddir = os.environ['top_builddir']
top_srcdir = os.environ['top_srcdir']
try:
top_builddir = os.environ['top_builddir']
top_srcdir = os.environ['top_srcdir']
except KeyError:
print('Required environment variables not found: top_srcdir/top_builddir', file=sys.stderr)
from pathlib import Path
top_srcdir = '.'
try:
top_builddir = next(Path('.').glob('**/meson-logs/')).parent
except StopIteration:
sys.exit(1)
print('Using srcdir "{}", builddir "{}"'.format(top_srcdir, top_builddir), file=sys.stderr)
logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger('test')