Qmake: Fix workdirectory for qmake projects

The rootProjectNode was not set when the desktopqmakerunconfiguration tried
to use it to figure out the default work directory. Move this code over to
using rootProFile() instead of rootProjectNode(), which is the right thing
to do: rootProFile() is the tree of objects used to parse the qmake project
now.

Task-number: QTCREATORBUG-17728
Change-Id: I76167ba2bbd395d58af7d3bfd50f33c4e37338db
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Tobias Hunger
2017-04-04 14:49:51 +02:00
parent f28e6dd029
commit cfda627abc
3 changed files with 25 additions and 30 deletions

View File

@@ -344,8 +344,8 @@ bool DesktopQmakeRunConfiguration::fromMap(const QVariantMap &map)
QString DesktopQmakeRunConfiguration::executable() const QString DesktopQmakeRunConfiguration::executable() const
{ {
if (QmakeProFileNode *node = projectNode()) if (QmakeProFile *pro = proFile())
return extractWorkingDirAndExecutable(node).second; return extractWorkingDirAndExecutable(pro).second;
return QString(); return QString();
} }
@@ -377,18 +377,18 @@ void DesktopQmakeRunConfiguration::setUsingLibrarySearchPath(bool state)
QString DesktopQmakeRunConfiguration::baseWorkingDirectory() const QString DesktopQmakeRunConfiguration::baseWorkingDirectory() const
{ {
if (QmakeProFileNode *node = projectNode()) if (QmakeProFile *pro = proFile())
return extractWorkingDirAndExecutable(node).first; return extractWorkingDirAndExecutable(pro).first;
return QString(); return QString();
} }
bool DesktopQmakeRunConfiguration::isConsoleApplication() const bool DesktopQmakeRunConfiguration::isConsoleApplication() const
{ {
if (QmakeProFileNode *node = projectNode()) { if (QmakeProFile *pro = proFile()) {
const QStringList config = node->variableValue(Variable::Config); const QStringList config = pro->variableValue(Variable::Config);
if (!config.contains("console") || config.contains("testcase")) if (!config.contains("console") || config.contains("testcase"))
return false; return false;
const QStringList qt = node->variableValue(Variable::Qt); const QStringList qt = pro->variableValue(Variable::Qt);
return !qt.contains("testlib") && !qt.contains("qmltest"); return !qt.contains("testlib") && !qt.contains("qmltest");
} }
return false; return false;
@@ -402,11 +402,11 @@ void DesktopQmakeRunConfiguration::addToBaseEnvironment(Environment &env) const
// The user could be linking to a library found via a -L/some/dir switch // The user could be linking to a library found via a -L/some/dir switch
// to find those libraries while actually running we explicitly prepend those // to find those libraries while actually running we explicitly prepend those
// dirs to the library search path // dirs to the library search path
const QmakeProFileNode *node = projectNode(); const QmakeProFile *pro = proFile();
if (m_isUsingLibrarySearchPath && node) { if (m_isUsingLibrarySearchPath && pro) {
const QStringList libDirectories = node->variableValue(Variable::LibDirectories); const QStringList libDirectories = pro->variableValue(Variable::LibDirectories);
if (!libDirectories.isEmpty()) { if (!libDirectories.isEmpty()) {
const QString proDirectory = node->buildDir(); const QString proDirectory = pro->buildDir().toString();
foreach (QString dir, libDirectories) { foreach (QString dir, libDirectories) {
// Fix up relative entries like "LIBS+=-L.." // Fix up relative entries like "LIBS+=-L.."
const QFileInfo fi(dir); const QFileInfo fi(dir);
@@ -415,7 +415,7 @@ void DesktopQmakeRunConfiguration::addToBaseEnvironment(Environment &env) const
env.prependOrSetLibrarySearchPath(dir); env.prependOrSetLibrarySearchPath(dir);
} // foreach } // foreach
} // libDirectories } // libDirectories
} // node } // pro
QtSupport::BaseQtVersion *qtVersion = QtSupport::QtKitInformation::qtVersion(target()->kit()); QtSupport::BaseQtVersion *qtVersion = QtSupport::QtKitInformation::qtVersion(target()->kit());
if (qtVersion && m_isUsingLibrarySearchPath) if (qtVersion && m_isUsingLibrarySearchPath)
@@ -437,20 +437,18 @@ QmakeProject *DesktopQmakeRunConfiguration::qmakeProject() const
return static_cast<QmakeProject *>(target()->project()); return static_cast<QmakeProject *>(target()->project());
} }
QmakeProFileNode *DesktopQmakeRunConfiguration::projectNode() const QmakeProFile *DesktopQmakeRunConfiguration::proFile() const
{ {
QmakeProject *project = qmakeProject(); QmakeProject *project = qmakeProject();
QTC_ASSERT(project, return nullptr); QTC_ASSERT(project, return nullptr);
QmakeProFileNode *rootNode = project->rootProjectNode(); QmakeProFile *rootProFile = project->rootProFile();
if (!rootNode) return rootProFile ? rootProFile->findProFile(m_proFilePath) : nullptr;
return nullptr;
return rootNode->findProFileFor(m_proFilePath);
} }
QString DesktopQmakeRunConfiguration::defaultDisplayName() QString DesktopQmakeRunConfiguration::defaultDisplayName()
{ {
if (QmakeProFileNode *node = projectNode()) if (QmakeProFile *pro = proFile())
return node->displayName(); return pro->displayName();
QString defaultName; QString defaultName;
if (!m_proFilePath.isEmpty()) if (!m_proFilePath.isEmpty())
@@ -465,19 +463,16 @@ OutputFormatter *DesktopQmakeRunConfiguration::createOutputFormatter() const
return new QtSupport::QtOutputFormatter(target()->project()); return new QtSupport::QtOutputFormatter(target()->project());
} }
QPair<QString, QString> DesktopQmakeRunConfiguration::extractWorkingDirAndExecutable(const QmakeProFileNode *node) const QPair<QString, QString> DesktopQmakeRunConfiguration::extractWorkingDirAndExecutable(const QmakeProFile *proFile) const
{ {
if (!node) if (!proFile)
return {}; return {};
QmakeProFile *pro = node->proFile(); TargetInformation ti = proFile->targetInformation();
QTC_ASSERT(pro, return { });
TargetInformation ti = pro->targetInformation();
if (!ti.valid) if (!ti.valid)
return qMakePair(QString(), QString()); return qMakePair(QString(), QString());
const QStringList &config = pro->variableValue(Variable::Config); const QStringList &config = proFile->variableValue(Variable::Config);
QString destDir = ti.destDir.toString(); QString destDir = ti.destDir.toString();
QString workingDir; QString workingDir;

View File

@@ -98,12 +98,12 @@ protected:
bool fromMap(const QVariantMap &map) override; bool fromMap(const QVariantMap &map) override;
private: private:
QPair<QString, QString> extractWorkingDirAndExecutable(const QmakeProFileNode *node) const; QPair<QString, QString> extractWorkingDirAndExecutable(const QmakeProFile *proFile) const;
QString baseWorkingDirectory() const; QString baseWorkingDirectory() const;
QString defaultDisplayName(); QString defaultDisplayName();
bool isConsoleApplication() const; bool isConsoleApplication() const;
QmakeProject *qmakeProject() const; QmakeProject *qmakeProject() const;
QmakeProFileNode *projectNode() const; QmakeProFile *proFile() const;
void ctor(); void ctor();