Skip to content

Commit

Permalink
qbs build: Clean up testing infrastructure
Browse files Browse the repository at this point in the history
- 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 <[email protected]>
  • Loading branch information
ckandeler committed Sep 19, 2023
1 parent ef00a7e commit a217fa0
Show file tree
Hide file tree
Showing 26 changed files with 61 additions and 91 deletions.
2 changes: 2 additions & 0 deletions qbs/imports/QtcAutotest.qbs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions qbs/imports/QtcManualtest.qbs
Original file line number Diff line number Diff line change
@@ -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("")
Expand Down
2 changes: 1 addition & 1 deletion qbs/imports/QtcPlugin.qbs
Original file line number Diff line number Diff line change
Expand Up @@ -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" }

Expand Down
2 changes: 1 addition & 1 deletion qbs/imports/QtcTestFiles.qbs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Group {
name: "Unit tests"
condition: qtc.testsEnabled
condition: qtc.withPluginTests
}
7 changes: 5 additions & 2 deletions qbs/modules/qtc/qtc.qbs
Original file line number Diff line number Diff line change
Expand Up @@ -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 + '"',
Expand All @@ -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"] : [])
}
34 changes: 1 addition & 33 deletions qtcreator.qbs
Original file line number Diff line number Diff line change
@@ -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: []
Expand Down Expand Up @@ -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;
}
}
}
2 changes: 1 addition & 1 deletion src/libs/extensionsystem/extensionsystem.qbs
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down
2 changes: 1 addition & 1 deletion src/libs/tracing/tracing.qbs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
14 changes: 2 additions & 12 deletions src/plugins/autotest/autotest.qbs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import qbs

QtcPlugin {
name: "AutoTest"

Expand All @@ -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: [
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/clangcodemodel/clangcodemodel.qbs
Original file line number Diff line number Diff line change
Expand Up @@ -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" }

Expand Down
2 changes: 1 addition & 1 deletion src/plugins/clangtools/clangtools.qbs
Original file line number Diff line number Diff line change
Expand Up @@ -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" }

Expand Down
4 changes: 2 additions & 2 deletions src/plugins/cppeditor/cppeditor.qbs
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down Expand Up @@ -233,7 +233,7 @@ QtcPlugin {

Group {
name: "TestCase"
condition: qtc.testsEnabled || project.withAutotests
condition: qtc.withPluginTests || qtc.withAutotests
files: [
"cpptoolstestcase.cpp",
"cpptoolstestcase.h",
Expand Down
5 changes: 1 addition & 4 deletions src/plugins/languageclient/languageclient.qbs
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down
8 changes: 4 additions & 4 deletions src/plugins/mcusupport/mcusupport.qbs
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand All @@ -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",
Expand Down Expand Up @@ -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",
Expand All @@ -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([ "." ])
}
Expand Down
4 changes: 0 additions & 4 deletions src/plugins/mesonprojectmanager/mesonprojectmanager.qbs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ Project {

QtcAutotest {
name: "mesonwrapper"
condition: project.withAutotests

Depends { name: "Core" }
Depends { name: "Utils" }
Expand All @@ -116,7 +115,6 @@ Project {

QtcAutotest {
name: "mesoninfoparser"
condition: project.withAutotests

Depends { name: "Core" }
Depends { name: "Utils" }
Expand All @@ -138,7 +136,6 @@ Project {

QtcAutotest {
name: "ninjaparser"
condition: project.withAutotests

Depends { name: "Core" }
Depends { name: "ProjectExplorer" }
Expand All @@ -156,7 +153,6 @@ Project {

QtcAutotest {
name: "mesonparser"
condition: project.withAutotests

Depends { name: "Core" }
Depends { name: "ProjectExplorer" }
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/projectexplorer/projectexplorer.qbs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/vcsbase/vcsbase.qbs
Original file line number Diff line number Diff line change
Expand Up @@ -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 + '"'] : [])
}
3 changes: 0 additions & 3 deletions src/tools/sdktool/sdktool.qbs
Original file line number Diff line number Diff line change
@@ -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([
Expand Down
6 changes: 2 additions & 4 deletions src/tools/sdktool/sdktoollib.qbs
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import qbs 1.0

QtcLibrary {
name: "sdktoolLib"

type: "staticlibrary"

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"

Expand All @@ -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;
}
Expand Down
1 change: 0 additions & 1 deletion tests/auto/auto.qbs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import qbs

Project {
name: "QtcAutotests"
condition: project.withAutotests
references: [
"aggregation/aggregation.qbs",
"algorithm/algorithm.qbs",
Expand Down
5 changes: 0 additions & 5 deletions tests/manual/debugger/simple/simple.qbs
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
1 change: 1 addition & 0 deletions tests/manual/debugger/simple/simple_test_app.qbs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import qbs.File
import qbs.FileInfo

CppApplication {
condition: qtc.withAutotests
name: "Manual Test Simple Application"
targetName: "simple_test_app"

Expand Down
1 change: 1 addition & 0 deletions tests/manual/debugger/simple/simple_test_plugin.qbs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import qbs.FileInfo

DynamicLibrary {
condition: qtc.withAutotests
name: "Manual Test Simple Plugin"
targetName: "simple_test_plugin"

Expand Down
4 changes: 1 addition & 3 deletions tests/manual/manual.qbs
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
4 changes: 0 additions & 4 deletions tests/manual/widgets/widgets.qbs
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import qbs

Project {
name: "Widgets manualtests"

condition: project.withAutotests

references: [
"crumblepath/crumblepath.qbs",
"infolabel/infolabel.qbs",
Expand Down
Loading

0 comments on commit a217fa0

Please sign in to comment.