From 89a0ed100977a86f12ce0837b4d7787b88f09922 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Thu, 1 Apr 2021 23:59:55 -0700 Subject: [PATCH 1/3] Allow qrandom_p.h to be included by more than one .cpp in QtCore I thought we could use C++17 inline variables, but those can't be used across DLL boundaries: qrandom_p.h:75:48: error: definition of 'QBasicAtomicInteger qt_randomdevice_control' is marked 'dllimport' Change-Id: Id2983978ad544ff79911fffd1671f857587ef2fb Reviewed-by: Giuseppe D'Angelo --- src/corelib/global/qrandom.cpp | 4 ++++ src/corelib/global/qrandom_p.h | 4 +--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/corelib/global/qrandom.cpp b/src/corelib/global/qrandom.cpp index 6db8121028a..c978228094c 100644 --- a/src/corelib/global/qrandom.cpp +++ b/src/corelib/global/qrandom.cpp @@ -92,6 +92,10 @@ enum { FillBufferNoexcept = true }; +#if defined(QT_BUILD_INTERNAL) +QBasicAtomicInteger qt_randomdevice_control = Q_BASIC_ATOMIC_INITIALIZER(0U); +#endif + struct QRandomGenerator::SystemGenerator { #if QT_CONFIG(getentropy) diff --git a/src/corelib/global/qrandom_p.h b/src/corelib/global/qrandom_p.h index 052aef262ef..7e228b3fde4 100644 --- a/src/corelib/global/qrandom_p.h +++ b/src/corelib/global/qrandom_p.h @@ -71,9 +71,7 @@ enum RNGType { MersenneTwister = 1 }; -#if defined(QT_BUILD_INTERNAL) && defined(QT_BUILD_CORE_LIB) -Q_CORE_EXPORT QBasicAtomicInteger qt_randomdevice_control = Q_BASIC_ATOMIC_INITIALIZER(0U); -#elif defined(QT_BUILD_INTERNAL) +#if defined(QT_BUILD_INTERNAL) extern Q_CORE_EXPORT QBasicAtomicInteger qt_randomdevice_control; #else static const struct From cbdce59cd24861210a01fa9f319607b3a538ebbb Mon Sep 17 00:00:00 2001 From: Alexey Edelev Date: Thu, 25 Mar 2021 11:10:47 +0100 Subject: [PATCH 2/3] Add the SIMULATE_IN_SOURCE argument to _qt_internal_test_expect_pass test_QFINDTESTDATA builds the project in the source tree, this is necessary because the test requires relative paths to the source file names. This function could be useful for other tests, so it makes sense to extend the _qt_internal_test_expect_pass/fail macros to support build in the source tree. Note that, the SIMULATE_IN_SOURCE argument doesn't build the test in the existing source tree, but copies source files to the build tree first to do not litter the source directory. Change-Id: I16e790d74be2a0c5ca0593e0f88580dbe09882b9 Reviewed-by: Alexandru Croitor --- src/corelib/Qt6CTestMacros.cmake | 91 +++++++++++++++++++++++++------- tests/auto/cmake/CMakeLists.txt | 22 ++------ 2 files changed, 74 insertions(+), 39 deletions(-) diff --git a/src/corelib/Qt6CTestMacros.cmake b/src/corelib/Qt6CTestMacros.cmake index 5a96e15ea63..4e1abe904ca 100644 --- a/src/corelib/Qt6CTestMacros.cmake +++ b/src/corelib/Qt6CTestMacros.cmake @@ -113,44 +113,95 @@ function(_qt_internal_set_up_test_run_environment testname) endfunction() -# Checks if the test project can be built successfully. +# Checks if the test project can be built successfully. Arguments: +# +# SIMULATE_IN_SOURCE: If the option is specified, the function copies sources of the tests to the +# CMAKE_CURRENT_BINARY_DIR directory, creates internal build directory in the +# copied sources and uses this directory to build and test the project. +# This makes possible to have relative paths to the source files in the +# generated ninja rules. +# +# BINARY: Path to the test artifact that will be executed after the build is complete. If a +# relative path is specified, it will be counted from the build directory. # # 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;TESTNAME" "BUILD_OPTIONS" ${ARGN}) - + cmake_parse_arguments(_ARGS "SIMULATE_IN_SOURCE" "BINARY;TESTNAME" "BUILD_OPTIONS" ${ARGN}) if(_ARGS_TESTNAME) set(testname "${_ARGS_TESTNAME}") else() string(REPLACE "(" "_" testname "${_dir}") string(REPLACE ")" "_" testname "${testname}") + string(REPLACE "/" "_" testname "${testname}") endif() - set(__expect_pass__prefixes "${CMAKE_PREFIX_PATH}") - string(REPLACE ";" "\;" __expect_pass__prefixes "${__expect_pass__prefixes}") + set(__expect_pass_prefixes "${CMAKE_PREFIX_PATH}") + string(REPLACE ";" "\;" __expect_pass_prefixes "${__expect_pass_prefixes}") - set(ctest_command_args - --build-and-test - "${CMAKE_CURRENT_SOURCE_DIR}/${_dir}" - "${CMAKE_CURRENT_BINARY_DIR}/${_dir}" - --build-config "${CMAKE_BUILD_TYPE}" - --build-generator "${CMAKE_GENERATOR}" - --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) - _qt_internal_set_up_test_run_environment("${testname}") - endif() + set(__expect_pass_build_dir "${CMAKE_CURRENT_BINARY_DIR}/${_dir}") + set(__expect_pass_source_dir "${CMAKE_CURRENT_SOURCE_DIR}/${_dir}") + if(_ARGS_SIMULATE_IN_SOURCE) + set(__expect_pass_in_source_build_dir "${CMAKE_CURRENT_BINARY_DIR}/in_source") + set(__expect_pass_build_dir "${__expect_pass_in_source_build_dir}/${_dir}/build") + set(__expect_pass_source_dir "${__expect_pass_in_source_build_dir}/${_dir}") + + unset(__expect_pass_in_source_build_dir) + endif() + + if(_ARGS_BINARY AND NOT IS_ABSOLUTE "${_ARGS_BINARY}") + set(_ARGS_BINARY "${__expect_pass_build_dir}/${_ARGS_BINARY}") + endif() + + if(_ARGS_SIMULATE_IN_SOURCE) + add_test(NAME ${testname}_cleanup + COMMAND ${CMAKE_COMMAND} -E remove_directory "${__expect_pass_source_dir}" + ) + set_tests_properties(${testname}_cleanup PROPERTIES + FIXTURES_SETUP "${testname}SIMULATE_IN_SOURCE_FIXTURE" + ) + add_test(${testname}_copy_sources ${CMAKE_COMMAND} -E copy_directory + "${CMAKE_CURRENT_SOURCE_DIR}/${_dir}" "${__expect_pass_source_dir}" + ) + set_tests_properties(${testname}_copy_sources PROPERTIES + FIXTURES_SETUP "${testname}SIMULATE_IN_SOURCE_FIXTURE" + DEPENDS ${testname}_cleanup + ) + endif() + + set(ctest_command_args + --build-and-test + "${__expect_pass_source_dir}" + "${__expect_pass_build_dir}" + --build-config "${CMAKE_BUILD_TYPE}" + --build-generator "${CMAKE_GENERATOR}" + --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_SIMULATE_IN_SOURCE) + set_tests_properties(${testname} PROPERTIES + FIXTURES_REQUIRED "${testname}SIMULATE_IN_SOURCE_FIXTURE") + endif() + + if(_ARGS_BINARY) + _qt_internal_set_up_test_run_environment("${testname}") + endif() + + unset(__expect_pass_source_dir) + unset(__expect_pass_build_dir) + unset(__expect_pass_prefixes) endmacro() # Checks if the build of the test project fails. # This test passes if the test project fails either at the # configuring or build steps. +# Arguments: See _qt_internal_test_expect_pass macro(_qt_internal_test_expect_fail) _qt_internal_test_expect_pass(${ARGV}) set_tests_properties(${testname} PROPERTIES WILL_FAIL TRUE) diff --git a/tests/auto/cmake/CMakeLists.txt b/tests/auto/cmake/CMakeLists.txt index b43aa8f0a6b..4fb6c24d8d2 100644 --- a/tests/auto/cmake/CMakeLists.txt +++ b/tests/auto/cmake/CMakeLists.txt @@ -108,26 +108,10 @@ _qt_internal_test_expect_pass(test_platform_defs_include) _qt_internal_test_expect_pass(test_qtmainwin_library) if (CMAKE_GENERATOR STREQUAL Ninja AND UNIX AND NOT WIN32) - set(qfindtestdata_build_dir "${CMAKE_CURRENT_SOURCE_DIR}/test_QFINDTESTDATA/build") - add_test(test_QFINDTESTDATA ${CMAKE_CTEST_COMMAND} - --build-and-test - "${CMAKE_CURRENT_SOURCE_DIR}/test_QFINDTESTDATA" - # Build in a subdir of the source dir. - # This causes Ninja to use relative paths. - "${qfindtestdata_build_dir}" - --build-config "${CMAKE_BUILD_TYPE}" - --build-generator "${CMAKE_GENERATOR}" - --build-makeprogram "${CMAKE_MAKE_PROGRAM}" - --build-options "-DCMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH}" ${BUILD_OPTIONS_LIST} + _qt_internal_test_expect_pass(test_QFINDTESTDATA + BINARY "tests/test_QFINDTESTDATA" + SIMULATE_IN_SOURCE ) - set_tests_properties(test_QFINDTESTDATA PROPERTIES FIXTURES_SETUP QFINDTESTDATA) - - add_test(NAME run_test_QFINDTESTDATA COMMAND sh -c "cd \"${qfindtestdata_build_dir}/tests\" && ./test_QFINDTESTDATA -v2") - set_tests_properties(run_test_QFINDTESTDATA PROPERTIES FIXTURES_REQUIRED QFINDTESTDATA) - - # source dir should be untouched by build, so remove build results - add_test(NAME cleanup_test_QFINDTESTDATA COMMAND sh -c "rm -rf \"${qfindtestdata_build_dir}\"") - set_tests_properties(cleanup_test_QFINDTESTDATA PROPERTIES FIXTURES_CLEANUP QFINDTESTDATA) endif() if (NOT NO_DBUS) From 62e697fd568f6acdae7144a58efa08990eb7d9ab Mon Sep 17 00:00:00 2001 From: Andrey Butirsky Date: Thu, 18 Mar 2021 17:42:51 +0300 Subject: [PATCH 3/3] fix Alt+` shortcut on non-US layouts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Make it possible for non-letter-keys with Latin 1 symbols (`, !, @ etc.) to participate in shortcuts also, when the keys generate national symbols on non-Latin layout. For example, in Russian layout, "`" key generates cyrillic "ё" letter of national alphabet, so shortcuts with the key should still work regardless of the actual layout. Fixes: QTBUG-90611 Change-Id: Id9a505210ff33a94b82511b88c30ef79f3d03913 Reviewed-by: Shawn Rutledge --- src/gui/platform/unix/qxkbcommon.cpp | 12 ++++++------ src/gui/platform/unix/qxkbcommon_p.h | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/gui/platform/unix/qxkbcommon.cpp b/src/gui/platform/unix/qxkbcommon.cpp index 459f6a16bb9..3db84097c77 100644 --- a/src/gui/platform/unix/qxkbcommon.cpp +++ b/src/gui/platform/unix/qxkbcommon.cpp @@ -469,7 +469,7 @@ QList QXkbCommon::toKeysym(QKeyEvent *event) } else if (event->modifiers() & Qt::KeypadModifier) { if (qtKey >= Qt::Key_0 && qtKey <= Qt::Key_9) keysyms.append(XKB_KEY_KP_0 + (qtKey - Qt::Key_0)); - } else if (isLatin(qtKey) && event->text().isUpper()) { + } else if (isLatin1(qtKey) && event->text().isUpper()) { keysyms.append(qtKey); } @@ -521,7 +521,7 @@ int QXkbCommon::keysymToQtKey(xkb_keysym_t keysym, Qt::KeyboardModifiers modifie // With standard shortcuts we should prefer a latin character, this is // for checks like "some qkeyevent == QKeySequence::Copy" to work even // when using for example 'russian' keyboard layout. - if (!QXkbCommon::isLatin(keysym)) { + if (!QXkbCommon::isLatin1(keysym)) { xkb_keysym_t latinKeysym = QXkbCommon::lookupLatinKeysym(state, code); if (latinKeysym != XKB_KEY_NoSymbol) keysym = latinKeysym; @@ -544,7 +544,7 @@ static int keysymToQtKey_internal(xkb_keysym_t keysym, Qt::KeyboardModifiers mod } else if (keysym >= XKB_KEY_KP_0 && keysym <= XKB_KEY_KP_9) { // numeric keypad keys qtKey = Qt::Key_0 + (keysym - XKB_KEY_KP_0); - } else if (QXkbCommon::isLatin(keysym)) { + } else if (QXkbCommon::isLatin1(keysym)) { qtKey = QXkbCommon::qxkbcommon_xkb_keysym_to_upper(keysym); } else { // check if we have a direct mapping @@ -677,7 +677,7 @@ QList QXkbCommon::possibleKeys(xkb_state *state, const QKeyEvent *event, Qt::KeyboardModifiers neededMods = ModsTbl[i]; if ((modifiers & neededMods) == neededMods) { if (i == 8) { - if (isLatin(baseQtKey)) + if (isLatin1(baseQtKey)) continue; // add a latin key as a fall back key sym = lookupLatinKeysym(state, keycode); @@ -732,7 +732,7 @@ void QXkbCommon::verifyHasLatinLayout(xkb_keymap *keymap) for (xkb_layout_index_t layout = 0; layout < layoutCount; ++layout) { for (xkb_keycode_t code = minKeycode; code < maxKeycode; ++code) { xkb_keymap_key_get_syms_by_level(keymap, code, layout, 0, &keysyms); - if (keysyms && isLatin(keysyms[0])) + if (keysyms && isLatin1(keysyms[0])) nrLatinKeys++; if (nrLatinKeys > 10) // arbitrarily chosen threshold return; @@ -765,7 +765,7 @@ xkb_keysym_t QXkbCommon::lookupLatinKeysym(xkb_state *state, xkb_keycode_t keyco xkb_level_index_t level = xkb_state_key_get_level(state, keycode, layout); if (xkb_keymap_key_get_syms_by_level(keymap, keycode, layout, level, &syms) != 1) continue; - if (isLatin(syms[0])) { + if (isLatin1(syms[0])) { sym = syms[0]; break; } diff --git a/src/gui/platform/unix/qxkbcommon_p.h b/src/gui/platform/unix/qxkbcommon_p.h index d5fa47d4fe1..197268dbc11 100644 --- a/src/gui/platform/unix/qxkbcommon_p.h +++ b/src/gui/platform/unix/qxkbcommon_p.h @@ -94,8 +94,8 @@ public: static void verifyHasLatinLayout(xkb_keymap *keymap); static xkb_keysym_t lookupLatinKeysym(xkb_state *state, xkb_keycode_t keycode); - static bool isLatin(xkb_keysym_t sym) { - return ((sym >= 'a' && sym <= 'z') || (sym >= 'A' && sym <= 'Z')); + static bool isLatin1(xkb_keysym_t sym) { + return sym <= 0xff; } static bool isKeypad(xkb_keysym_t sym) { return sym >= XKB_KEY_KP_Space && sym <= XKB_KEY_KP_9;