From 728f520378872a64a241119ce19082a19590f7ec Mon Sep 17 00:00:00 2001 From: Corey Minyard Date: Fri, 19 Jan 2024 17:46:20 -0800 Subject: [PATCH] windows: Fix various path issues PYTHONPATH needs to be separated by ';', not ':' now. It used to work, not sure what changed. Make sure all the local PATH things come first. Load DLL pathces with os.add_dll_directory() in reverse PATH order. Testing shows that it searches the last added directory first, loading in reverse order preserves the PATH order. Signed-off-by: Corey Minyard --- c++/swig/pygensio/tests/runtest.in | 8 ++++++-- c++/swig/pygensio/tests/testbase.py | 4 +++- tests/runtest.in | 10 +++++++--- tests/utils.py | 4 +++- 4 files changed, 19 insertions(+), 7 deletions(-) diff --git a/c++/swig/pygensio/tests/runtest.in b/c++/swig/pygensio/tests/runtest.in index 4b43f29f..243da129 100644 --- a/c++/swig/pygensio/tests/runtest.in +++ b/c++/swig/pygensio/tests/runtest.in @@ -54,7 +54,11 @@ else fi if ${PYTHON_MODE}; then - export PYTHONPATH=${BUILDDIR}/tests:${BUILDDIR}/c++/swig/pygensio:${BUILDDIR}/c++/swig/pygensio/.libs:${SRCDIR}/c++/swig/pygensio/test:${BUILDDIR}/glib/c++/swig/pygensio:${BUILDDIR}/glib/c++/swig/pygensio/.libs:${BUILDDIR}/tcl/c++/swig/pygensio:${BUILDDIR}/tcl/c++/swig/pygensio/.libs:${TEST_BUILDDIR} + export PYTHONPATH="${BUILDDIR}/tests:${BUILDDIR}/c++/swig/pygensio:${BUILDDIR}/c++/swig/pygensio/.libs:${SRCDIR}/c++/swig/pygensio/test:${BUILDDIR}/glib/c++/swig/pygensio:${BUILDDIR}/glib/c++/swig/pygensio/.libs:${BUILDDIR}/tcl/c++/swig/pygensio:${BUILDDIR}/tcl/c++/swig/pygensio/.libs:${TEST_BUILDDIR}" + if [ ! -z "$MSYSTEM" ]; then + # PYTHONPATH is separated by ; on windows + export PYTHONPATH=`echo ${PYTHONPATH} | tr ':' ';'` + fi TEST="${PYTHON} ${TEST}" export GENSIO_MEMTRACK=abort else @@ -66,7 +70,7 @@ fi # We need to put the DLL in PATH for MSYS on Windows if [ ! -z "$MSYSTEM" ]; then - export PATH=${BUILDDIR}/lib:${BUILDDIR}/lib/.libs:${BUILDDIR}/c++/lib/.libs:${BUILDDIR}/c++/swig/pygensio/.libs:${BUILDDIR}/glib/.libs:${BUILDDIR}/glib/c++/swig/pygensio/.libs:${BUILDDIR}/tcl/.libs:${BUILDDIR}/tcl/c++/swig/pygensio/.libs:$PATH + export PATH="${BUILDDIR}/lib:${BUILDDIR}/lib/.libs:${BUILDDIR}/c++/lib/.libs:${BUILDDIR}/c++/swig/pygensio/.libs:${BUILDDIR}/glib/.libs:${BUILDDIR}/glib/c++/swig/pygensio/.libs:${BUILDDIR}/tcl/.libs:${BUILDDIR}/tcl/c++/swig/pygensio/.libs:$PATH" else export LD_LIBRARY_PATH=${BUILDDIR}/lib:${BUILDDIR}/lib/.libs:${BUILDDIR}/c++/swig/pygensio/.libs:${BUILDDIR}/glib/.libs:${BUILDDIR}/glib/c++/pygensio/.libs:${BUILDDIR}/tcl/.libs:${BUILDDIR}/tcl/c++/pygensio/.libs:${BUILDDIR}/c++/lib/.libs fi diff --git a/c++/swig/pygensio/tests/testbase.py b/c++/swig/pygensio/tests/testbase.py index a02495d2..4546ea0a 100644 --- a/c++/swig/pygensio/tests/testbase.py +++ b/c++/swig/pygensio/tests/testbase.py @@ -17,7 +17,9 @@ def fix_dll_path(): if not path: return paths = path.split(";") - for folder in paths: + # The patches added below are search last added first. So preserved + # the DLL order by putting them in backwards. + for folder in reversed(paths): if os.path.exists(folder): os.add_dll_directory(folder) diff --git a/tests/runtest.in b/tests/runtest.in index 382b58e9..39d13748 100755 --- a/tests/runtest.in +++ b/tests/runtest.in @@ -54,7 +54,11 @@ else fi if ${PYTHON_MODE}; then - export PYTHONPATH=${BUILDDIR}/swig/python:${BUILDDIR}/swig/python/.libs:${BUILDDIR}/glib/swig/python:${BUILDDIR}/glib/swig/python/.libs:${BUILDDIR}/tcl/swig/python:${BUILDDIR}/tcl/swig/python/.libs:${TEST_BUILDDIR} + export PYTHONPATH="${BUILDDIR}/swig/python:${BUILDDIR}/swig/python/.libs:${BUILDDIR}/glib/swig/python:${BUILDDIR}/glib/swig/python/.libs:${BUILDDIR}/tcl/swig/python:${BUILDDIR}/tcl/swig/python/.libs:${TEST_BUILDDIR}" + if [ ! -z "$MSYSTEM" ]; then + # PYTHONPATH is separated by ; on windows + export PYTHONPATH=`echo ${PYTHONPATH} | tr ':' ';'` + fi TEST="${PYTHON} ${TEST}" export GENSIO_MEMTRACK=abort else @@ -66,7 +70,7 @@ fi # We need to put the DLL in PATH for MSYS on Windows if [ ! -z "$MSYSTEM" ]; then - export PATH=${BUILDDIR}/lib:${BUILDDIR}/lib/.libs:$PATH:${BUILDDIR}/glib/.libs:${BUILDDIR}/tcl/.libs:${BUILDDIR}/swig/python/.libs + export PATH="${BUILDDIR}/lib:${BUILDDIR}/lib/.libs:${BUILDDIR}/glib/.libs:${BUILDDIR}/tcl/.libs:${BUILDDIR}/swig/python/.libs:$PATH" else export LD_LIBRARY_PATH=${BUILDDIR}/lib:${BUILDDIR}/lib/.libs:${BUILDDIR}/glib/.libs:${BUILDDIR}/tcl/.libs:${BUILDDIR}/swig/python/.libs fi @@ -77,7 +81,7 @@ fi if ${PRINT_MODE}; then echo export PYTHONPATH="${PYTHONPATH}" if [ ! -z "$MSYSTEM" ]; then - echo export PATH=${BUILDDIR}/lib:${BUILDDIR}/lib/.libs:\$PATH:${BUILDDIR}/swig/python/.libs:${BUILDDIR}/glib/.libs:${BUILDDIR}/tcl/.libs + echo export PATH="${PATH}" else echo export LD_LIBRARY_PATH="${LD_LIBRARY_PATH}" fi diff --git a/tests/utils.py b/tests/utils.py index e2565c86..07cb22e7 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -24,7 +24,9 @@ def fix_dll_path(): if not path: return paths = path.split(";") - for folder in paths: + # The patches added below are search last added first. So preserved + # the DLL order by putting them in backwards. + for folder in reversed(paths): if os.path.exists(folder): os.add_dll_directory(folder)