#!/bin/sh

# Run Python 3 with environment variables set so that local headers and
# libraries in this repository are used when running tests.

# Usually, one would do this setup as part of test-env.sh, i.e.,
# AM_TESTS_ENVIRONMENT. However, macOS drops DYLD_LIBRARY_PATH whenever a
# shebang is followed, so we actually need to execute the Python binary
# directly and pass a script to it as a parameter to keep DYLD_LIBRARY_PATH
# alive.

# Resolve #include <e-antic/*.h> relative to libeantic in the source tree and
# resolve #include "local.h" relative to e-antic/e-antic in the build tree.
export EXTRA_CLING_ARGS="-I@abs_srcdir@/../.. -I@abs_builddir@/../../e-antic -std=c++17 -Wno-unused-comparison $EXTRA_CLING_ARGS"

# Load libeantic.so and libeanticxx.so from our build tree.
export LD_LIBRARY_PATH="@abs_builddir@/../../src/.libs/:@abs_builddir@/../../srcxx/.libs/:$LD_LIBRARY_PATH"

# Load libeantic.dylib and libeanticxx.dylib from our build tree.
export DYLD_LIBRARY_PATH="@abs_builddir@/../../src/.libs/:@abs_builddir@/../../srcxx/.libs/:$DYLD_LIBRARY_PATH"

exec python3 "$@"
