From a217fa0c223946fbf44592e0e57ce8d68faa8378 Mon Sep 17 00:00:00 2001 From: Christian Kandeler Date: Mon, 18 Sep 2023 16:25:12 +0200 Subject: [PATCH] qbs build: Clean up testing infrastructure - Rename ambiguously named "testsEnabled" property to "withPluginTests" and fix the wrong uses. - Move AutotestRunner out of main project file and into tests.qbs. - Move "withAutotests" property into qtc module. We cannot remove it from the main project file just yet, because some manual tests do not make use of QtcManualTest at the moment. - Do not remove the autotests from the project tree if autotests are disabled. Instead, just disable the products. Change-Id: I74a4cc717d9adbe53d37536b2565111e1617115b Reviewed-by: Christian Stenger --- qbs/imports/QtcAutotest.qbs | 2 ++ qbs/imports/QtcManualtest.qbs | 1 + qbs/imports/QtcPlugin.qbs | 2 +- qbs/imports/QtcTestFiles.qbs | 2 +- qbs/modules/qtc/qtc.qbs | 7 ++-- qtcreator.qbs | 34 +------------------ src/libs/extensionsystem/extensionsystem.qbs | 2 +- src/libs/tracing/tracing.qbs | 2 +- src/plugins/autotest/autotest.qbs | 14 ++------ src/plugins/clangcodemodel/clangcodemodel.qbs | 2 +- src/plugins/clangtools/clangtools.qbs | 2 +- src/plugins/cppeditor/cppeditor.qbs | 4 +-- src/plugins/languageclient/languageclient.qbs | 5 +-- src/plugins/mcusupport/mcusupport.qbs | 8 ++--- .../mesonprojectmanager.qbs | 4 --- .../projectexplorer/projectexplorer.qbs | 4 +-- src/plugins/vcsbase/vcsbase.qbs | 2 +- src/tools/sdktool/sdktool.qbs | 3 -- src/tools/sdktool/sdktoollib.qbs | 6 ++-- tests/auto/auto.qbs | 1 - tests/manual/debugger/simple/simple.qbs | 5 --- .../debugger/simple/simple_test_app.qbs | 1 + .../debugger/simple/simple_test_plugin.qbs | 1 + tests/manual/manual.qbs | 4 +-- tests/manual/widgets/widgets.qbs | 4 --- tests/tests.qbs | 30 +++++++++++++++- 26 files changed, 61 insertions(+), 91 deletions(-) diff --git a/qbs/imports/QtcAutotest.qbs b/qbs/imports/QtcAutotest.qbs index 523f1cdbfd7..3d1f3a50ec6 100644 --- a/qbs/imports/QtcAutotest.qbs +++ b/qbs/imports/QtcAutotest.qbs @@ -2,6 +2,8 @@ import qbs import qbs.FileInfo QtcProduct { + condition: qtc.withAutotests + // This needs to be absolute, because it is passed to one of the source files. destinationDirectory: project.buildDirectory + '/' + FileInfo.relativePath(project.ide_source_tree, sourceDirectory) diff --git a/qbs/imports/QtcManualtest.qbs b/qbs/imports/QtcManualtest.qbs index 0c47bf1c8fa..7a388b81366 100644 --- a/qbs/imports/QtcManualtest.qbs +++ b/qbs/imports/QtcManualtest.qbs @@ -1,6 +1,7 @@ import qbs.FileInfo QtcProduct { + condition: qtc.withAutotests destinationDirectory: project.buildDirectory + '/' + FileInfo.relativePath(project.ide_source_tree, sourceDirectory) targetName: "tst_" + name.split(' ').join("") diff --git a/qbs/imports/QtcPlugin.qbs b/qbs/imports/QtcPlugin.qbs index 8c26050328f..d06f99385e4 100644 --- a/qbs/imports/QtcPlugin.qbs +++ b/qbs/imports/QtcPlugin.qbs @@ -14,7 +14,7 @@ QtcProduct { property stringList pluginRecommends: [] property stringList pluginTestDepends: [] - Depends { name: "Qt.testlib"; condition: qtc.testsEnabled } + Depends { name: "Qt.testlib"; condition: qtc.withPluginTests } Depends { name: "ExtensionSystem" } Depends { name: "pluginjson" } diff --git a/qbs/imports/QtcTestFiles.qbs b/qbs/imports/QtcTestFiles.qbs index e1be695dac0..0dbf377e1f9 100644 --- a/qbs/imports/QtcTestFiles.qbs +++ b/qbs/imports/QtcTestFiles.qbs @@ -1,4 +1,4 @@ Group { name: "Unit tests" - condition: qtc.testsEnabled + condition: qtc.withPluginTests } diff --git a/qbs/modules/qtc/qtc.qbs b/qbs/modules/qtc/qtc.qbs index 73b26adf9e5..eca67fc9d55 100644 --- a/qbs/modules/qtc/qtc.qbs +++ b/qbs/modules/qtc/qtc.qbs @@ -72,7 +72,10 @@ Module { property bool preferSystemSyntaxHighlighting: true - property bool testsEnabled: Environment.getEnv("TEST") || qbs.buildVariant === "debug" + property bool withPluginTests: Environment.getEnv("TEST") || qbs.buildVariant === "debug" + property bool testsEnabled: withPluginTests // TODO: compat, remove + property bool withAutotests: project.withAutotests // FIXME: withPluginTests + property stringList generalDefines: [ "QT_CREATOR", 'IDE_LIBRARY_BASENAME="' + libDirName + '"', @@ -88,6 +91,6 @@ Module { "QT_NO_FOREACH", "QT_DISABLE_DEPRECATED_BEFORE=0x050900", "QT_USE_QSTRINGBUILDER", - ].concat(testsEnabled ? ["WITH_TESTS"] : []) + ].concat(withPluginTests ? ["WITH_TESTS"] : []) .concat(qbs.toolchain.contains("msvc") ? ["_CRT_SECURE_NO_WARNINGS"] : []) } diff --git a/qtcreator.qbs b/qtcreator.qbs index f542f5c5fb5..daa8427b0ef 100644 --- a/qtcreator.qbs +++ b/qtcreator.qbs @@ -1,11 +1,7 @@ -import qbs 1.0 -import qbs.Environment -import qbs.FileInfo - Project { name: "Qt Creator" minimumQbsVersion: "2.0.0" - property bool withAutotests: qbs.buildVariant === "debug" + property bool withAutotests: qbs.buildVariant === "debug" // FIXME: Remove property path ide_source_tree: path property pathList additionalPlugins: [] property pathList additionalLibs: [] @@ -37,32 +33,4 @@ Project { return list; } } - - AutotestRunner { - Depends { name: "Qt.core" } - Depends { name: "qtc" } - environment: { - var env = base; - if (!qbs.hostOS.contains("windows") || !qbs.targetOS.contains("windows")) - return env; - var path = ""; - for (var i = 0; i < env.length; ++i) { - if (env[i].startsWith("PATH=")) { - path = env[i].substring(5); - break; - } - } - var fullQtcInstallDir = FileInfo.joinPaths(qbs.installRoot, qbs.installPrefix); - var fullLibInstallDir = FileInfo.joinPaths(fullQtcInstallDir, qtc.ide_library_path); - var fullPluginInstallDir = FileInfo.joinPaths(fullQtcInstallDir, qtc.ide_plugin_path); - path = Qt.core.binPath + ";" + fullLibInstallDir + ";" + fullPluginInstallDir - + ";" + path; - var arrayElem = "PATH=" + path; - if (i < env.length) - env[i] = arrayElem; - else - env.push(arrayElem); - return env; - } - } } diff --git a/src/libs/extensionsystem/extensionsystem.qbs b/src/libs/extensionsystem/extensionsystem.qbs index 07fc87fd286..8748c27ba69 100644 --- a/src/libs/extensionsystem/extensionsystem.qbs +++ b/src/libs/extensionsystem/extensionsystem.qbs @@ -4,7 +4,7 @@ QtcLibrary { cpp.defines: base.concat(["EXTENSIONSYSTEM_LIBRARY", "IDE_TEST_DIR=\".\""]) Depends { name: "Qt"; submodules: ["core", "widgets"] } - Depends { name: "Qt.testlib"; condition: qtc.testsEnabled } + Depends { name: "Qt.testlib"; condition: qtc.withPluginTests } Depends { name: "Aggregation" } Depends { name: "Utils" } diff --git a/src/libs/tracing/tracing.qbs b/src/libs/tracing/tracing.qbs index d044800f846..6876dccd256 100644 --- a/src/libs/tracing/tracing.qbs +++ b/src/libs/tracing/tracing.qbs @@ -2,7 +2,7 @@ QtcLibrary { name: "Tracing" Depends { name: "Qt"; submodules: ["qml", "quick", "gui"] } - Depends { name: "Qt.testlib"; condition: project.withAutotests } + Depends { name: "Qt.testlib"; condition: qtc.withAutotests } Depends { name: "Utils" } Group { diff --git a/src/plugins/autotest/autotest.qbs b/src/plugins/autotest/autotest.qbs index 90f1728c4ae..9e9625006b6 100644 --- a/src/plugins/autotest/autotest.qbs +++ b/src/plugins/autotest/autotest.qbs @@ -1,5 +1,3 @@ -import qbs - QtcPlugin { name: "AutoTest" @@ -18,16 +16,8 @@ QtcPlugin { "QmakeProjectManager" ] - Depends { - name: "QtSupport" - condition: qtc.testsEnabled - } - - Depends { - name: "Qt.testlib" - condition: qtc.testsEnabled - } - + Depends { name: "QtSupport"; condition: qtc.withPluginTests } + Depends { name: "Qt.testlib"; condition: qtc.withPluginTests } Depends { name: "Qt.widgets" } files: [ diff --git a/src/plugins/clangcodemodel/clangcodemodel.qbs b/src/plugins/clangcodemodel/clangcodemodel.qbs index 903a81147a9..16e4d00035e 100644 --- a/src/plugins/clangcodemodel/clangcodemodel.qbs +++ b/src/plugins/clangcodemodel/clangcodemodel.qbs @@ -10,7 +10,7 @@ QtcPlugin { Depends { name: "CppEditor" } Depends { name: "LanguageClient" } Depends { name: "ProjectExplorer" } - Depends { name: "QtSupport"; condition: qtc.testsEnabled } + Depends { name: "QtSupport"; condition: qtc.withPluginTests } Depends { name: "TextEditor" } Depends { name: "Utils" } diff --git a/src/plugins/clangtools/clangtools.qbs b/src/plugins/clangtools/clangtools.qbs index 5aba1655197..6afa5d026b1 100644 --- a/src/plugins/clangtools/clangtools.qbs +++ b/src/plugins/clangtools/clangtools.qbs @@ -8,7 +8,7 @@ QtcPlugin { Depends { name: "CppEditor" } Depends { name: "Debugger" } Depends { name: "ProjectExplorer" } - Depends { name: "QtSupport"; condition: qtc.testsEnabled } + Depends { name: "QtSupport"; condition: qtc.withPluginTests } Depends { name: "TextEditor" } Depends { name: "Utils" } diff --git a/src/plugins/cppeditor/cppeditor.qbs b/src/plugins/cppeditor/cppeditor.qbs index 2c0ff18dc30..160fd70aee2 100644 --- a/src/plugins/cppeditor/cppeditor.qbs +++ b/src/plugins/cppeditor/cppeditor.qbs @@ -4,7 +4,7 @@ QtcPlugin { name: "CppEditor" Depends { name: "Qt.widgets" } - Depends { condition: project.withAutotests; name: "Qt.testlib" } + Depends { condition: project.withPluginTests; name: "Qt.testlib" } Depends { name: "CPlusPlus" } Depends { name: "Utils" } @@ -233,7 +233,7 @@ QtcPlugin { Group { name: "TestCase" - condition: qtc.testsEnabled || project.withAutotests + condition: qtc.withPluginTests || qtc.withAutotests files: [ "cpptoolstestcase.cpp", "cpptoolstestcase.h", diff --git a/src/plugins/languageclient/languageclient.qbs b/src/plugins/languageclient/languageclient.qbs index bfb29ded282..7f1899927fe 100644 --- a/src/plugins/languageclient/languageclient.qbs +++ b/src/plugins/languageclient/languageclient.qbs @@ -5,10 +5,7 @@ QtcPlugin { name: "LanguageClient" Depends { name: "Qt.core" } - Depends { - name: "Qt.testlib" - condition: qtc.testsEnabled - } + Depends { name: "Qt.testlib"; condition: qtc.withPluginTests } Depends { name: "Utils" } Depends { name: "ProjectExplorer" } diff --git a/src/plugins/mcusupport/mcusupport.qbs b/src/plugins/mcusupport/mcusupport.qbs index 96fea109d75..b14c6a90a23 100644 --- a/src/plugins/mcusupport/mcusupport.qbs +++ b/src/plugins/mcusupport/mcusupport.qbs @@ -5,7 +5,7 @@ QtcPlugin { Depends { name: "Qt.core" } Depends { name: "Qt.widgets" } - Depends { name: "Qt.testlib"; condition: qtc.testsEnabled } + Depends { name: "Qt.testlib"; condition: qtc.withPluginTests } Depends { name: "Utils" } Depends { name: "Core" } @@ -16,7 +16,7 @@ QtcPlugin { Depends { name: "QmlJS" } Depends { name: "QtSupport" } - Depends { name: "qtc_gtest_gmock"; condition: qtc.testsEnabled; required: false } + Depends { name: "qtc_gtest_gmock"; condition: qtc.withPluginTests; required: false } files: [ "mcuabstractpackage.h", @@ -65,7 +65,7 @@ QtcPlugin { ] QtcTestFiles { - condition: qtc.testsEnabled && (qtc_gtest_gmock.hasRepo || qtc_gtest_gmock.externalLibsPresent) + condition: qtc.withPluginTests && (qtc_gtest_gmock.hasRepo || qtc_gtest_gmock.externalLibsPresent) prefix: "test/" files: [ "packagemock.h", @@ -75,7 +75,7 @@ QtcPlugin { } Properties { - condition: qtc.testsEnabled && (qtc_gtest_gmock.hasRepo || qtc_gtest_gmock.externalLibsPresent) + condition: qtc.withPluginTests && (qtc_gtest_gmock.hasRepo || qtc_gtest_gmock.externalLibsPresent) cpp.defines: base.concat(["GOOGLE_TEST_IS_FOUND"]) cpp.includePaths: base.concat([ "." ]) } diff --git a/src/plugins/mesonprojectmanager/mesonprojectmanager.qbs b/src/plugins/mesonprojectmanager/mesonprojectmanager.qbs index c977f8b8283..9167f025b20 100644 --- a/src/plugins/mesonprojectmanager/mesonprojectmanager.qbs +++ b/src/plugins/mesonprojectmanager/mesonprojectmanager.qbs @@ -95,7 +95,6 @@ Project { QtcAutotest { name: "mesonwrapper" - condition: project.withAutotests Depends { name: "Core" } Depends { name: "Utils" } @@ -116,7 +115,6 @@ Project { QtcAutotest { name: "mesoninfoparser" - condition: project.withAutotests Depends { name: "Core" } Depends { name: "Utils" } @@ -138,7 +136,6 @@ Project { QtcAutotest { name: "ninjaparser" - condition: project.withAutotests Depends { name: "Core" } Depends { name: "ProjectExplorer" } @@ -156,7 +153,6 @@ Project { QtcAutotest { name: "mesonparser" - condition: project.withAutotests Depends { name: "Core" } Depends { name: "ProjectExplorer" } diff --git a/src/plugins/projectexplorer/projectexplorer.qbs b/src/plugins/projectexplorer/projectexplorer.qbs index 5f24d9f12da..8f5e7e75f57 100644 --- a/src/plugins/projectexplorer/projectexplorer.qbs +++ b/src/plugins/projectexplorer/projectexplorer.qbs @@ -231,7 +231,7 @@ QtcPlugin { Group { name: "WindowsToolChains" - condition: qbs.targetOS.contains("windows") || qtc.testsEnabled + condition: qbs.targetOS.contains("windows") || qtc.withPluginTests files: [ "msvctoolchain.cpp", "msvctoolchain.h", @@ -244,7 +244,7 @@ QtcPlugin { Group { name: "Test resources" - condition: qtc.testsEnabled + condition: qtc.withPluginTests files: ["testdata/**"] fileTags: ["qt.core.resource_data"] Qt.core.resourcePrefix: "/projectexplorer" diff --git a/src/plugins/vcsbase/vcsbase.qbs b/src/plugins/vcsbase/vcsbase.qbs index 0c2f08abd58..7cf0a8fe487 100644 --- a/src/plugins/vcsbase/vcsbase.qbs +++ b/src/plugins/vcsbase/vcsbase.qbs @@ -75,5 +75,5 @@ QtcPlugin { "wizard/vcsjsextension.h", ] - cpp.defines: base.concat(qtc.testsEnabled ? ['SRC_DIR="' + project.ide_source_tree + '"'] : []) + cpp.defines: base.concat(qtc.withPluginTests ? ['SRC_DIR="' + project.ide_source_tree + '"'] : []) } diff --git a/src/tools/sdktool/sdktool.qbs b/src/tools/sdktool/sdktool.qbs index a1da4f5df3e..268b6db40c2 100644 --- a/src/tools/sdktool/sdktool.qbs +++ b/src/tools/sdktool/sdktool.qbs @@ -1,11 +1,8 @@ -import qbs 1.0 - QtcTool { name: "sdktool" Depends { name: "Qt.core" } Depends { name: "app_version_header" } - Depends { name: "Qt.testlib"; condition: project.withAutotests } Depends { name: "sdktoolLib" } cpp.defines: base.concat([ diff --git a/src/tools/sdktool/sdktoollib.qbs b/src/tools/sdktool/sdktoollib.qbs index 17028776e40..d179a2eaa87 100644 --- a/src/tools/sdktool/sdktoollib.qbs +++ b/src/tools/sdktool/sdktoollib.qbs @@ -1,5 +1,3 @@ -import qbs 1.0 - QtcLibrary { name: "sdktoolLib" @@ -7,7 +5,7 @@ QtcLibrary { Depends { name: "Qt.core" } Depends { name: "app_version_header" } - Depends { name: "Qt.testlib"; condition: project.withAutotests } + Depends { name: "Qt.testlib"; condition: qtc.withPluginTests } property string libsDir: path + "/../../libs" @@ -19,7 +17,7 @@ QtcLibrary { ? 'DATA_PATH="."' : qbs.targetOS.contains("windows") ? 'DATA_PATH="../share/qtcreator"' : 'DATA_PATH="../../share/qtcreator"'); - if (project.withAutotests) + if (qtc.withPluginTests) defines.push("WITH_TESTS"); return defines; } diff --git a/tests/auto/auto.qbs b/tests/auto/auto.qbs index a21b61fc0cd..4df8e3118f3 100644 --- a/tests/auto/auto.qbs +++ b/tests/auto/auto.qbs @@ -2,7 +2,6 @@ import qbs Project { name: "QtcAutotests" - condition: project.withAutotests references: [ "aggregation/aggregation.qbs", "algorithm/algorithm.qbs", diff --git a/tests/manual/debugger/simple/simple.qbs b/tests/manual/debugger/simple/simple.qbs index c05ef68ac8a..9f2b2c03e8b 100644 --- a/tests/manual/debugger/simple/simple.qbs +++ b/tests/manual/debugger/simple/simple.qbs @@ -1,11 +1,6 @@ -import qbs -import qbs.FileInfo - Project { name: "Manual debugger simple tests" - condition: project.withAutotests - references: [ "simple_test_app.qbs", "simple_test_plugin.qbs" diff --git a/tests/manual/debugger/simple/simple_test_app.qbs b/tests/manual/debugger/simple/simple_test_app.qbs index ca2c56229e4..e6b19d8bcf8 100644 --- a/tests/manual/debugger/simple/simple_test_app.qbs +++ b/tests/manual/debugger/simple/simple_test_app.qbs @@ -2,6 +2,7 @@ import qbs.File import qbs.FileInfo CppApplication { + condition: qtc.withAutotests name: "Manual Test Simple Application" targetName: "simple_test_app" diff --git a/tests/manual/debugger/simple/simple_test_plugin.qbs b/tests/manual/debugger/simple/simple_test_plugin.qbs index eca6791c02c..c06bc83112b 100644 --- a/tests/manual/debugger/simple/simple_test_plugin.qbs +++ b/tests/manual/debugger/simple/simple_test_plugin.qbs @@ -1,6 +1,7 @@ import qbs.FileInfo DynamicLibrary { + condition: qtc.withAutotests name: "Manual Test Simple Plugin" targetName: "simple_test_plugin" diff --git a/tests/manual/manual.qbs b/tests/manual/manual.qbs index ecf0a6d2f87..b8a37c9356e 100644 --- a/tests/manual/manual.qbs +++ b/tests/manual/manual.qbs @@ -1,9 +1,7 @@ -import qbs - Project { name: "QtcManualtests" - condition: project.withAutotests + condition: project.withAutotests // FIXME: Why are these not QtcManualTests? references: [ "debugger/gui/gui.qbs", diff --git a/tests/manual/widgets/widgets.qbs b/tests/manual/widgets/widgets.qbs index 518ea823b1b..d6b6cd633b1 100644 --- a/tests/manual/widgets/widgets.qbs +++ b/tests/manual/widgets/widgets.qbs @@ -1,10 +1,6 @@ -import qbs - Project { name: "Widgets manualtests" - condition: project.withAutotests - references: [ "crumblepath/crumblepath.qbs", "infolabel/infolabel.qbs", diff --git a/tests/tests.qbs b/tests/tests.qbs index fc634c93d08..7605c427366 100644 --- a/tests/tests.qbs +++ b/tests/tests.qbs @@ -1,4 +1,4 @@ -import qbs +import qbs.FileInfo Project { name: "Tests" @@ -8,4 +8,32 @@ Project { "tools/qml-ast2dot/qml-ast2dot.qbs", "unit/unit.qbs", ] + + AutotestRunner { + Depends { name: "Qt.core" } + Depends { name: "qtc" } + environment: { + var env = base; + if (!qbs.hostOS.contains("windows") || !qbs.targetOS.contains("windows")) + return env; + var path = ""; + for (var i = 0; i < env.length; ++i) { + if (env[i].startsWith("PATH=")) { + path = env[i].substring(5); + break; + } + } + var fullQtcInstallDir = FileInfo.joinPaths(qbs.installRoot, qbs.installPrefix); + var fullLibInstallDir = FileInfo.joinPaths(fullQtcInstallDir, qtc.ide_library_path); + var fullPluginInstallDir = FileInfo.joinPaths(fullQtcInstallDir, qtc.ide_plugin_path); + path = Qt.core.binPath + ";" + fullLibInstallDir + ";" + fullPluginInstallDir + + ";" + path; + var arrayElem = "PATH=" + path; + if (i < env.length) + env[i] = arrayElem; + else + env.push(arrayElem); + return env; + } + } }