diff options
author | Christian Stenger <[email protected]> | 2017-07-12 15:53:31 +0200 |
---|---|---|
committer | Christian Stenger <[email protected]> | 2017-07-31 06:11:35 +0000 |
commit | 27cb331b4b08867ae36364cfa6e60aa26993736e (patch) | |
tree | 59220c5aa8afb2f88e523aaaeb14ec183e3711fd /src/plugins/autotest/testconfiguration.cpp | |
parent | b50d5a4b0bb3f1fdce90ae0f8a1a6729020f797b (diff) |
AutoTest: Avoid guessing run configuration
Base the selection of the run configuration on the executable
we have gotten already from the BuildTargetInfo and take
deployment information into account.
This also reverts cce1e130 partially and avoids
stuffing unrelated information into the buildsystemtarget.
Change-Id: I3de6e910a5fd1092d428ec4afc33c4ca62daaa25
Reviewed-by: Christian Kandeler <[email protected]>
Reviewed-by: Tobias Hunger <[email protected]>
Diffstat (limited to 'src/plugins/autotest/testconfiguration.cpp')
-rw-r--r-- | src/plugins/autotest/testconfiguration.cpp | 79 |
1 files changed, 50 insertions, 29 deletions
diff --git a/src/plugins/autotest/testconfiguration.cpp b/src/plugins/autotest/testconfiguration.cpp index 8440348d7d2..7fe89b3ca3a 100644 --- a/src/plugins/autotest/testconfiguration.cpp +++ b/src/plugins/autotest/testconfiguration.cpp @@ -33,6 +33,7 @@ #include <projectexplorer/buildconfiguration.h> #include <projectexplorer/buildtargetinfo.h> +#include <projectexplorer/deploymentdata.h> #include <projectexplorer/environmentaspect.h> #include <projectexplorer/kitinformation.h> #include <projectexplorer/runnables.h> @@ -61,6 +62,13 @@ static bool isLocal(RunConfiguration *runConfiguration) return DeviceTypeKitInformation::deviceTypeId(kit) == ProjectExplorer::Constants::DESKTOP_DEVICE_TYPE; } +static QString ensureExeEnding(const QString& file) +{ + if (!Utils::HostOsInfo::isWindowsHost() || file.isEmpty() || file.toLower().endsWith(".exe")) + return file; + return Utils::HostOsInfo::withExecutableSuffix(file); +} + void TestConfiguration::completeTestInformation(int runMode) { QTC_ASSERT(!m_projectFile.isEmpty(), return); @@ -82,44 +90,65 @@ void TestConfiguration::completeTestInformation(int runMode) const QStringList targWithProjectFile = b.split('|'); if (targWithProjectFile.size() != 2) // some build targets might miss the project file return false; - return targWithProjectFile.at(0) == bti.targetName + return !bti.targetFilePath.isEmpty() && targWithProjectFile.at(0) == bti.targetName && targWithProjectFile.at(1).startsWith(bti.projectFilePath.toString()); }); }); - QString executable = targetInfo.targetFilePath.toString(); // empty if BTI default created - if (Utils::HostOsInfo::isWindowsHost() && !executable.isEmpty() - && !executable.toLower().endsWith(".exe")) { - executable = Utils::HostOsInfo::withExecutableSuffix(executable); + QTC_CHECK(!targetInfo.targetFilePath.isEmpty()); // empty if BTI default created + const QString localExecutable = ensureExeEnding(targetInfo.targetFilePath.toString()); + + QString buildBase; + if (auto buildConfig = target->activeBuildConfiguration()) { + buildBase = buildConfig->buildDirectory().toString(); + const QString projBase = project->projectDirectory().toString(); + if (m_projectFile.startsWith(projBase)) + m_buildDir = QFileInfo(buildBase + m_projectFile.mid(projBase.length())).absolutePath(); } + // deployment information should get taken into account, but it pretty much seems as if + // each build system uses it differently + const DeploymentData &deployData = target->deploymentData(); + const DeployableFile deploy = deployData.deployableForLocalFile(localExecutable); + // we might have a deployable executable + const QString deployedExecutable = ensureExeEnding((deploy.isValid() && deploy.isExecutable()) + ? QDir::cleanPath(deploy.remoteFilePath()) : localExecutable); + for (RunConfiguration *runConfig : target->runConfigurations()) { if (!isLocal(runConfig)) // TODO add device support continue; - const QString bst = runConfig->buildSystemTarget() + '|' + m_projectFile; - if (buildSystemTargets.contains(bst)) { - Runnable runnable = runConfig->runnable(); - if (!runnable.is<StandardRunnable>()) - continue; - StandardRunnable stdRunnable = runnable.as<StandardRunnable>(); - // TODO this might pick up the wrong executable - m_executableFile = stdRunnable.executable; - if (Utils::HostOsInfo::isWindowsHost() && !m_executableFile.isEmpty() - && !m_executableFile.toLower().endsWith(".exe")) { - m_executableFile = Utils::HostOsInfo::withExecutableSuffix(m_executableFile); - } + Runnable runnable = runConfig->runnable(); + if (!runnable.is<StandardRunnable>()) + continue; + StandardRunnable stdRunnable = runnable.as<StandardRunnable>(); + // not the best approach - but depending on the build system and whether the executables + // are going to get installed or not we have to soften the condition... + const QString ¤tExecutable = ensureExeEnding(stdRunnable.executable); + const QString currentBST = runConfig->buildSystemTarget() + '|'; + const bool isQbs = runConfig->id().toString().startsWith("Qbs.RunConfiguration:"); // BAD! + if ((localExecutable == currentExecutable) + || (deployedExecutable == currentExecutable) + || (isQbs && Utils::anyOf(buildSystemTargets, [currentBST] (const QString &b) { + return b.startsWith(currentBST); + }))) { + m_executableFile = currentExecutable; m_displayName = runConfig->displayName(); m_workingDir = Utils::FileUtils::normalizePathName(stdRunnable.workingDirectory); m_environment = stdRunnable.environment; m_project = project; if (runMode == TestRunner::Debug) m_runConfig = new TestRunConfiguration(runConfig->target(), this); - if (m_executableFile == executable) // we can find a better runConfig if no match - break; + break; } } + // RunConfiguration for this target could be explicitly removed or not created at all - if (m_displayName.isEmpty() && !executable.isEmpty()) { + // or we might have end up using the (wrong) path of a locally installed executable + // for this case try the original executable path of the BuildTargetInfo (the executable + // before installation) to have at least something to execute + if (m_executableFile.isEmpty() && !localExecutable.isEmpty()) + m_executableFile = localExecutable; + if (m_displayName.isEmpty() && !m_executableFile.isEmpty()) { // we failed to find a valid runconfiguration - but we've got the executable already if (auto rc = target->activeRunConfiguration()) { if (isLocal(rc)) { // FIXME for now only Desktop support @@ -127,7 +156,6 @@ void TestConfiguration::completeTestInformation(int runMode) if (runnable.is<StandardRunnable>()) { StandardRunnable stdRunnable = runnable.as<StandardRunnable>(); m_environment = stdRunnable.environment; - m_executableFile = executable; m_project = project; m_guessedConfiguration = true; m_guessedFrom = rc->displayName(); @@ -138,15 +166,8 @@ void TestConfiguration::completeTestInformation(int runMode) } } - if (auto buildConfig = target->activeBuildConfiguration()) { - const QString buildBase = buildConfig->buildDirectory().toString(); - const QString projBase = project->projectDirectory().toString(); - if (m_projectFile.startsWith(projBase)) - m_buildDir = QFileInfo(buildBase + m_projectFile.mid(projBase.length())).absolutePath(); - } - if (m_displayName.isEmpty()) // happens e.g. when guessing the TestConfiguration or error - m_displayName = buildSystemTargets.isEmpty() ? "unknown" : (*buildSystemTargets.begin()).split('|').first(); + m_displayName = (*buildSystemTargets.begin()).split('|').first(); } /** |