From 22e359bc19daf19033332aa2d7bb9726c7f4be14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cristi=C3=A1n=20Maureira-Fredes?= Date: Mon, 17 Feb 2020 13:41:08 +0100 Subject: shiboken: Improve the libdir for windows With virtualenv 20 we have the case where the first path in the PYTHON_LIBRARIES cmake variable was wrong: a_virtual_env/libs/python3.lib so the python code inside the helper didn't have a proper check if the file was valid or it was just a wrong construct. Additionally, the 'prefix' variable will contain the virtual environment directory location, which will not contain the 'libs' directory, because that's included in the system's installation path. To solve this, we use the 'INCLUDEPY' directory, which is correct as a base to create the real 'libs' one. Task-number: PYSIDE-1231 Change-Id: Ifca08d74c49cd57572836a087edb96c089266dc7 Reviewed-by: Friedemann Kleint --- build_scripts/main.py | 8 +++++++- sources/pyside2/tests/pysidetest/CMakeLists.txt | 9 ++++++++- sources/shiboken2/data/shiboken_helpers.cmake | 3 ++- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/build_scripts/main.py b/build_scripts/main.py index 674048e23..cf56850df 100644 --- a/build_scripts/main.py +++ b/build_scripts/main.py @@ -530,7 +530,13 @@ class PysideBuild(_build): self.py_scripts_dir = py_scripts_dir if py_libdir is None or not os.path.exists(py_libdir): if sys.platform == "win32": - py_libdir = os.path.join(py_prefix, "libs") + # For virtual environments on Windows, the py_prefix will contain a path pointing + # to it, instead of the system Python installation path. + # Since INCLUDEPY contains a path to the system location, we use the same base + # directory to define the py_libdir variable. + py_libdir = os.path.join(os.path.dirname(py_include_dir), "libs") + if not os.path.isdir(py_libdir): + raise DistutilsSetupError("Failed to locate the 'libs' directory") else: py_libdir = os.path.join(py_prefix, "lib") if py_include_dir is None or not os.path.exists(py_include_dir): diff --git a/sources/pyside2/tests/pysidetest/CMakeLists.txt b/sources/pyside2/tests/pysidetest/CMakeLists.txt index 4dcf9b89c..3ba2ad29d 100644 --- a/sources/pyside2/tests/pysidetest/CMakeLists.txt +++ b/sources/pyside2/tests/pysidetest/CMakeLists.txt @@ -107,10 +107,17 @@ set_property(TARGET testbinding PROPERTY OUTPUT_NAME "testbinding${SHIBOKEN_PYTH if(WIN32) set_property(TARGET testbinding PROPERTY SUFFIX ".pyd") endif() + +if(PYTHON_LIMITED_API) + set(TESTBINDING_PYTHON_LIBS ${PYTHON_LIMITED_LIBRARIES}) +else() + set(TESTBINDING_PYTHON_LIBS ${PYTHON_LIBRARIES}) +endif() + target_link_libraries(testbinding pysidetest pyside2 - ${PYTHON_LIBRARIES} + ${TESTBINDING_PYTHON_LIBS} Shiboken2::libshiboken ${Qt5Core_LIBRARIES} ${Qt5Gui_LIBRARIES} diff --git a/sources/shiboken2/data/shiboken_helpers.cmake b/sources/shiboken2/data/shiboken_helpers.cmake index 9772ee597..ee6c6c4d5 100644 --- a/sources/shiboken2/data/shiboken_helpers.cmake +++ b/sources/shiboken2/data/shiboken_helpers.cmake @@ -287,8 +287,9 @@ macro(shiboken_check_if_limited_api) # On other platforms, this result is not used at all. execute_process( COMMAND ${PYTHON_EXECUTABLE} -c "if True: + import os for lib in '${PYTHON_LIBRARIES}'.split(';'): - if '/' in lib: + if '/' in lib and os.path.isfile(lib): prefix, py = lib.rsplit('/', 1) if py.startswith('python3'): print(prefix + '/python3.lib') -- cgit v1.2.3