diff options
34 files changed, 250 insertions, 155 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index f61a4f256..c470ab9f7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,11 +15,12 @@ endif() # Used to prevent overriding message function in both shiboken6 and pyside6. set(is_pyside6_superproject_build 1) +add_subdirectory(sources/shiboken6_generator) add_subdirectory(sources/shiboken6) # Ensure Shiboken6 and Shiboken6Tools packags are found during super-build list(APPEND CMAKE_PREFIX_PATH "${CMAKE_CURRENT_BINARY_DIR}/sources/shiboken6/data") -list(APPEND CMAKE_PREFIX_PATH "${CMAKE_CURRENT_BINARY_DIR}/sources/shiboken6/generator") +list(APPEND CMAKE_PREFIX_PATH "${CMAKE_CURRENT_BINARY_DIR}/sources/shiboken6_generator/generator") add_subdirectory(sources/pyside6) add_subdirectory(sources/pyside-tools) diff --git a/build_scripts/__init__.py b/build_scripts/__init__.py index 17975e34d..3df279dec 100644 --- a/build_scripts/__init__.py +++ b/build_scripts/__init__.py @@ -6,6 +6,7 @@ from pathlib import Path PYSIDE = 'pyside6' PYSIDE_MODULE = 'PySide6' SHIBOKEN = 'shiboken6' +SHIBOKEN_GENERATOR = 'shiboken6_generator' PYSIDE_PYTHON_TOOLS = ["metaobjectdump", "deploy", diff --git a/build_scripts/config.py b/build_scripts/config.py index efafc7688..47dd28b7c 100644 --- a/build_scripts/config.py +++ b/build_scripts/config.py @@ -7,7 +7,7 @@ import sys from pathlib import Path from typing import Any -from . import PYPROJECT_PATH, PYSIDE, PYSIDE_MODULE, SHIBOKEN +from . import PYPROJECT_PATH, PYSIDE, PYSIDE_MODULE, SHIBOKEN, SHIBOKEN_GENERATOR from .log import LogLevel, log from .utils import available_pyside_tools, Singleton @@ -240,7 +240,7 @@ class Config(metaclass=Singleton): if self.is_internal_shiboken_module_build(): return SHIBOKEN elif self.is_internal_shiboken_generator_build(): - return f"{SHIBOKEN}_generator" + return SHIBOKEN_GENERATOR elif self.is_internal_pyside_build(): return PYSIDE_MODULE else: @@ -299,7 +299,9 @@ class Config(metaclass=Singleton): Used by PysideBuild.run to build the CMake projects. :return: A list of directory names under the sources directory. """ - if self.is_internal_shiboken_module_build() or self.is_internal_shiboken_generator_build(): + if self.is_internal_shiboken_generator_build(): + return [SHIBOKEN_GENERATOR] + if self.is_internal_shiboken_module_build(): return [SHIBOKEN] elif self.is_internal_pyside_build(): return [PYSIDE, 'pyside-tools'] diff --git a/build_scripts/main.py b/build_scripts/main.py index cdaa439ff..c98390cf1 100644 --- a/build_scripts/main.py +++ b/build_scripts/main.py @@ -42,7 +42,7 @@ from .utils import (copydir, copyfile, detect_clang, linux_fix_rpaths_for_library, macos_fix_rpaths_for_library, parse_modules, platform_cmake_options, remove_tree, run_process, run_process_output, update_env_path, which) -from . import PYSIDE, PYSIDE_MODULE, SHIBOKEN +from . import PYSIDE, PYSIDE_MODULE, SHIBOKEN, SHIBOKEN_GENERATOR from .wheel_override import get_bdist_wheel_override, wheel_module_exists from .wheel_utils import (get_package_timestamp, get_package_version, macos_plat_name, macos_pyside_min_deployment_target) @@ -380,9 +380,9 @@ class PysideBuild(_build, CommandMixin, BuildInfoCollectorMixin): self.build_tests = OPTION["BUILDTESTS"] - # Save the shiboken build dir path for clang deployment + # Save the shiboken generator build dir path for clang deployment # purposes. - self.shiboken_build_dir = self.build_dir / SHIBOKEN + self.shiboken_generator_build_dir = self.build_dir / SHIBOKEN_GENERATOR self.log_pre_build_info() @@ -404,8 +404,7 @@ class PysideBuild(_build, CommandMixin, BuildInfoCollectorMixin): with open(self.internal_cmake_install_dir_query_file_path, 'w') as f: f.write(os.fspath(self.install_dir)) - if (not OPTION["ONLYPACKAGE"] - and not config.is_internal_shiboken_generator_build_and_part_of_top_level_all()): + if not OPTION["ONLYPACKAGE"]: # Build extensions for ext in config.get_buildable_extensions(): self.build_extension(ext) @@ -994,7 +993,7 @@ class PysideBuild(_build, CommandMixin, BuildInfoCollectorMixin): "-L", # Lists variables "-N", # Just inspects the cache (faster) "-B", # Specifies the build dir - str(self.shiboken_build_dir) + str(self.shiboken_generator_build_dir) ] out = run_process_output(cmake_cmd) lines = [s.strip() for s in out] diff --git a/build_scripts/platforms/windows_desktop.py b/build_scripts/platforms/windows_desktop.py index e023ff003..55b92873a 100644 --- a/build_scripts/platforms/windows_desktop.py +++ b/build_scripts/platforms/windows_desktop.py @@ -12,9 +12,11 @@ from pathlib import Path from ..log import log from ..config import config from ..options import OPTION -from ..utils import (copydir, copyfile, copy_qt_metatypes, download_and_extract_7z, - filter_match, makefile, in_coin, coin_job_id, copy_cmake_config_dirs) -from .. import PYSIDE, SHIBOKEN, PYSIDE_WINDOWS_BIN_TOOLS, PYSIDE_MULTIMEDIA_LIBS +from ..utils import (copydir, copyfile, copy_qt_metatypes, + download_and_extract_7z, filter_match, makefile, in_coin, coin_job_id, + copy_cmake_config_dirs) +from .. import (PYSIDE, SHIBOKEN, PYSIDE_WINDOWS_BIN_TOOLS, PYSIDE_MULTIMEDIA_LIBS, + SHIBOKEN_GENERATOR) def prepare_packages_win32(pyside_build, _vars): @@ -90,7 +92,7 @@ def prepare_packages_win32(pyside_build, _vars): # {shibokenmodule}.pdb file. # Task-number: PYSIDE-615 copydir( - f"{{build_dir}}/{SHIBOKEN}/generator", destination_dir, + f"{{build_dir}}/{SHIBOKEN_GENERATOR}/generator", destination_dir, _filter=pdbs, recursive=False, _vars=_vars) @@ -370,12 +372,12 @@ def copy_qt_artifacts(pyside_build, destination_qt_dir, copy_pdbs, _vars): file_filter_function=qt_dll_filter, recursive=False, _vars=_vars) + pdb_pattern = "*{}.pdb" if copy_plugins: is_pypy = "pypy" in pyside_build.build_classifiers # <qt>/plugins/* -> <setup>/{st_package_name}/plugins plugins_target = f"{destination_qt_dir}/plugins" plugin_dll_patterns = ["*{}.dll"] - pdb_pattern = "*{}.pdb" if copy_pdbs: plugin_dll_patterns += [pdb_pattern] plugin_dll_filter = functools.partial(qt_build_config_filter, plugin_dll_patterns) diff --git a/build_scripts/setup_runner.py b/build_scripts/setup_runner.py index ec679801e..116ab4a72 100644 --- a/build_scripts/setup_runner.py +++ b/build_scripts/setup_runner.py @@ -126,7 +126,7 @@ class SetupRunner: # instead of shiboken_generator_option_name, but it will # actually build the generator. host_cmd = self.new_setup_internal_invocation( - initialized_config.shiboken_module_option_name, + initialized_config.shiboken_generator_option_name, extra_args=extra_host_args, replace_command_with="build") @@ -228,19 +228,14 @@ class SetupRunner: # target invocations. if config.is_cross_compile(): extra_args = self.add_host_tools_setup_internal_invocation(config) + else: + self.add_setup_internal_invocation( + config.shiboken_generator_option_name) self.add_setup_internal_invocation( config.shiboken_module_option_name, extra_args=extra_args) - # Reuse the shiboken build for the generator package instead - # of rebuilding it again. - # Don't build it in a cross-build though. - if not config.is_cross_compile(): - self.add_setup_internal_invocation( - config.shiboken_generator_option_name, - reuse_build=True) - self.add_setup_internal_invocation(config.pyside_option_name, extra_args=extra_args) diff --git a/create_wheels.py b/create_wheels.py index 6f8d8812e..d9d900fb4 100644 --- a/create_wheels.py +++ b/create_wheels.py @@ -185,8 +185,6 @@ def generate_pyproject_toml(artifacts: Path, setup: SetupData) -> str: elif _name == "PySide6_Addons": _dependencies.append(f"shiboken6=={setup.version[0]}") _dependencies.append(f"PySide6_Essentials=={setup.version[0]}") - elif _name == "shiboken6_generator": - _dependencies.append(f"shiboken6=={setup.version[0]}") with open(artifacts / "pyproject.toml.base") as f: content = ( diff --git a/examples/corelib/mimetypesbrowser/mimetypesbrowser.py b/examples/corelib/mimetypesbrowser/mimetypesbrowser.py index 4f7b6959a..00d58bde3 100644 --- a/examples/corelib/mimetypesbrowser/mimetypesbrowser.py +++ b/examples/corelib/mimetypesbrowser/mimetypesbrowser.py @@ -8,10 +8,15 @@ import argparse import sys from mainwindow import MainWindow +from PySide6.QtCore import QLibraryInfo, QLocale, QTranslator from PySide6.QtWidgets import QApplication if __name__ == "__main__": app = QApplication(sys.argv) + translator = QTranslator(app) + if translator.load(QLocale.system(), "qtbase", "_", + QLibraryInfo.path(QLibraryInfo.LibraryPath.TranslationsPath)): + app.installTranslator(translator) parser = argparse.ArgumentParser(description="MimeTypesBrowser Example") parser.add_argument("-v", "--version", action="version", version="%(prog)s 1.0") diff --git a/examples/utils/pyside_config.py b/examples/utils/pyside_config.py index ea021030f..ec4cb61d1 100644 --- a/examples/utils/pyside_config.py +++ b/examples/utils/pyside_config.py @@ -53,6 +53,10 @@ options.append(("--shiboken-include-path", lambda: get_package_include_path(Package.SHIBOKEN_MODULE), pyside_error, "Print shiboken module include paths")) +options.append(("--shiboken-generator-include-path", + lambda: get_package_include_path(Package.SHIBOKEN_GENERATOR), + pyside_error, + "Print shiboken generator include paths")) options.append(("--pyside-include-path", lambda: get_package_include_path(Package.PYSIDE_MODULE), pyside_error, diff --git a/examples/widgets/dialogs/standarddialogs/standarddialogs.py b/examples/widgets/dialogs/standarddialogs/standarddialogs.py index 7bd68620a..541aab305 100644 --- a/examples/widgets/dialogs/standarddialogs/standarddialogs.py +++ b/examples/widgets/dialogs/standarddialogs/standarddialogs.py @@ -8,7 +8,7 @@ from __future__ import annotations import sys from textwrap import dedent -from PySide6.QtCore import QDir, Qt, Slot +from PySide6.QtCore import QDir, QLibraryInfo, QLocale, QTranslator, Qt, Slot from PySide6.QtGui import QFont, QPalette from PySide6.QtWidgets import (QApplication, QColorDialog, QCheckBox, QDialog, QErrorMessage, QFontDialog, QFileDialog, QFrame, @@ -432,6 +432,10 @@ class Dialog(QDialog): if __name__ == '__main__': app = QApplication(sys.argv) + translator = QTranslator(app) + if translator.load(QLocale.system(), "qtbase", "_", + QLibraryInfo.path(QLibraryInfo.LibraryPath.TranslationsPath)): + app.installTranslator(translator) dialog = Dialog() availableGeometry = dialog.screen().availableGeometry() dialog.resize(availableGeometry.width() / 3, availableGeometry.height() * 2 / 3) diff --git a/sources/pyside6/PySide6/QtCore/typesystem_core_common.xml b/sources/pyside6/PySide6/QtCore/typesystem_core_common.xml index 0256821d4..acf9202cb 100644 --- a/sources/pyside6/PySide6/QtCore/typesystem_core_common.xml +++ b/sources/pyside6/PySide6/QtCore/typesystem_core_common.xml @@ -336,7 +336,8 @@ <add-conversion type="SbkObject" file="../glue/qtcore.cpp" snippet="conversion-sbkobject"/> <add-conversion type="PyDict" check="PyDict_CheckExact(%in)" file="../glue/qtcore.cpp" snippet="conversion-pydict"/> <add-conversion type="PyList" check="PyList_Check(%in)" file="../glue/qtcore.cpp" snippet="conversion-pylist"/> - <add-conversion type="PyTuple" check="PyTuple_Check(%in)" file="../glue/qtcore.cpp" snippet="conversion-pylist"/> + <add-conversion type="PyTuple" check="PyTuple_CheckExact(%in)" + file="../glue/qtcore.cpp" snippet="conversion-pylist"/> <add-conversion type="PyObject" file="../glue/qtcore.cpp" snippet="conversion-pyobject"/> </target-to-native> </conversion-rule> @@ -3414,6 +3415,9 @@ <add-function signature="__repr__" return-type="str"> <inject-code class="target" position="beginning" file="../glue/qtcore.cpp" snippet="qmetaobject-repr"/> </add-function> + <modify-function signature="className()const"> + <modify-argument index="return" pyi-type="str"/> + </modify-function> <modify-function signature="indexOfClassInfo(const char *)const"> <modify-argument index="1" pyi-type="str"/> </modify-function> diff --git a/sources/pyside6/doc/developer/add_port_example.rst b/sources/pyside6/doc/developer/add_port_example.rst index 909986e79..e65c3c9c8 100644 --- a/sources/pyside6/doc/developer/add_port_example.rst +++ b/sources/pyside6/doc/developer/add_port_example.rst @@ -67,11 +67,17 @@ Port a Qt example - Note that our examples need to have unique names due to the doc build. - Verify that all slots are decorated using ``@Slot``. - Enumerations should be fully qualified (PYSIDE-1735). +- Check the above by running the example with the environment variables: + + .. code-block:: bash + + export PYSIDE6_OPTION_PYTHON_ENUM=0x71 + export QT_LOGGING_RULES=qt.pyside.libpyside.warning=true + - Add a ``.pyproject`` file (verify later on that docs build). -- Add a ``doc`` directory and descriptive ``.rst`` file, +- Add a ``doc`` directory and descriptive ``.md`` or ``.rst`` file, and a screenshot if suitable (use ``optipng`` to reduce file size). - Add the ``"""Port of the ... example from Qt 6"""`` doc string. -- Try to port variable and function names to snake case convention. - Remove C++ documentation from ``sources/pyside6/doc/additionaldocs.lst``. .. note:: Example screenshots in ``.png`` should be optimized by diff --git a/sources/pyside6/plugins/designer/designercustomwidgets.cpp b/sources/pyside6/plugins/designer/designercustomwidgets.cpp index d13539859..c43af1f6d 100644 --- a/sources/pyside6/plugins/designer/designercustomwidgets.cpp +++ b/sources/pyside6/plugins/designer/designercustomwidgets.cpp @@ -68,7 +68,7 @@ static QString pyErrorMessage() #else // <3.11 if (PyObject *pvalue = PyErr_GetRaisedException()) { result = pyStr(pvalue); - Py_DECREF(pvalue); + PyErr_SetRaisedException(pvalue); } #endif return result; diff --git a/sources/pyside6/tests/QtCore/qobject_property_test.py b/sources/pyside6/tests/QtCore/qobject_property_test.py index 80387ec77..9d2bd2c56 100644 --- a/sources/pyside6/tests/QtCore/qobject_property_test.py +++ b/sources/pyside6/tests/QtCore/qobject_property_test.py @@ -9,6 +9,7 @@ import sys import unittest from pathlib import Path +from typing import NamedTuple sys.path.append(os.fspath(Path(__file__).resolve().parents[1])) from init_paths import init_test_paths init_test_paths(False) @@ -16,6 +17,9 @@ init_test_paths(False) from PySide6.QtCore import QObject, Property, Signal +Point = NamedTuple("Point", [("x", float), ("y", float)]) + + class MyObjectWithNotifyProperty(QObject): def __init__(self, parent=None): QObject.__init__(self, parent) @@ -52,6 +56,23 @@ class MyObjectWithOtherClassProperty(QObject): otherclass = Property(OtherClass, fget=_get_otherclass, fset=_set_otherclass) +class TestVariantPropertyObject(QObject): + """Helper for testing QVariant conversion in properties and signals + (PYSIDE-3206, PYSIDE-3244). It uses a property of list type that + can passed a QVariant list with various element types.""" + def __init__(self, parent=None): + super().__init__(parent) + self._property = None + + def set_property(self, v): + self._property = v + + def get_property(self): + return self._property + + testProperty = Property(list, fget=get_property, fset=set_property) + + class PropertyWithNotify(unittest.TestCase): def called(self): self.called_ = True @@ -84,5 +105,32 @@ class QObjectWithOtherClassPropertyTest(unittest.TestCase): self.assertTrue(type(pv) is OtherClass) +class VariantPropertyTest(unittest.TestCase): + """Test QVariant conversion in properties and signals (PYSIDE-3206, PYSIDE-3244). + It uses a property of list type that is passed a QVariantList + with various element types when using QObject.setProperty().""" + + def testIt(self): + to = TestVariantPropertyObject() + idx = to.metaObject().indexOfProperty("testProperty") + self.assertTrue(idx != -1) + + # List + to.setProperty("testProperty", [[1, 2]]) + self.assertEqual(type(to.get_property()[0]), list) + + # Dict + to.setProperty("testProperty", [{"key": 42}]) + self.assertEqual(type(to.get_property()[0]), dict) + + # PYSIDE-3206 (DBus): Convert a tuple to a list + to.setProperty("testProperty", [(1, 2)]) + self.assertEqual(type(to.get_property()[0]), list) + + # PYSIDE-324: The tuple conversion must not occur for named tuples + to.setProperty("testProperty", [Point(1, 2)]) + self.assertEqual(type(to.get_property()[0]), Point) + + if __name__ == '__main__': unittest.main() diff --git a/sources/pyside6/tests/QtRemoteObjects/CMakeLists.txt b/sources/pyside6/tests/QtRemoteObjects/CMakeLists.txt index ace1a00fa..72e7d3cea 100644 --- a/sources/pyside6/tests/QtRemoteObjects/CMakeLists.txt +++ b/sources/pyside6/tests/QtRemoteObjects/CMakeLists.txt @@ -1,11 +1,8 @@ # Copyright (C) 2025 Ford Motor Company # SPDX-License-Identifier: BSD-3-Clause -# FIXME: TypeError: Failed to generate default value. Error: name 'int' is not defined. Problematic code: int(2) -if(NOT APPLE) PYSIDE_TEST(repfile_test.py) PYSIDE_TEST(dynamic_types_test.py) PYSIDE_TEST(integration_test.py) add_subdirectory(cpp_interop) -endif() diff --git a/sources/shiboken6/CMakeLists.txt b/sources/shiboken6/CMakeLists.txt index efc2ec7cf..5efa9633e 100644 --- a/sources/shiboken6/CMakeLists.txt +++ b/sources/shiboken6/CMakeLists.txt @@ -10,22 +10,16 @@ set(CMAKE_BUILD_TYPE Release CACHE STRING "Build Type") include(".cmake.conf") project(shiboken6) + include(cmake/ShibokenSetup.cmake) get_rpath_base_token(base) set(CMAKE_INSTALL_RPATH ${base}/) -if(SHIBOKEN_BUILD_TOOLS) - add_subdirectory(ApiExtractor) # Uses libclang - add_subdirectory(generator) # Uses ApiExtractor And QtCore -endif() - -if(SHIBOKEN_BUILD_LIBS) - add_subdirectory(libshiboken) # Uses Python - add_subdirectory(shibokenmodule) # Uses libshiboken - add_subdirectory(data) -endif() +add_subdirectory(libshiboken) # Uses Python +add_subdirectory(shibokenmodule) # Uses libshiboken +add_subdirectory(data) add_subdirectory(doc) diff --git a/sources/shiboken6/cmake/ShibokenHelpers.cmake b/sources/shiboken6/cmake/ShibokenHelpers.cmake index 0e993fadb..571ae6656 100644 --- a/sources/shiboken6/cmake/ShibokenHelpers.cmake +++ b/sources/shiboken6/cmake/ShibokenHelpers.cmake @@ -180,41 +180,6 @@ macro(set_python_config_suffix) endif() endmacro() -macro(setup_clang) - # Find libclang using the environment variables LLVM_INSTALL_DIR, - # CLANG_INSTALL_DIR using standard cmake. - # Use CLANG_INCLUDE_DIRS and link to libclang. - if(DEFINED ENV{LLVM_INSTALL_DIR}) - list(PREPEND CMAKE_PREFIX_PATH "$ENV{LLVM_INSTALL_DIR}") - list(PREPEND CMAKE_FIND_ROOT_PATH "$ENV{LLVM_INSTALL_DIR}") - elseif(DEFINED ENV{CLANG_INSTALL_DIR}) - list(PREPEND CMAKE_PREFIX_PATH "$ENV{CLANG_INSTALL_DIR}") - list(PREPEND CMAKE_FIND_ROOT_PATH "$ENV{CLANG_INSTALL_DIR}") - endif() - - find_package(Clang CONFIG REQUIRED) - # Need to explicitly handle the version check, because the Clang package doesn't. - set(REQUIRED_LLVM "18.0") - - if (LLVM_PACKAGE_VERSION AND LLVM_PACKAGE_VERSION VERSION_LESS "${REQUIRED_LLVM}") - message(WARNING "You need LLVM version ${REQUIRED_LLVM} or greater to build PySide " - "without issues, and ${LLVM_PACKAGE_VERSION} was found. " - "A lower version might case problems, specially on Windows.") - # Exception to enable Yocto builds (Kirkstone) - 6.8.x - set(REQUIRED_LLVM "14.0") - if (LLVM_PACKAGE_VERSION AND LLVM_PACKAGE_VERSION VERSION_LESS "${REQUIRED_LLVM}") - message(FATAL_ERROR "Using a LLVM version ${REQUIRED_LLVM} is the minimum allowed " - "to work pyside in some systems, however ${LLVM_PACKAGE_VERSION} was found.") - endif() - endif() - - # CLANG_LIBRARY is read out from the cmake cache to deploy libclang - get_target_property(CLANG_BUILD_TYPE libclang IMPORTED_CONFIGURATIONS) - get_target_property(CLANG_LIBRARY_NAME libclang IMPORTED_LOCATION_${CLANG_BUILD_TYPE}) - set(CLANG_LIBRARY "${CLANG_LIBRARY_NAME}" CACHE FILEPATH "libclang") - message(STATUS "CLANG: ${Clang_DIR}, ${CLANG_LIBRARY} detected") -endmacro() - macro(set_quiet_build) # Don't display "up-to-date / install" messages when installing, to reduce visual clutter. set(CMAKE_INSTALL_MESSAGE NEVER) @@ -551,18 +516,6 @@ function(shiboken_internal_detect_if_cross_building) endfunction() function(shiboken_internal_decide_parts_to_build) - set(build_libs_default ON) - option(SHIBOKEN_BUILD_LIBS "Build shiboken libraries" ${build_libs_default}) - message(STATUS "SHIBOKEN_BUILD_LIBS: ${SHIBOKEN_BUILD_LIBS}") - - if(SHIBOKEN_IS_CROSS_BUILD) - set(build_tools_default OFF) - else() - set(build_tools_default ON) - endif() - option(SHIBOKEN_BUILD_TOOLS "Build shiboken tools" ${build_tools_default}) - message(STATUS "SHIBOKEN_BUILD_TOOLS: ${SHIBOKEN_BUILD_TOOLS}") - if(SHIBOKEN_IS_CROSS_BUILD) set(_shiboken_build_tests_default OFF) elseif(SHIBOKEN_BUILD_LIBS) @@ -573,23 +526,22 @@ function(shiboken_internal_decide_parts_to_build) endfunction() function(shiboken_internal_find_host_shiboken_tools) - if(SHIBOKEN_IS_CROSS_BUILD) - set(find_package_extra_args) - if(QFP_SHIBOKEN_HOST_PATH) - list(APPEND find_package_extra_args PATHS "${QFP_SHIBOKEN_HOST_PATH}/lib/cmake") - list(PREPEND CMAKE_FIND_ROOT_PATH "${QFP_SHIBOKEN_HOST_PATH}") - endif() - find_package( - Shiboken6Tools 6 CONFIG - ${find_package_extra_args} - ) + set(find_package_extra_args) + if(QFP_SHIBOKEN_HOST_PATH) + list(APPEND find_package_extra_args PATHS "${QFP_SHIBOKEN_HOST_PATH}/lib/cmake") + list(PREPEND CMAKE_FIND_ROOT_PATH "${QFP_SHIBOKEN_HOST_PATH}") + endif() + set(SHIBOKEN6TOOLS_SKIP_FIND_DEPENDENCIES TRUE) + find_package( + Shiboken6Tools 6 CONFIG + ${find_package_extra_args} + ) - if(NOT Shiboken6Tools_DIR) - message(FATAL_ERROR - "Shiboken6Tools package was not found. " - "Please set QFP_SHIBOKEN_HOST_PATH to the location where the Shiboken6Tools CMake " - "package is installed.") - endif() + if(NOT Shiboken6Tools_DIR AND QFP_SHIBOKEN_HOST_PATH) + message(FATAL_ERROR + "Shiboken6Tools package was not found. " + "Please set QFP_SHIBOKEN_HOST_PATH to the location where the Shiboken6Tools CMake " + "package is installed.") endif() endfunction() diff --git a/sources/shiboken6/cmake/ShibokenSetup.cmake b/sources/shiboken6/cmake/ShibokenSetup.cmake index 32823d9fa..73030bc90 100644 --- a/sources/shiboken6/cmake/ShibokenSetup.cmake +++ b/sources/shiboken6/cmake/ShibokenSetup.cmake @@ -33,10 +33,6 @@ else() shiboken_find_required_python() endif() -if(SHIBOKEN_BUILD_TOOLS) - setup_clang() -endif() - set(shiboken6_VERSION "${shiboken_MAJOR_VERSION}.${shiboken_MINOR_VERSION}.${shiboken_MICRO_VERSION}") set(shiboken6_library_so_version "${shiboken_MAJOR_VERSION}.${shiboken_MINOR_VERSION}") diff --git a/sources/shiboken6/libshiboken/CMakeLists.txt b/sources/shiboken6/libshiboken/CMakeLists.txt index dc8a73156..9290256f8 100644 --- a/sources/shiboken6/libshiboken/CMakeLists.txt +++ b/sources/shiboken6/libshiboken/CMakeLists.txt @@ -106,7 +106,6 @@ signature/signature_helper.cpp set_property(SOURCE "pep384impl.cpp" PROPERTY SKIP_UNITY_BUILD_INCLUSION ON) add_library(libshiboken SHARED ${libshiboken_SRC}) -add_library(Shiboken6::libshiboken ALIAS libshiboken) target_include_directories(libshiboken PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}> diff --git a/sources/shiboken6/libshiboken/basewrapper.cpp b/sources/shiboken6/libshiboken/basewrapper.cpp index 4b69abd4d..1bcc27218 100644 --- a/sources/shiboken6/libshiboken/basewrapper.cpp +++ b/sources/shiboken6/libshiboken/basewrapper.cpp @@ -869,10 +869,10 @@ static std::string msgFailedToInitializeType(const char *description) { std::ostringstream stream; stream << "libshiboken: Failed to initialize " << description; - if (auto *error = PepErr_GetRaisedException()) { - if (auto *str = PyObject_Str(error)) + if (PyErr_Occurred() != nullptr) { + Shiboken::Errors::Stash stash; + if (auto *str = PyObject_Str(stash.getException())) stream << ": " << Shiboken::String::toCString(str); - Py_DECREF(error); } stream << '.'; return stream.str(); diff --git a/sources/shiboken6/libshiboken/pep384impl.cpp b/sources/shiboken6/libshiboken/pep384impl.cpp index 4afdcdc8b..e274b4a62 100644 --- a/sources/shiboken6/libshiboken/pep384impl.cpp +++ b/sources/shiboken6/libshiboken/pep384impl.cpp @@ -391,18 +391,6 @@ Pep_GetVerboseFlag() // Support for pyerrors.h #ifdef PEP_OLD_ERR_API -// Emulate PyErr_GetRaisedException() using the deprecated PyErr_Fetch()/PyErr_Store() -PyObject *PepErr_GetRaisedException() -{ - PyObject *type{}; - PyObject *value{}; - PyObject *traceback{}; - PyErr_Fetch(&type, &value, &traceback); - Py_XINCREF(value); - PyErr_Restore(type, value, traceback); - return value; -} - struct PepException_HEAD { PyObject_HEAD diff --git a/sources/shiboken6/libshiboken/pep384impl.h b/sources/shiboken6/libshiboken/pep384impl.h index 0e32ec0c8..8552a1e40 100644 --- a/sources/shiboken6/libshiboken/pep384impl.h +++ b/sources/shiboken6/libshiboken/pep384impl.h @@ -192,11 +192,9 @@ LIBSHIBOKEN_API int Pep_GetVerboseFlag(void); // pyerrors.h #ifdef PEP_OLD_ERR_API -LIBSHIBOKEN_API PyObject *PepErr_GetRaisedException(); LIBSHIBOKEN_API PyObject *PepException_GetArgs(PyObject *ex); LIBSHIBOKEN_API void PepException_SetArgs(PyObject *ex, PyObject *args); #else -inline PyObject *PepErr_GetRaisedException() { return PyErr_GetRaisedException(); } inline PyObject *PepException_GetArgs(PyObject *ex) { return PyException_GetArgs(ex); } inline void PepException_SetArgs(PyObject *ex, PyObject *args) { PyException_SetArgs(ex, args); } diff --git a/sources/shiboken6/libshiboken/sbkfeature_base.cpp b/sources/shiboken6/libshiboken/sbkfeature_base.cpp index a705cdb40..fc29442ce 100644 --- a/sources/shiboken6/libshiboken/sbkfeature_base.cpp +++ b/sources/shiboken6/libshiboken/sbkfeature_base.cpp @@ -269,6 +269,11 @@ static PyObject *lookupUnqualifiedOrOldEnum(PyTypeObject *type, PyObject *name) // MRO has been observed to be 0 in case of errors with QML decorators if (type == nullptr || type->tp_mro == nullptr) return nullptr; + // Quick Check: Disabled? + const bool useFakeRenames = (Enum::enumOption & Enum::ENOPT_NO_FAKERENAMES) == 0; + const bool useFakeShortcuts = (Enum::enumOption & Enum::ENOPT_NO_FAKESHORTCUT) == 0; + if (!useFakeRenames && !useFakeShortcuts) + return nullptr; // Quick Check: Avoid "__..", "_slots", etc. if (std::isalpha(Shiboken::String::toCString(name)[0]) == 0) return nullptr; @@ -291,7 +296,6 @@ static PyObject *lookupUnqualifiedOrOldEnum(PyTypeObject *type, PyObject *name) continue; if (!sotp->enumFlagsDict) initEnumFlagsDict(type_base); - bool useFakeRenames = !(Enum::enumOption & Enum::ENOPT_NO_FAKERENAMES); if (useFakeRenames) { auto *rename = PyDict_GetItem(sotp->enumFlagsDict, name); if (rename) { @@ -322,7 +326,6 @@ static PyObject *lookupUnqualifiedOrOldEnum(PyTypeObject *type, PyObject *name) return flagType; } } - bool useFakeShortcuts = !(Enum::enumOption & Enum::ENOPT_NO_FAKESHORTCUT); if (useFakeShortcuts) { AutoDecRef tpDict(PepType_GetDict(type_base)); auto *dict = tpDict.object(); diff --git a/sources/shiboken6/tests/CMakeLists.txt b/sources/shiboken6/tests/CMakeLists.txt index 6de8199ef..c9277d0dc 100644 --- a/sources/shiboken6/tests/CMakeLists.txt +++ b/sources/shiboken6/tests/CMakeLists.txt @@ -83,15 +83,3 @@ foreach(test_file ${TEST_FILES}) set_tests_properties(${test_name} PROPERTIES WILL_FAIL TRUE) endif() endforeach() - -# dumpcodemodel depends on apiextractor which is not cross-built. -if(SHIBOKEN_BUILD_TOOLS) - add_subdirectory(dumpcodemodel) -endif() - -# FIXME Skipped until add an option to choose the generator -# add_subdirectory(test_generator) - -if (NOT APIEXTRACTOR_DOCSTRINGS_DISABLED) - add_subdirectory(qtxmltosphinxtest) -endif() diff --git a/sources/shiboken6_generator/ApiExtractor/CMakeLists.txt b/sources/shiboken6_generator/ApiExtractor/CMakeLists.txt index 5385eccf1..b0ce14bef 100644 --- a/sources/shiboken6_generator/ApiExtractor/CMakeLists.txt +++ b/sources/shiboken6_generator/ApiExtractor/CMakeLists.txt @@ -131,8 +131,6 @@ target_compile_definitions(apiextractor PRIVATE CMAKE_CXX_COMPILER="${CMAKE_CXX_COMPILER}" PRIVATE QT_LEAN_HEADERS=1) -set(LIB_INSTALL_DIR "lib${LIB_SUFFIX}" CACHE PATH "The subdirectory relative to the install prefix where libraries will be installed (default is /lib${LIB_SUFFIX})" FORCE) - if (BUILD_TESTS) find_package(Qt6 REQUIRED COMPONENTS Test) set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/tests) diff --git a/sources/shiboken6_generator/CMakeLists.txt b/sources/shiboken6_generator/CMakeLists.txt new file mode 100644 index 000000000..24fb91c57 --- /dev/null +++ b/sources/shiboken6_generator/CMakeLists.txt @@ -0,0 +1,23 @@ +include(../shiboken6/icecc.cmake) +include(../shiboken6/.cmake.conf) + +cmake_minimum_required(VERSION 3.18) +cmake_policy(VERSION 3.18) + +project(shiboken_generator) + +include(cmake/ShibokenGeneratorSetup.cmake) + +get_rpath_base_token(base) + +set(CMAKE_INSTALL_RPATH ${base}/) + +set(CMAKE_BUILD_TYPE Release CACHE STRING "Build Type") + +add_subdirectory(ApiExtractor) # Uses libclang +add_subdirectory(generator) # Uses ApiExtractor And QtCore + +if(BUILD_TESTS) + enable_testing() + add_subdirectory(tests) +endif() diff --git a/sources/shiboken6_generator/cmake/ShibokenGeneratorHelpers.cmake b/sources/shiboken6_generator/cmake/ShibokenGeneratorHelpers.cmake new file mode 100644 index 000000000..90d43c15e --- /dev/null +++ b/sources/shiboken6_generator/cmake/ShibokenGeneratorHelpers.cmake @@ -0,0 +1,26 @@ +option(BUILD_TESTS "Build tests." ON) + +macro(setup_clang) + # Find libclang using the environment variables LLVM_INSTALL_DIR, + # CLANG_INSTALL_DIR using standard cmake. + # Use CLANG_INCLUDE_DIRS and link to libclang. + if(DEFINED ENV{LLVM_INSTALL_DIR}) + list(PREPEND CMAKE_PREFIX_PATH "$ENV{LLVM_INSTALL_DIR}") + list(PREPEND CMAKE_FIND_ROOT_PATH "$ENV{LLVM_INSTALL_DIR}") + elseif(DEFINED ENV{CLANG_INSTALL_DIR}) + list(PREPEND CMAKE_PREFIX_PATH "$ENV{CLANG_INSTALL_DIR}") + list(PREPEND CMAKE_FIND_ROOT_PATH "$ENV{CLANG_INSTALL_DIR}") + endif() + + find_package(Clang CONFIG REQUIRED) + # Need to explicitly handle the version check, because the Clang package doesn't. + if (LLVM_PACKAGE_VERSION AND LLVM_PACKAGE_VERSION VERSION_LESS "9.0") + message(FATAL_ERROR "You need LLVM version 9.0 or greater to build.") + endif() + + # CLANG_LIBRARY is read out from the cmake cache to deploy libclang + get_target_property(CLANG_BUILD_TYPE libclang IMPORTED_CONFIGURATIONS) + get_target_property(CLANG_LIBRARY_NAME libclang IMPORTED_LOCATION_${CLANG_BUILD_TYPE}) + set(CLANG_LIBRARY "${CLANG_LIBRARY_NAME}" CACHE FILEPATH "libclang") + message(STATUS "CLANG: ${Clang_DIR}, ${CLANG_LIBRARY} detected") +endmacro() diff --git a/sources/shiboken6_generator/cmake/ShibokenGeneratorSetup.cmake b/sources/shiboken6_generator/cmake/ShibokenGeneratorSetup.cmake new file mode 100644 index 000000000..137824d15 --- /dev/null +++ b/sources/shiboken6_generator/cmake/ShibokenGeneratorSetup.cmake @@ -0,0 +1,50 @@ +list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}" + "${CMAKE_CURRENT_LIST_DIR}/../../shiboken6/cmake") + +include(ShibokenHelpers) +include(ShibokenGeneratorHelpers) + +shiboken_internal_disable_pkg_config_if_needed() +shiboken_internal_detect_if_cross_building() + +# Note: For cross building, we rely on FindPython shipped with CMake 3.17+ to +# provide the value of Python_SOABI. + +shiboken_internal_decide_parts_to_build() +shiboken_internal_set_up_extra_dependency_paths() + +set(QT_MAJOR_VERSION 6) +message(STATUS "Using Qt ${QT_MAJOR_VERSION}") +find_package(Qt6 REQUIRED COMPONENTS Core) + +if(QUIET_BUILD) + set_quiet_build() +endif() + +if(USE_PYTHON_VERSION) + shiboken_find_required_python(${USE_PYTHON_VERSION}) +else() + shiboken_find_required_python() +endif() + +setup_clang() + +# from cmake.conf +set(shiboken6_VERSION "${shiboken_MAJOR_VERSION}.${shiboken_MINOR_VERSION}.${shiboken_MICRO_VERSION}") + +compute_config_py_values(shiboken6_VERSION) + +shiboken_internal_set_python_site_packages() + +set_cmake_cxx_flags() +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D QT_NO_CAST_FROM_ASCII -D QT_NO_CAST_TO_ASCII") + +# Force usage of the C++17 standard +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED ON) + +set(LIB_SUFFIX "" CACHE STRING "Define suffix of directory name (32/64)" ) +set(LIB_INSTALL_DIR "lib${LIB_SUFFIX}" CACHE PATH "The subdirectory relative to the install \ + prefix where libraries will be installed (default is /lib${LIB_SUFFIX})" FORCE) +set(BIN_INSTALL_DIR "bin" CACHE PATH "The subdirectory relative to the install prefix where \ + dlls will be installed (default is /bin)" FORCE) diff --git a/sources/shiboken6/data/Shiboken6ToolsMacros.cmake b/sources/shiboken6_generator/data/Shiboken6ToolsMacros.cmake index 2c1a8c786..2c1a8c786 100644 --- a/sources/shiboken6/data/Shiboken6ToolsMacros.cmake +++ b/sources/shiboken6_generator/data/Shiboken6ToolsMacros.cmake diff --git a/sources/shiboken6_generator/generator/CMakeLists.txt b/sources/shiboken6_generator/generator/CMakeLists.txt index 997468f02..33bb41321 100644 --- a/sources/shiboken6_generator/generator/CMakeLists.txt +++ b/sources/shiboken6_generator/generator/CMakeLists.txt @@ -6,11 +6,6 @@ set(package_name "Shiboken6Tools") set(CMAKE_AUTOMOC ON) -if(NOT (Qt${QT_MAJOR_VERSION}Core_FOUND AND Python_Interpreter_FOUND)) - message(WARNING "Some dependencies were not found: shiboken6 generator compilation disabled!") - return() -endif() - set(shiboken6_SRC defaultvalue.cpp defaultvalue.h generator.cpp generator.h @@ -60,6 +55,10 @@ if (NOT DISABLE_DOCSTRINGS) target_compile_definitions(shiboken6 PUBLIC DOCSTRINGS_ENABLED QT_LEAN_HEADERS=1) endif() +# TODO: We are not actually using the tool_wrapper, but we need to make sure +# the properties for the tool are properly set +shiboken_get_tool_shell_wrapper(shiboken tool_wrapper) + configure_file(shibokenconfig.h.in "${CMAKE_CURRENT_BINARY_DIR}/shibokenconfig.h" @ONLY) install(TARGETS shiboken6 @@ -103,7 +102,7 @@ install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/../shiboken_tool.py # Use absolute path instead of relative path, to avoid ninja build errors due to # duplicate file dependency inconsistency. -set(shiboken_version_relative_path "${CMAKE_CURRENT_SOURCE_DIR}/../shiboken_version.py") +set(shiboken_version_relative_path "${CMAKE_CURRENT_SOURCE_DIR}/../../shiboken6/shiboken_version.py") get_filename_component(shiboken_version_path ${shiboken_version_relative_path} ABSOLUTE) configure_file("${shiboken_version_path}" "${CMAKE_CURRENT_BINARY_DIR}/_git_shiboken_generator_version.py" @ONLY) diff --git a/sources/shiboken6_generator/tests/CMakeLists.txt b/sources/shiboken6_generator/tests/CMakeLists.txt new file mode 100644 index 000000000..f71467c87 --- /dev/null +++ b/sources/shiboken6_generator/tests/CMakeLists.txt @@ -0,0 +1,11 @@ +cmake_minimum_required(VERSION 3.18) + +# dumpcodemodel depends on apiextractor which is not cross-built. +add_subdirectory(dumpcodemodel) + +# FIXME Skipped until add an option to choose the generator +# add_subdirectory(test_generator) + +if (NOT APIEXTRACTOR_DOCSTRINGS_DISABLED) + add_subdirectory(qtxmltosphinxtest) +endif() diff --git a/sources/shiboken6_generator/tests/dumpcodemodel/CMakeLists.txt b/sources/shiboken6_generator/tests/dumpcodemodel/CMakeLists.txt index e7dbef961..8b71389f1 100644 --- a/sources/shiboken6_generator/tests/dumpcodemodel/CMakeLists.txt +++ b/sources/shiboken6_generator/tests/dumpcodemodel/CMakeLists.txt @@ -3,6 +3,8 @@ add_executable(dumpcodemodel main.cpp) +find_package(Qt6 COMPONENTS Core) + target_include_directories(dumpcodemodel PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} diff --git a/sources/shiboken6_generator/tests/qtxmltosphinx/CMakeLists.txt b/sources/shiboken6_generator/tests/qtxmltosphinx/CMakeLists.txt index 4a200becd..489fbebfa 100644 --- a/sources/shiboken6_generator/tests/qtxmltosphinx/CMakeLists.txt +++ b/sources/shiboken6_generator/tests/qtxmltosphinx/CMakeLists.txt @@ -11,8 +11,9 @@ set(CMAKE_AUTOMOC ON) find_package(Qt6 COMPONENTS Core) -set(generator_src_dir ${CMAKE_CURRENT_SOURCE_DIR}/../../generator) -set(api_extractor_src_dir ${CMAKE_CURRENT_SOURCE_DIR}/../../ApiExtractor) +set(shiboken_generator_src_dir ${CMAKE_CURRENT_SOURCE_DIR}/../../../shiboken6_generator) +set(generator_src_dir ${shiboken_generator_src_dir}/generator) +set(api_extractor_src_dir ${shiboken_generator_src_dir}/ApiExtractor) set(qtxmltosphinx_SRC ${generator_src_dir}/qtdoc/qtxmltosphinx.cpp diff --git a/sources/shiboken6_generator/tests/qtxmltosphinxtest/CMakeLists.txt b/sources/shiboken6_generator/tests/qtxmltosphinxtest/CMakeLists.txt index 109ab288e..cb170efe6 100644 --- a/sources/shiboken6_generator/tests/qtxmltosphinxtest/CMakeLists.txt +++ b/sources/shiboken6_generator/tests/qtxmltosphinxtest/CMakeLists.txt @@ -10,8 +10,9 @@ set(CMAKE_AUTOMOC ON) find_package(Qt6 COMPONENTS Core) find_package(Qt6 COMPONENTS Test) -set(generator_src_dir ${CMAKE_CURRENT_SOURCE_DIR}/../../generator) -set(api_extractor_src_dir ${CMAKE_CURRENT_SOURCE_DIR}/../../ApiExtractor) +set(shiboken_generator_src_dir ${CMAKE_CURRENT_SOURCE_DIR}/../../../shiboken6_generator) +set(generator_src_dir ${shiboken_generator_src_dir}/generator) +set(api_extractor_src_dir ${shiboken_generator_src_dir}/ApiExtractor) set(qtxmltosphinxtest_SRC ${generator_src_dir}/qtdoc/qtxmltosphinx.cpp |
