From 73b1a765f322a73f2bc5adf99832e514c167be60 Mon Sep 17 00:00:00 2001 From: Christian Kandeler Date: Wed, 14 Nov 2018 09:28:19 +0100 Subject: [PATCH] Move evaluation of QtCreatorDeploymentData.txt to ProjectExplorer We want to re-use it outside of the CMakeProjectManager. Change-Id: I7550f86704bb7c2a683e831cf8827d5b0f6d90f6 Reviewed-by: hjk --- .../cmakeprojectmanager/cmakeproject.cpp | 40 ++++++------------- .../projectexplorer/deploymentdata.cpp | 28 +++++++++++++ src/plugins/projectexplorer/deploymentdata.h | 1 + 3 files changed, 41 insertions(+), 28 deletions(-) diff --git a/src/plugins/cmakeprojectmanager/cmakeproject.cpp b/src/plugins/cmakeprojectmanager/cmakeproject.cpp index 70a6bc19b59..73d94f54b43 100644 --- a/src/plugins/cmakeprojectmanager/cmakeproject.cpp +++ b/src/plugins/cmakeprojectmanager/cmakeproject.cpp @@ -595,27 +595,24 @@ void CMakeProject::updateApplicationAndDeploymentTargets() if (!t) return; - QFile deploymentFile; - QTextStream deploymentStream; - QString deploymentPrefix; - QDir sourceDir(t->project()->projectDirectory().toString()); QDir buildDir(t->activeBuildConfiguration()->buildDirectory().toString()); - deploymentFile.setFileName(sourceDir.filePath("QtCreatorDeployment.txt")); - // If we don't have a global QtCreatorDeployment.txt check for one created by the active build configuration - if (!deploymentFile.exists()) - deploymentFile.setFileName(buildDir.filePath("QtCreatorDeployment.txt")); - if (deploymentFile.open(QFile::ReadOnly | QFile::Text)) { - deploymentStream.setDevice(&deploymentFile); - deploymentPrefix = deploymentStream.readLine(); - if (!deploymentPrefix.endsWith('/')) - deploymentPrefix.append('/'); - } - BuildTargetInfoList appTargetList; DeploymentData deploymentData; + QString deploymentPrefix; + QString deploymentFilePath = sourceDir.filePath("QtCreatorDeployment.txt"); + bool hasDeploymentFile = QFileInfo::exists(deploymentFilePath); + if (!hasDeploymentFile) { + deploymentFilePath = buildDir.filePath("QtCreatorDeployment.txt"); + hasDeploymentFile = QFileInfo::exists(deploymentFilePath); + } + if (hasDeploymentFile) { + deploymentPrefix = deploymentData.addFilesFromDeploymentFile(deploymentFilePath, + sourceDir.absolutePath()); + } + foreach (const CMakeBuildTarget &ct, buildTargets()) { if (ct.targetType == UtilityType) continue; @@ -639,19 +636,6 @@ void CMakeProject::updateApplicationAndDeploymentTargets() } } - QString absoluteSourcePath = sourceDir.absolutePath(); - if (!absoluteSourcePath.endsWith('/')) - absoluteSourcePath.append('/'); - if (deploymentStream.device()) { - while (!deploymentStream.atEnd()) { - QString line = deploymentStream.readLine(); - if (!line.contains(':')) - continue; - QStringList file = line.split(':'); - deploymentData.addFile(absoluteSourcePath + file.at(0), deploymentPrefix + file.at(1)); - } - } - t->setApplicationTargets(appTargetList); t->setDeploymentData(deploymentData); } diff --git a/src/plugins/projectexplorer/deploymentdata.cpp b/src/plugins/projectexplorer/deploymentdata.cpp index 459973d6872..99888148e10 100644 --- a/src/plugins/projectexplorer/deploymentdata.cpp +++ b/src/plugins/projectexplorer/deploymentdata.cpp @@ -27,6 +27,9 @@ #include +#include +#include + namespace ProjectExplorer { void DeploymentData::setLocalInstallRoot(const Utils::FileName &installRoot) @@ -64,5 +67,30 @@ bool DeploymentData::operator==(const DeploymentData &other) const && m_localInstallRoot == other.m_localInstallRoot; } +QString DeploymentData::addFilesFromDeploymentFile(const QString &deploymentFilePath, + const QString &sourceDir) +{ + const QString sourcePrefix = sourceDir.endsWith('/') ? sourceDir : sourceDir + '/'; + QFile deploymentFile(deploymentFilePath); + QTextStream deploymentStream; + QString deploymentPrefix; + + if (!deploymentFile.open(QFile::ReadOnly | QFile::Text)) + return deploymentPrefix; + deploymentStream.setDevice(&deploymentFile); + deploymentPrefix = deploymentStream.readLine(); + if (!deploymentPrefix.endsWith('/')) + deploymentPrefix.append('/'); + if (deploymentStream.device()) { + while (!deploymentStream.atEnd()) { + QString line = deploymentStream.readLine(); + if (!line.contains(':')) + continue; + QStringList file = line.split(':'); + addFile(sourcePrefix + file.at(0), deploymentPrefix + file.at(1)); + } + } + return deploymentPrefix; +} } // namespace ProjectExplorer diff --git a/src/plugins/projectexplorer/deploymentdata.h b/src/plugins/projectexplorer/deploymentdata.h index 76ceb6fda90..7297ad84b2c 100644 --- a/src/plugins/projectexplorer/deploymentdata.h +++ b/src/plugins/projectexplorer/deploymentdata.h @@ -44,6 +44,7 @@ public: void addFile(const DeployableFile &file); void addFile(const QString &localFilePath, const QString &remoteDirectory, DeployableFile::Type type = DeployableFile::TypeNormal); + QString addFilesFromDeploymentFile(const QString &deploymentFilePath, const QString &sourceDir); int fileCount() const { return m_files.count(); } DeployableFile fileAt(int index) const { return m_files.at(index); }