From fc058479b1d0ab8498b23a68dcbb56be1b38c793 Mon Sep 17 00:00:00 2001 From: Alexander Lohnau Date: Sat, 7 Sep 2024 14:25:45 +0200 Subject: [PATCH] Only look for Qt5/Qt6 installs if respective CI job is running We may have a qt6 installation even on a Qt5 image But in any case, we should only run them on the dedicated im age and not waste CI time otherwise --- ClazyTests.generated.cmake | 8 +++++++- dev-scripts/generate.py | 8 +++++++- tests/run_tests.py | 22 ++++++++++++++-------- 3 files changed, 28 insertions(+), 10 deletions(-) diff --git a/ClazyTests.generated.cmake b/ClazyTests.generated.cmake index 49b0f69e..9babc7c5 100644 --- a/ClazyTests.generated.cmake +++ b/ClazyTests.generated.cmake @@ -1,7 +1,13 @@ # This file was autogenerated by running: ./dev-scripts/generate.py --generate +if ($ENV{CI_JOB_NAME_SLUG} MATCHES "qt5") + set(TEST_VERSION_OPTION "--qt-versions=5") +elseif($ENV{CI_JOB_NAME_SLUG} MATCHES "qt6") + set(TEST_VERSION_OPTION "--qt-versions=6") +endif() + macro(add_clazy_test name) - add_test(NAME ${name} COMMAND python3 run_tests.py ${name} --verbose WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/tests/) + add_test(NAME ${name} COMMAND python3 run_tests.py ${name} --verbose ${TEST_VERSION_OPTION} WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/tests/) if (CLANG_EXECUTABLE_PATH) set(CLANG_CXX_TEST "CLANGXX=${CLANG_EXECUTABLE_PATH};") endif() diff --git a/dev-scripts/generate.py b/dev-scripts/generate.py index 11fc5bfc..a1233698 100755 --- a/dev-scripts/generate.py +++ b/dev-scripts/generate.py @@ -466,8 +466,14 @@ def generate_ctest(checks): filename = clazy_source_path() + 'ClazyTests.generated.cmake' contents = """# This file was autogenerated by running: ./dev-scripts/generate.py --generate\n +if ($ENV{CI_JOB_NAME_SLUG} MATCHES "qt5") + set(TEST_VERSION_OPTION "--qt-versions=5") +elseif($ENV{CI_JOB_NAME_SLUG} MATCHES "qt6") + set(TEST_VERSION_OPTION "--qt-versions=6") +endif() + macro(add_clazy_test name) - add_test(NAME ${name} COMMAND python3 run_tests.py ${name} --verbose WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/tests/) + add_test(NAME ${name} COMMAND python3 run_tests.py ${name} --verbose ${TEST_VERSION_OPTION} WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/tests/) if (CLANG_EXECUTABLE_PATH) set(CLANG_CXX_TEST "CLANGXX=${CLANG_EXECUTABLE_PATH};") endif() diff --git a/tests/run_tests.py b/tests/run_tests.py index 9fb9d5dc..da54e45a 100755 --- a/tests/run_tests.py +++ b/tests/run_tests.py @@ -457,6 +457,8 @@ parser.add_argument("--only-standalone", action='store_true', help='Only run clazy-standalone') parser.add_argument("--dump-ast", action='store_true', help='Dump a unit-test AST to file') +parser.add_argument("--qt-versions", type=int, choices=[5, 6], nargs='+', default=[5, 6], + help='Specify one or more Qt versions to use (default: 5 and 6)') parser.add_argument( "--exclude", help='Comma separated list of checks to ignore') parser.add_argument("-j", "--jobs", type=int, default=multiprocessing.cpu_count(), @@ -481,10 +483,14 @@ _only_standalone = args.only_standalone _num_threads = args.jobs _lock = threading.Lock() _was_successful = True -_qt6_installation = find_qt_installation( - 6, ["QT_SELECT=6 qmake", "qmake-qt6", "qmake", "qmake6"]) -_qt5_installation = find_qt_installation( - 5, ["QT_SELECT=5 qmake", "qmake-qt5", "qmake", "qmake5"]) +if 6 in args.qt_versions: + _qt6_installation = find_qt_installation(6, ["QT_SELECT=6 qmake", "qmake-qt6", "qmake", "qmake6"]) +else: + _qt6_installation = None +if 5 in args.qt_versions: + _qt5_installation = find_qt_installation(5, ["QT_SELECT=5 qmake", "qmake-qt5", "qmake", "qmake5"]) +else: + _qt5_installation = None _excluded_checks = args.exclude.split(',') if args.exclude is not None else [] # ------------------------------------------------------------------------------- @@ -697,6 +703,8 @@ def run_unit_test(test, is_standalone, cppStandard, qt_major_version): return True qt = qt_installation(qt_major_version) + if qt == None: + return True # silently skip if _verbose: print("Qt major versions required by the test: " + str(test.qt_major_versions)) @@ -709,14 +717,12 @@ def run_unit_test(test, is_standalone, cppStandard, qt_major_version): if qt.int_version < test.minimum_qt_version or qt.int_version > test.maximum_qt_version or CLANG_VERSION < test.minimum_clang_version: if (_verbose): - print("Skipping " + printableName + - " because required version is not available") + print("Skipping " + printableName + " because required version is not available") return True if test.requires_std_filesystem and not _hasStdFileSystem: if (_verbose): - print("Skipping " + printableName + - " because it requires std::filesystem") + print("Skipping " + printableName + " because it requires std::filesystem") return True if _platform in test.blacklist_platforms: -- GitLab