Qbs run config: Run executable from installed location, if possible

It's been like that for a long time, but the behavior was inadvertantly
changed in a recent refactoring.

Change-Id: I2f301c995c1f9bb235718e02326c4c64dea91694
Reviewed-by: hjk <hjk@qt.io>
Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
Christian Kandeler
2018-04-16 15:57:20 +02:00
parent 780d4c6a43
commit c6cd9e8fbe
5 changed files with 47 additions and 4 deletions

View File

@@ -40,6 +40,12 @@ class PROJECTEXPLORER_EXPORT DeploymentData
public:
void setFileList(const QList<DeployableFile> &files) { m_files = files; }
void setLocalInstallRoot(const Utils::FileName &installRoot)
{
m_localInstallRoot = installRoot;
}
Utils::FileName localInstallRoot() const { return m_localInstallRoot; }
void addFile(const DeployableFile &file)
{
for (int i = 0; i < m_files.size(); ++i) {
@@ -70,11 +76,13 @@ public:
bool operator==(const DeploymentData &other) const
{
return m_files.toSet() == other.m_files.toSet();
return m_files.toSet() == other.m_files.toSet()
&& m_localInstallRoot == other.m_localInstallRoot;
}
private:
QList<DeployableFile> m_files;
Utils::FileName m_localInstallRoot;
};
inline bool operator!=(const DeploymentData &d1, const DeploymentData &d2)

View File

@@ -26,6 +26,7 @@
#include "qbsproject.h"
#include "qbsbuildconfiguration.h"
#include "qbsbuildstep.h"
#include "qbslogsink.h"
#include "qbspmlogging.h"
#include "qbsprojectimporter.h"
@@ -474,6 +475,18 @@ void QbsProject::updateProjectNodes()
rebuildProjectTree();
}
FileName QbsProject::installRoot()
{
if (!activeTarget())
return FileName();
const auto * const bc
= qobject_cast<QbsBuildConfiguration *>(activeTarget()->activeBuildConfiguration());
if (!bc)
return FileName();
const QbsBuildStep * const buildStep = bc->qbsStep();
return buildStep && buildStep->install() ? buildStep->installRoot() : FileName();
}
void QbsProject::handleQbsParsingDone(bool success)
{
QTC_ASSERT(m_qbsProjectParser, return);
@@ -607,8 +620,14 @@ void QbsProject::updateAfterBuild()
OpTimer opTimer("updateAfterBuild");
QTC_ASSERT(m_qbsProject.isValid(), return);
const qbs::ProjectData &projectData = m_qbsProject.projectData();
if (projectData == m_projectData)
if (projectData == m_projectData) {
if (activeTarget()) {
DeploymentData deploymentData = activeTarget()->deploymentData();
deploymentData.setLocalInstallRoot(installRoot());
activeTarget()->setDeploymentData(deploymentData);
}
return;
}
qCDebug(qbsPmLog) << "Updating data after build";
m_projectData = projectData;
updateProjectNodes();
@@ -1077,6 +1096,7 @@ void QbsProject::updateApplicationTargets()
break;
}
}
BuildTargetInfo bti;
bti.buildKey = QbsProject::uniqueProductName(productData);
bti.targetFilePath = FileName::fromString(targetFile);
@@ -1120,6 +1140,7 @@ void QbsProject::updateDeploymentInfo()
f.isExecutable() ? DeployableFile::TypeExecutable : DeployableFile::TypeNormal);
}
}
deploymentData.setLocalInstallRoot(installRoot());
if (activeTarget())
activeTarget()->setDeploymentData(deploymentData);
}

View File

@@ -131,6 +131,7 @@ private:
void updateAfterParse();
void delayedUpdateAfterParse();
void updateProjectNodes();
Utils::FileName installRoot();
void projectLoaded() override;
ProjectExplorer::ProjectImporter *projectImporter() const override;

View File

@@ -31,6 +31,7 @@
#include <coreplugin/variablechooser.h>
#include <projectexplorer/deploymentdata.h>
#include <projectexplorer/localenvironmentaspect.h>
#include <projectexplorer/project.h>
#include <projectexplorer/runconfigurationaspects.h>
@@ -165,11 +166,22 @@ void QbsRunConfiguration::addToBaseEnvironment(Utils::Environment &env) const
m_envCache.insert(key, env);
}
Utils::FileName QbsRunConfiguration::executableToRun(const BuildTargetInfo &targetInfo) const
{
const FileName appInBuildDir = targetInfo.targetFilePath;
if (target()->deploymentData().localInstallRoot().isEmpty())
return appInBuildDir;
const QString deployedAppFilePath = target()->deploymentData()
.deployableForLocalFile(appInBuildDir.toString()).remoteFilePath();
const FileName appInLocalInstallDir = target()->deploymentData().localInstallRoot()
+ deployedAppFilePath;
return appInLocalInstallDir.exists() ? appInLocalInstallDir : appInBuildDir;
}
void QbsRunConfiguration::updateTargetInformation()
{
BuildTargetInfo bti = target()->applicationTargets().buildTargetInfo(buildKey());
FileName executable = bti.targetFilePath;
const FileName executable = executableToRun(bti);
auto terminalAspect = extraAspect<TerminalAspect>();
if (!terminalAspect->isUserSet())
terminalAspect->setUseTerminal(bti.usesTerminal);

View File

@@ -53,6 +53,7 @@ public:
void addToBaseEnvironment(Utils::Environment &env) const;
private:
Utils::FileName executableToRun(const ProjectExplorer::BuildTargetInfo &targetInfo) const;
QVariantMap toMap() const final;
bool fromMap(const QVariantMap &map) final;
void doAdditionalSetup(const ProjectExplorer::RunConfigurationCreationInfo &rci) final;