RemoteLinux: Create run configs by target name, not by project file.

The current approach fails for all build systems where one project file
can define more than one executable.

Change-Id: Ieda413975709fbd6e7ea87b185aa962f63cb7c1f
Reviewed-by: Daniel Teske <daniel.teske@digia.com>
This commit is contained in:
Christian Kandeler
2014-08-07 15:53:54 +02:00
parent 758e189dca
commit 0c3eeab464
10 changed files with 67 additions and 49 deletions

View File

@@ -709,7 +709,9 @@ void CMakeProject::updateApplicationAndDeploymentTargets()
deploymentData.addFile(ct.executable, deploymentPrefix + buildDir.relativeFilePath(QFileInfo(ct.executable).dir().path()), DeployableFile::TypeExecutable); deploymentData.addFile(ct.executable, deploymentPrefix + buildDir.relativeFilePath(QFileInfo(ct.executable).dir().path()), DeployableFile::TypeExecutable);
if (!ct.library) { if (!ct.library) {
// TODO: Put a path to corresponding .cbp file into projectFilePath? // TODO: Put a path to corresponding .cbp file into projectFilePath?
appTargetList.list << BuildTargetInfo(ct.executable, ct.executable); appTargetList.list << BuildTargetInfo(ct.title,
Utils::FileName::fromString(ct.executable),
Utils::FileName::fromString(ct.executable));
} }
} }

View File

@@ -31,6 +31,7 @@
#include "projectexplorer_export.h" #include "projectexplorer_export.h"
#include <utils/algorithm.h>
#include <utils/fileutils.h> #include <utils/fileutils.h>
#include <QList> #include <QList>
@@ -42,26 +43,24 @@ class PROJECTEXPLORER_EXPORT BuildTargetInfo
{ {
public: public:
BuildTargetInfo() {} BuildTargetInfo() {}
BuildTargetInfo(const Utils::FileName &targetFilePath, const Utils::FileName &projectFilePath) BuildTargetInfo(const QString &targetName, const Utils::FileName &targetFilePath,
: targetFilePath(targetFilePath), projectFilePath(projectFilePath) const Utils::FileName &projectFilePath)
{ : targetName(targetName)
} , targetFilePath(targetFilePath)
, projectFilePath(projectFilePath)
BuildTargetInfo(const QString &targetFilePath, const QString &projectFilePath)
: targetFilePath(Utils::FileName::fromUserInput(targetFilePath)),
projectFilePath(Utils::FileName::fromUserInput(projectFilePath))
{ {
} }
QString targetName;
Utils::FileName targetFilePath; Utils::FileName targetFilePath;
Utils::FileName projectFilePath; Utils::FileName projectFilePath;
bool isValid() const { return !targetFilePath.isEmpty(); } bool isValid() const { return !targetName.isEmpty(); }
}; };
inline bool operator==(const BuildTargetInfo &ti1, const BuildTargetInfo &ti2) inline bool operator==(const BuildTargetInfo &ti1, const BuildTargetInfo &ti2)
{ {
return ti1.targetFilePath == ti2.targetFilePath; return ti1.targetName == ti2.targetName;
} }
inline bool operator!=(const BuildTargetInfo &ti1, const BuildTargetInfo &ti2) inline bool operator!=(const BuildTargetInfo &ti1, const BuildTargetInfo &ti2)
@@ -71,7 +70,7 @@ inline bool operator!=(const BuildTargetInfo &ti1, const BuildTargetInfo &ti2)
inline uint qHash(const BuildTargetInfo &ti) inline uint qHash(const BuildTargetInfo &ti)
{ {
return qHash(ti.targetFilePath); return qHash(ti.targetName);
} }
@@ -92,6 +91,18 @@ public:
return Utils::FileName(); return Utils::FileName();
} }
bool hasTarget(const QString &targetName) {
return Utils::anyOf(list, [&targetName](const BuildTargetInfo &ti) {
return ti.targetName == targetName;
});
}
Utils::FileName targetFilePath(const QString &targetName) {
return Utils::findOrDefault(list, [&targetName](const BuildTargetInfo &ti) {
return ti.targetName == targetName;
}).targetFilePath;
}
QList<BuildTargetInfo> list; QList<BuildTargetInfo> list;
}; };

View File

@@ -769,7 +769,8 @@ void QbsProject::updateApplicationTargets(const qbs::ProjectData &projectData)
if (!productData.isEnabled() || !productData.isRunnable()) if (!productData.isEnabled() || !productData.isRunnable())
continue; continue;
if (productData.targetArtifacts().isEmpty()) { // No build yet. if (productData.targetArtifacts().isEmpty()) { // No build yet.
applications.list << ProjectExplorer::BuildTargetInfo(Utils::FileName(), applications.list << ProjectExplorer::BuildTargetInfo(productData.name(),
Utils::FileName(),
Utils::FileName::fromString(productData.location().fileName())); Utils::FileName::fromString(productData.location().fileName()));
continue; continue;
} }
@@ -777,7 +778,8 @@ void QbsProject::updateApplicationTargets(const qbs::ProjectData &projectData)
QTC_ASSERT(ta.isValid(), continue); QTC_ASSERT(ta.isValid(), continue);
if (!ta.isExecutable()) if (!ta.isExecutable())
continue; continue;
applications.list << ProjectExplorer::BuildTargetInfo(Utils::FileName::fromString(ta.filePath()), applications.list << ProjectExplorer::BuildTargetInfo(productData.name(),
Utils::FileName::fromString(ta.filePath()),
Utils::FileName::fromString(productData.location().fileName())); Utils::FileName::fromString(productData.location().fileName()));
} }
} }

View File

@@ -1497,8 +1497,11 @@ void QmakeProject::updateBuildSystemData()
target->setDeploymentData(deploymentData); target->setDeploymentData(deploymentData);
BuildTargetInfoList appTargetList; BuildTargetInfoList appTargetList;
foreach (const QmakeProFileNode * const node, applicationProFiles()) foreach (const QmakeProFileNode * const node, applicationProFiles()) {
appTargetList.list << BuildTargetInfo(executableFor(node), node->path()); appTargetList.list << BuildTargetInfo(node->targetInformation().target,
Utils::FileName::fromString(executableFor(node)),
Utils::FileName::fromString(node->path()));
}
target->setApplicationTargets(appTargetList); target->setApplicationTargets(appTargetList);
} }

View File

@@ -45,8 +45,8 @@ namespace {
const char QtLibPathKey[] = "Qt4ProjectManager.QnxRunConfiguration.QtLibPath"; const char QtLibPathKey[] = "Qt4ProjectManager.QnxRunConfiguration.QtLibPath";
} }
QnxRunConfiguration::QnxRunConfiguration(ProjectExplorer::Target *parent, Core::Id id, const QString &proFilePath) QnxRunConfiguration::QnxRunConfiguration(ProjectExplorer::Target *parent, Core::Id id, const QString &targetName)
: RemoteLinux::RemoteLinuxRunConfiguration(parent, id, proFilePath) : RemoteLinux::RemoteLinuxRunConfiguration(parent, id, targetName)
{ {
} }

View File

@@ -44,7 +44,7 @@ class QnxRunConfiguration : public RemoteLinux::RemoteLinuxRunConfiguration
Q_OBJECT Q_OBJECT
public: public:
QnxRunConfiguration(ProjectExplorer::Target *parent, Core::Id id, QnxRunConfiguration(ProjectExplorer::Target *parent, Core::Id id,
const QString &projectFilePath); const QString &targetName);
Utils::Environment environment() const; Utils::Environment environment() const;

View File

@@ -97,7 +97,17 @@ bool QnxRunConfigurationFactory::canCreate(ProjectExplorer::Target *parent, Core
ProjectExplorer::RunConfiguration *QnxRunConfigurationFactory::doCreate(ProjectExplorer::Target *parent, Core::Id id) ProjectExplorer::RunConfiguration *QnxRunConfigurationFactory::doCreate(ProjectExplorer::Target *parent, Core::Id id)
{ {
return new QnxRunConfiguration(parent, id, pathFromId(id)); const QString projectFilePath = pathFromId(id);
const QmakeProjectManager::QmakeProject * const qt4Project
= qobject_cast<QmakeProjectManager::QmakeProject *>(parent->project());
QTC_ASSERT(qt4Project, return 0);
foreach (const QmakeProjectManager::QmakeProFileNode * const node,
qt4Project->applicationProFiles()) {
if (node->path() == projectFilePath)
return new QnxRunConfiguration(parent, id, node->targetInformation().target);
}
QTC_CHECK(false);
return 0;
} }
bool QnxRunConfigurationFactory::canRestore(ProjectExplorer::Target *parent, const QVariantMap &map) const bool QnxRunConfigurationFactory::canRestore(ProjectExplorer::Target *parent, const QVariantMap &map) const

View File

@@ -46,7 +46,7 @@ namespace RemoteLinux {
namespace Internal { namespace Internal {
namespace { namespace {
const char ArgumentsKey[] = "Qt4ProjectManager.MaemoRunConfiguration.Arguments"; const char ArgumentsKey[] = "Qt4ProjectManager.MaemoRunConfiguration.Arguments";
const char ProFileKey[] = "Qt4ProjectManager.MaemoRunConfiguration.ProFile"; const char TargetNameKey[] = "Qt4ProjectManager.MaemoRunConfiguration.TargetName";
const char UseAlternateExeKey[] = "RemoteLinux.RunConfig.UseAlternateRemoteExecutable"; const char UseAlternateExeKey[] = "RemoteLinux.RunConfig.UseAlternateRemoteExecutable";
const char AlternateExeKey[] = "RemoteLinux.RunConfig.AlternateRemoteExecutable"; const char AlternateExeKey[] = "RemoteLinux.RunConfig.AlternateRemoteExecutable";
const char WorkingDirectoryKey[] = "RemoteLinux.RunConfig.WorkingDirectory"; const char WorkingDirectoryKey[] = "RemoteLinux.RunConfig.WorkingDirectory";
@@ -55,14 +55,14 @@ const char WorkingDirectoryKey[] = "RemoteLinux.RunConfig.WorkingDirectory";
class RemoteLinuxRunConfigurationPrivate { class RemoteLinuxRunConfigurationPrivate {
public: public:
RemoteLinuxRunConfigurationPrivate(const QString &projectFilePath) RemoteLinuxRunConfigurationPrivate(const QString &targetName)
: projectFilePath(projectFilePath), : targetName(targetName),
useAlternateRemoteExecutable(false) useAlternateRemoteExecutable(false)
{ {
} }
RemoteLinuxRunConfigurationPrivate(const RemoteLinuxRunConfigurationPrivate *other) RemoteLinuxRunConfigurationPrivate(const RemoteLinuxRunConfigurationPrivate *other)
: projectFilePath(other->projectFilePath), : targetName(other->targetName),
arguments(other->arguments), arguments(other->arguments),
useAlternateRemoteExecutable(other->useAlternateRemoteExecutable), useAlternateRemoteExecutable(other->useAlternateRemoteExecutable),
alternateRemoteExecutable(other->alternateRemoteExecutable), alternateRemoteExecutable(other->alternateRemoteExecutable),
@@ -70,7 +70,7 @@ public:
{ {
} }
QString projectFilePath; QString targetName;
QStringList arguments; QStringList arguments;
bool useAlternateRemoteExecutable; bool useAlternateRemoteExecutable;
QString alternateRemoteExecutable; QString alternateRemoteExecutable;
@@ -82,9 +82,9 @@ public:
using namespace Internal; using namespace Internal;
RemoteLinuxRunConfiguration::RemoteLinuxRunConfiguration(Target *parent, Core::Id id, RemoteLinuxRunConfiguration::RemoteLinuxRunConfiguration(Target *parent, Core::Id id,
const QString &proFilePath) const QString &targetName)
: AbstractRemoteLinuxRunConfiguration(parent, id), : AbstractRemoteLinuxRunConfiguration(parent, id),
d(new RemoteLinuxRunConfigurationPrivate(proFilePath)) d(new RemoteLinuxRunConfigurationPrivate(targetName))
{ {
init(); init();
} }
@@ -135,7 +135,7 @@ QVariantMap RemoteLinuxRunConfiguration::toMap() const
QVariantMap map(RunConfiguration::toMap()); QVariantMap map(RunConfiguration::toMap());
map.insert(QLatin1String(ArgumentsKey), d->arguments); map.insert(QLatin1String(ArgumentsKey), d->arguments);
const QDir dir = QDir(target()->project()->projectDirectory().toString()); const QDir dir = QDir(target()->project()->projectDirectory().toString());
map.insert(QLatin1String(ProFileKey), dir.relativeFilePath(d->projectFilePath)); map.insert(QLatin1String(TargetNameKey), d->targetName);
map.insert(QLatin1String(UseAlternateExeKey), d->useAlternateRemoteExecutable); map.insert(QLatin1String(UseAlternateExeKey), d->useAlternateRemoteExecutable);
map.insert(QLatin1String(AlternateExeKey), d->alternateRemoteExecutable); map.insert(QLatin1String(AlternateExeKey), d->alternateRemoteExecutable);
map.insert(QLatin1String(WorkingDirectoryKey), d->workingDirectory); map.insert(QLatin1String(WorkingDirectoryKey), d->workingDirectory);
@@ -149,8 +149,8 @@ bool RemoteLinuxRunConfiguration::fromMap(const QVariantMap &map)
d->arguments = map.value(QLatin1String(ArgumentsKey)).toStringList(); d->arguments = map.value(QLatin1String(ArgumentsKey)).toStringList();
const QDir dir = QDir(target()->project()->projectDirectory().toString()); const QDir dir = QDir(target()->project()->projectDirectory().toString());
d->projectFilePath d->targetName
= QDir::cleanPath(dir.filePath(map.value(QLatin1String(ProFileKey)).toString())); = QDir::cleanPath(dir.filePath(map.value(QLatin1String(TargetNameKey)).toString()));
d->useAlternateRemoteExecutable = map.value(QLatin1String(UseAlternateExeKey), false).toBool(); d->useAlternateRemoteExecutable = map.value(QLatin1String(UseAlternateExeKey), false).toBool();
d->alternateRemoteExecutable = map.value(QLatin1String(AlternateExeKey)).toString(); d->alternateRemoteExecutable = map.value(QLatin1String(AlternateExeKey)).toString();
d->workingDirectory = map.value(QLatin1String(WorkingDirectoryKey)).toString(); d->workingDirectory = map.value(QLatin1String(WorkingDirectoryKey)).toString();
@@ -162,9 +162,9 @@ bool RemoteLinuxRunConfiguration::fromMap(const QVariantMap &map)
QString RemoteLinuxRunConfiguration::defaultDisplayName() QString RemoteLinuxRunConfiguration::defaultDisplayName()
{ {
if (!d->projectFilePath.isEmpty()) if (!d->targetName.isEmpty())
//: %1 is the name of a project which is being run on remote Linux //: %1 is the name of a project which is being run on remote Linux
return tr("%1 (on Remote Device)").arg(QFileInfo(d->projectFilePath).completeBaseName()); return tr("%1 (on Remote Device)").arg(d->targetName);
//: Remote Linux run configuration default display name //: Remote Linux run configuration default display name
return tr("Run on Remote Device"); return tr("Run on Remote Device");
} }
@@ -183,8 +183,7 @@ Environment RemoteLinuxRunConfiguration::environment() const
QString RemoteLinuxRunConfiguration::localExecutableFilePath() const QString RemoteLinuxRunConfiguration::localExecutableFilePath() const
{ {
return target()->applicationTargets() return target()->applicationTargets().targetFilePath(d->targetName).toString();
.targetForProject(Utils::FileName::fromString(d->projectFilePath)).toString();
} }
QString RemoteLinuxRunConfiguration::defaultRemoteExecutableFilePath() const QString RemoteLinuxRunConfiguration::defaultRemoteExecutableFilePath() const
@@ -241,11 +240,6 @@ void RemoteLinuxRunConfiguration::handleBuildSystemDataUpdated()
updateEnabledState(); updateEnabledState();
} }
QString RemoteLinuxRunConfiguration::projectFilePath() const
{
return d->projectFilePath;
}
const char *RemoteLinuxRunConfiguration::IdPrefix = "RemoteLinuxRunConfiguration:"; const char *RemoteLinuxRunConfiguration::IdPrefix = "RemoteLinuxRunConfiguration:";
} // namespace RemoteLinux } // namespace RemoteLinux

View File

@@ -60,7 +60,7 @@ class REMOTELINUX_EXPORT RemoteLinuxRunConfiguration : public AbstractRemoteLinu
public: public:
RemoteLinuxRunConfiguration(ProjectExplorer::Target *parent, Core::Id id, RemoteLinuxRunConfiguration(ProjectExplorer::Target *parent, Core::Id id,
const QString &projectFilePath); const QString &targetName);
~RemoteLinuxRunConfiguration(); ~RemoteLinuxRunConfiguration();
bool isEnabled() const; bool isEnabled() const;
@@ -83,8 +83,6 @@ public:
QVariantMap toMap() const; QVariantMap toMap() const;
QString projectFilePath() const;
static const char *IdPrefix; static const char *IdPrefix;
signals: signals:

View File

@@ -38,7 +38,6 @@
#include <projectexplorer/target.h> #include <projectexplorer/target.h>
#include <utils/qtcassert.h> #include <utils/qtcassert.h>
#include <QFileInfo>
#include <QString> #include <QString>
using namespace ProjectExplorer; using namespace ProjectExplorer;
@@ -47,7 +46,7 @@ namespace RemoteLinux {
namespace Internal { namespace Internal {
namespace { namespace {
QString pathFromId(Core::Id id) QString stringFromId(Core::Id id)
{ {
QByteArray idStr = id.name(); QByteArray idStr = id.name();
if (!idStr.startsWith(RemoteLinuxRunConfiguration::IdPrefix)) if (!idStr.startsWith(RemoteLinuxRunConfiguration::IdPrefix))
@@ -72,7 +71,7 @@ bool RemoteLinuxRunConfigurationFactory::canCreate(Target *parent, Core::Id id)
if (!canHandle(parent)) if (!canHandle(parent))
return false; return false;
return id == RemoteLinuxCustomRunConfiguration::runConfigId() return id == RemoteLinuxCustomRunConfiguration::runConfigId()
|| !parent->applicationTargets().targetForProject(pathFromId(id)).isEmpty(); || parent->applicationTargets().hasTarget(stringFromId(id));
} }
bool RemoteLinuxRunConfigurationFactory::canRestore(Target *parent, const QVariantMap &map) const bool RemoteLinuxRunConfigurationFactory::canRestore(Target *parent, const QVariantMap &map) const
@@ -100,7 +99,7 @@ QList<Core::Id> RemoteLinuxRunConfigurationFactory::availableCreationIds(Target
const Core::Id base = Core::Id(RemoteLinuxRunConfiguration::IdPrefix); const Core::Id base = Core::Id(RemoteLinuxRunConfiguration::IdPrefix);
foreach (const BuildTargetInfo &bti, parent->applicationTargets().list) foreach (const BuildTargetInfo &bti, parent->applicationTargets().list)
result << base.withSuffix(bti.projectFilePath.toString()); result << base.withSuffix(bti.targetName);
result << RemoteLinuxCustomRunConfiguration::runConfigId(); result << RemoteLinuxCustomRunConfiguration::runConfigId();
return result; return result;
} }
@@ -109,15 +108,14 @@ QString RemoteLinuxRunConfigurationFactory::displayNameForId(Core::Id id) const
{ {
if (id == RemoteLinuxCustomRunConfiguration::runConfigId()) if (id == RemoteLinuxCustomRunConfiguration::runConfigId())
return RemoteLinuxCustomRunConfiguration::runConfigDefaultDisplayName(); return RemoteLinuxCustomRunConfiguration::runConfigDefaultDisplayName();
return QFileInfo(pathFromId(id)).completeBaseName() return stringFromId(id) + QLatin1Char(' ') + tr("(on Remote Generic Linux Host)");
+ QLatin1Char(' ') + tr("(on Remote Generic Linux Host)");
} }
RunConfiguration *RemoteLinuxRunConfigurationFactory::doCreate(Target *parent, Core::Id id) RunConfiguration *RemoteLinuxRunConfigurationFactory::doCreate(Target *parent, Core::Id id)
{ {
if (id == RemoteLinuxCustomRunConfiguration::runConfigId()) if (id == RemoteLinuxCustomRunConfiguration::runConfigId())
return new RemoteLinuxCustomRunConfiguration(parent); return new RemoteLinuxCustomRunConfiguration(parent);
return new RemoteLinuxRunConfiguration(parent, id, pathFromId(id)); return new RemoteLinuxRunConfiguration(parent, id, stringFromId(id));
} }
RunConfiguration *RemoteLinuxRunConfigurationFactory::doRestore(Target *parent, RunConfiguration *RemoteLinuxRunConfigurationFactory::doRestore(Target *parent,