From d15bfba176f7e6c616f299e82adfde148b3f26d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20L=C3=B6hning?= Date: Fri, 26 Mar 2021 10:23:59 +0100 Subject: [PATCH 1/6] Explicitly set enums' type to avoid undefined behavior Fixes oss-fuzz issue 31022. Fixes: QTBUG-92159 Pick-to: 6.1 Change-Id: I8f0dfbe0e198f9ac43754758d18db1f0842d6eae Reviewed-by: Thiago Macieira --- src/corelib/io/qurl.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/corelib/io/qurl.h b/src/corelib/io/qurl.h index a78fbfcd3f9..f777a1a6294 100644 --- a/src/corelib/io/qurl.h +++ b/src/corelib/io/qurl.h @@ -130,7 +130,7 @@ public: }; // encoding / toString values - enum UrlFormattingOption { + enum UrlFormattingOption : unsigned int { None = 0x0, RemoveScheme = 0x1, RemovePassword = 0x2, @@ -147,7 +147,7 @@ public: NormalizePathSegments = 0x1000 }; - enum ComponentFormattingOption { + enum ComponentFormattingOption : unsigned int { PrettyDecoded = 0x000000, EncodeSpaces = 0x100000, EncodeUnicode = 0x200000, From e9ae8c2b0c2f4d983efe5b0317c95498368bc285 Mon Sep 17 00:00:00 2001 From: Volker Hilsheimer Date: Tue, 6 Apr 2021 17:04:37 +0200 Subject: [PATCH 2/6] Fusion style: don't use large icons in QLineEdit Partly revert 24226bb5f595581a239356c18a338783a85349ca by falling through to the QCommonStyle implementation, which defaults to PM_SmallIconSize. Fixes: QTBUG-92460 Change-Id: I82f99e98640a962577fd94556bef04f4da5789e7 Reviewed-by: Friedemann Kleint --- src/widgets/styles/qfusionstyle.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/widgets/styles/qfusionstyle.cpp b/src/widgets/styles/qfusionstyle.cpp index 51cd5109a0d..5772c7d4c48 100644 --- a/src/widgets/styles/qfusionstyle.cpp +++ b/src/widgets/styles/qfusionstyle.cpp @@ -3045,9 +3045,6 @@ int QFusionStyle::pixelMetric(PixelMetric metric, const QStyleOption *option, co case PM_ListViewIconSize: val = 24; break; - case PM_LineEditIconSize: - val = 24; - break; case PM_DialogButtonsSeparator: case PM_ScrollBarSliderMin: val = 26; From 1e8b085f8c8bce5d69852df4c4b72d30fcffe793 Mon Sep 17 00:00:00 2001 From: Volker Hilsheimer Date: Tue, 6 Apr 2021 17:00:35 +0200 Subject: [PATCH 3/6] Fix return type of QMetaType::sizeOf in documentation Pick-to: 6.1 Change-Id: I6f5a866fa83f0e2720d62c5170c9283997b31a7f Reviewed-by: Fabian Kosmale --- src/corelib/kernel/qmetatype.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/corelib/kernel/qmetatype.cpp b/src/corelib/kernel/qmetatype.cpp index 9554a844f1c..43e633faafb 100644 --- a/src/corelib/kernel/qmetatype.cpp +++ b/src/corelib/kernel/qmetatype.cpp @@ -518,7 +518,7 @@ int QMetaType::idHelper() const } /*! - \fn constexpr bool QMetaType::sizeOf() const + \fn constexpr qsizetype QMetaType::sizeOf() const \since 5.0 Returns the size of the type in bytes (i.e. sizeof(T), From ae70011377900d0d459a6f5cecb3d8d9608f7113 Mon Sep 17 00:00:00 2001 From: Alexey Edelev Date: Tue, 6 Apr 2021 16:01:51 +0200 Subject: [PATCH 4/6] Remove use of qt_internal_module_info from qt_internal_add_plugin Plugin targets don't fit the requirements of the module but use the function associated to the module. The purpose of using qt_internal_module_info is to get the path to the top-level include directory. So there is no point in breaking the encapsulation rules to get a well-known directory. Change-Id: If3d2a31d4ec186929e3d662a79a1ae9eac988d1a Reviewed-by: Alexandru Croitor --- cmake/QtPluginHelpers.cmake | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/cmake/QtPluginHelpers.cmake b/cmake/QtPluginHelpers.cmake index 86d59cb8ab9..0787e31e06f 100644 --- a/cmake/QtPluginHelpers.cmake +++ b/cmake/QtPluginHelpers.cmake @@ -23,8 +23,6 @@ endmacro() # A CMake target is created with the given target. The TYPE parameter is needed to place the # plugin into the correct plugins/ sub-directory. function(qt_internal_add_plugin target) - qt_internal_module_info(module "${target}") - qt_internal_set_qt_known_plugins("${QT_KNOWN_PLUGINS}" "${target}") _qt_internal_get_add_plugin_keywords( @@ -230,7 +228,7 @@ function(qt_internal_add_plugin target) "${CMAKE_CURRENT_SOURCE_DIR}" "${CMAKE_CURRENT_BINARY_DIR}" # For the syncqt headers - "$" + "$" ${arg_INCLUDE_DIRECTORIES} ) From d0c2425d791edd75e35cce65ddbcfaab9a7f16ed Mon Sep 17 00:00:00 2001 From: Alexandru Croitor Date: Tue, 6 Apr 2021 13:06:11 +0200 Subject: [PATCH 5/6] CMake: Choose better defaults for qt_add_plugin STATIC/SHARED There was a recent behavior change where the public CMake API qt_add_plugin API took into account the value of BUILD_SHARED_LIBS to decide whether the plugin should be a static or shared library. Instead, use the following new behavior - If no explicit option STATIC / SHARED option is passed, default to whatever flavor Qt was built as. Aka if Qt was configured with -shared, qt_add_plugin defaults to creating shared plugins. If it's a -static Qt, create static plugins. - If an explicit STATIC / SHARED option is set, override the default computed value with the given value. As a result BUILD_SHARED_LIBS does not affect Qt plugins anymore. This is more in line with Qt expectations. Add SHARED as a new valid option to pass to qt_add_plugin (it wasn't before). Add tests to check for the above behavior. Amends aa4a1006cbccbc180c600f9b4dc9e882bb5ed5ca Pick-to: 6.1 Fixes: QTBUG-92361 Task-number: QTBUG-88763 Change-Id: Iae806024ddd5cf10cfe58ddbcebd2818084b0bd7 Reviewed-by: Joerg Bornemann --- CMakeLists.txt | 4 +++ src/corelib/Qt6CTestMacros.cmake | 16 ++++++++-- src/corelib/Qt6CoreMacros.cmake | 23 +++++++++++++- tests/auto/cmake/CMakeLists.txt | 2 ++ .../test_plugin_shared_static_flavor.cmake | 24 ++++++++++++++ .../CMakeLists.txt | 31 +++++++++++++++++++ 6 files changed, 96 insertions(+), 4 deletions(-) create mode 100644 tests/auto/cmake/test_plugin_shared_static_flavor.cmake create mode 100644 tests/auto/cmake/test_plugin_shared_static_flavor/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index 18eaf95c509..6d7a8ec9b77 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -71,6 +71,10 @@ if(NOT QT_BUILD_STANDALONE_TESTS) option(BUILD_SHARED_LIBS "Build Qt statically or dynamically" ON) set(QT_BUILD_SHARED_LIBS ${BUILD_SHARED_LIBS}) + # This variable is also set in Qt6CoreConfigExtras.cmake, but it's not loaded when building + # qtbase. Set it here so qt_add_plugin can compute the proper plugin flavor. + set(QT6_IS_SHARED_LIBS_BUILD ${BUILD_SHARED_LIBS}) + ## Should this Qt be built with Werror? option(WARNINGS_ARE_ERRORS "Build Qt with warnings as errors" ${FEATURE_developer_build}) diff --git a/src/corelib/Qt6CTestMacros.cmake b/src/corelib/Qt6CTestMacros.cmake index 9062985ac0b..5a96e15ea63 100644 --- a/src/corelib/Qt6CTestMacros.cmake +++ b/src/corelib/Qt6CTestMacros.cmake @@ -114,10 +114,19 @@ function(_qt_internal_set_up_test_run_environment testname) endfunction() # Checks if the test project can be built successfully. +# +# TESTNAME: a custom test name to use instead of the one derived from the source directory name +# BUILD_OPTIONS: a list of -D style CMake definitions to pass to ctest's --build-options (which +# are ultimately passed to the CMake invocation of the test project) macro(_qt_internal_test_expect_pass _dir) - cmake_parse_arguments(_ARGS "" "BINARY" "" ${ARGN}) - string(REPLACE "(" "_" testname "${_dir}") - string(REPLACE ")" "_" testname "${testname}") + cmake_parse_arguments(_ARGS "" "BINARY;TESTNAME" "BUILD_OPTIONS" ${ARGN}) + + if(_ARGS_TESTNAME) + set(testname "${_ARGS_TESTNAME}") + else() + string(REPLACE "(" "_" testname "${_dir}") + string(REPLACE ")" "_" testname "${testname}") + endif() set(__expect_pass__prefixes "${CMAKE_PREFIX_PATH}") string(REPLACE ";" "\;" __expect_pass__prefixes "${__expect_pass__prefixes}") @@ -131,6 +140,7 @@ macro(_qt_internal_test_expect_pass _dir) --build-makeprogram "${CMAKE_MAKE_PROGRAM}" --build-project "${_dir}" --build-options "-DCMAKE_PREFIX_PATH=${__expect_pass__prefixes}" ${BUILD_OPTIONS_LIST} + ${_ARGS_BUILD_OPTIONS} --test-command ${_ARGS_BINARY}) add_test(${testname} ${CMAKE_CTEST_COMMAND} ${ctest_command_args}) if(_ARGS_BINARY) diff --git a/src/corelib/Qt6CoreMacros.cmake b/src/corelib/Qt6CoreMacros.cmake index 54edcd102f6..d6ad9dab3d8 100644 --- a/src/corelib/Qt6CoreMacros.cmake +++ b/src/corelib/Qt6CoreMacros.cmake @@ -1429,6 +1429,7 @@ endfunction() macro(_qt_internal_get_add_plugin_keywords option_args single_args multi_args) set(${option_args} STATIC + SHARED ) set(${single_args} TYPE @@ -1461,7 +1462,27 @@ function(qt6_add_plugin target) unset(arg_CLASSNAME) endif() - if (arg_STATIC OR NOT BUILD_SHARED_LIBS) + if(arg_STATIC AND arg_SHARED) + message(FATAL_ERROR + "Both STATIC and SHARED options were given. Only one of the two should be used." + ) + endif() + + # If no explicit STATIC/SHARED option is set, default to the flavor of the Qt build. + if(QT6_IS_SHARED_LIBS_BUILD) + set(create_static_plugin FALSE) + else() + set(create_static_plugin TRUE) + endif() + + # Explicit option takes priority over the computed default. + if(arg_STATIC) + set(create_static_plugin TRUE) + elseif(arg_SHARED) + set(create_static_plugin FALSE) + endif() + + if (create_static_plugin) add_library(${target} STATIC) target_compile_definitions(${target} PRIVATE QT_STATICPLUGIN) else() diff --git a/tests/auto/cmake/CMakeLists.txt b/tests/auto/cmake/CMakeLists.txt index 317541f984a..b43aa8f0a6b 100644 --- a/tests/auto/cmake/CMakeLists.txt +++ b/tests/auto/cmake/CMakeLists.txt @@ -226,3 +226,5 @@ _qt_internal_test_expect_pass(test_versionless_targets) _qt_internal_test_expect_pass(test_add_resources_binary_generated BINARY test_add_resources_binary_generated) + +include(test_plugin_shared_static_flavor.cmake) diff --git a/tests/auto/cmake/test_plugin_shared_static_flavor.cmake b/tests/auto/cmake/test_plugin_shared_static_flavor.cmake new file mode 100644 index 00000000000..a906bfebbc9 --- /dev/null +++ b/tests/auto/cmake/test_plugin_shared_static_flavor.cmake @@ -0,0 +1,24 @@ +_qt_internal_test_expect_pass(test_plugin_shared_static_flavor + TESTNAME test_plugin_flavor_static + BUILD_OPTIONS + "-DPLUGIN_OPTIONS=STATIC" + "-DEXPECTED_PLUGIN_TARGET_TYPE=STATIC_LIBRARY") + +_qt_internal_test_expect_pass(test_plugin_shared_static_flavor + TESTNAME test_plugin_flavor_shared + BUILD_OPTIONS + "-DPLUGIN_OPTIONS=SHARED" + "-DEXPECTED_PLUGIN_TARGET_TYPE=MODULE_LIBRARY") + +if(QT6_IS_SHARED_LIBS_BUILD) + set(expected_plugin_target_type "MODULE_LIBRARY") +else() + set(expected_plugin_target_type "STATIC_LIBRARY") +endif() + +# Check default computed value when no explicit option is set. +_qt_internal_test_expect_pass(test_plugin_shared_static_flavor + TESTNAME test_plugin_flavor_derived_from_qt_type + BUILD_OPTIONS + "-DPLUGIN_OPTIONS=" + "-DEXPECTED_PLUGIN_TARGET_TYPE=${expected_plugin_target_type}") diff --git a/tests/auto/cmake/test_plugin_shared_static_flavor/CMakeLists.txt b/tests/auto/cmake/test_plugin_shared_static_flavor/CMakeLists.txt new file mode 100644 index 00000000000..12d7affc516 --- /dev/null +++ b/tests/auto/cmake/test_plugin_shared_static_flavor/CMakeLists.txt @@ -0,0 +1,31 @@ +cmake_minimum_required(VERSION 3.14) + +project(test_plugin_flavor) + +if (EXISTS "${CMAKE_CURRENT_LIST_DIR}/FindPackageHints.cmake") + include("${CMAKE_CURRENT_LIST_DIR}/FindPackageHints.cmake") +endif() + +find_package(Qt6Core REQUIRED HINTS ${Qt6Tests_PREFIX_PATH}) + +qt6_add_plugin(test_plugin ${PLUGIN_OPTIONS}) + +set(plugin_source_path "${CMAKE_CURRENT_BINARY_DIR}/plugin.cpp") +file(GENERATE OUTPUT "${plugin_source_path}" CONTENT "int foo() {return 0;}") +target_sources(test_plugin PRIVATE "${plugin_source_path}") + +get_target_property(plugin_target_type test_plugin TYPE) + +if(NOT EXPECTED_PLUGIN_TARGET_TYPE) + message(FATAL_ERROR "No value given for EXPECTED_PLUGIN_TARGET_TYPE variable") +endif() + +if(NOT plugin_target_type STREQUAL "${EXPECTED_PLUGIN_TARGET_TYPE}") + set(info "") + list(APPEND info "PLUGIN_OPTIONS: ${PLUGIN_OPTIONS}") + list(APPEND info "QT6_IS_SHARED_LIBS_BUILD: ${QT6_IS_SHARED_LIBS_BUILD}") + list(APPEND info "EXPECTED_PLUGIN_TARGET_TYPE: ${EXPECTED_PLUGIN_TARGET_TYPE}") + list(JOIN info "\n" info) + message(FATAL_ERROR + "Computed plugin target type '${plugin_target_type}' did not match expected type '${EXPECTED_PLUGIN_TARGET_TYPE}'\n${info}") +endif() From 20db8dbeeb808edce683e34de10498ee2cdda0fc Mon Sep 17 00:00:00 2001 From: Joerg Bornemann Date: Tue, 6 Apr 2021 15:19:20 +0200 Subject: [PATCH 6/6] androiddeployqt: Fix the fallback location of rcc Now, that rcc lives in libexec, we need to assume the location of rcc to be "bin" on Windows and "libexec" elsewhere. Pick-to: 6.1 Fixes: QTBUG-92245 Change-Id: Idb81a5d02bae9ca3254e7590140a128500572b07 Reviewed-by: Alexandru Croitor --- src/tools/androiddeployqt/main.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/tools/androiddeployqt/main.cpp b/src/tools/androiddeployqt/main.cpp index c7b85071b04..2d660ff8445 100644 --- a/src/tools/androiddeployqt/main.cpp +++ b/src/tools/androiddeployqt/main.cpp @@ -1785,6 +1785,15 @@ bool readDependenciesFromElf(Options *options, return true; } +QString defaultLibexecDir() +{ +#ifdef Q_OS_WIN32 + return QStringLiteral("bin"); +#else + return QStringLiteral("libexec"); +#endif +} + bool goodToCopy(const Options *options, const QString &file, QStringList *unmetDependencies); bool scanImports(Options *options, QSet *usedDependencies) @@ -1985,7 +1994,8 @@ bool createRcc(const Options &options) if (!options.rccBinaryPath.isEmpty()) { rcc = options.rccBinaryPath; } else { - rcc = options.qtInstallDirectory + QLatin1String("/bin/rcc"); + rcc = options.qtInstallDirectory + QLatin1Char('/') + defaultLibexecDir() + + QLatin1String("/rcc"); } #if defined(Q_OS_WIN32)