From dc805ebcf7eed90d11a27c2abc92d2bd70ea6620 Mon Sep 17 00:00:00 2001
From: Joerg Bornemann <joerg.bornemann@digia.com>
Date: Mon, 4 Aug 2014 12:46:09 +0200
Subject: [PATCH] WinRt: fix deploy step for non-application projects

Deploy the executable target of the project of the active run
configuration. This fixes the deploy step for SUBDIRS projects
and sessions with multiple loaded projects.

Task-number: QTCREATORBUG-12775
Change-Id: Ieba529db83c53bffad8c494173ca84159e989b65
Reviewed-by: Christian Kandeler <christian.kandeler@digia.com>
Reviewed-by: Oliver Wolff <oliver.wolff@digia.com>
---
 .../winrt/winrtpackagedeploymentstep.cpp      | 38 +++++++++++++++----
 1 file changed, 30 insertions(+), 8 deletions(-)

diff --git a/src/plugins/winrt/winrtpackagedeploymentstep.cpp b/src/plugins/winrt/winrtpackagedeploymentstep.cpp
index fcb5e5a84f..ce9e37035b 100644
--- a/src/plugins/winrt/winrtpackagedeploymentstep.cpp
+++ b/src/plugins/winrt/winrtpackagedeploymentstep.cpp
@@ -28,8 +28,10 @@
 ****************************************************************************/
 
 #include "winrtpackagedeploymentstep.h"
-#include "winrtpackagedeploymentstepwidget.h"
+
 #include "winrtconstants.h"
+#include "winrtpackagedeploymentstepwidget.h"
+#include "winrtrunconfiguration.h"
 
 #include <projectexplorer/project.h>
 #include <projectexplorer/target.h>
@@ -39,6 +41,7 @@
 #include <projectexplorer/deploymentdata.h>
 #include <projectexplorer/projectexplorerconstants.h>
 #include <qtsupport/qtkitinformation.h>
+#include <utils/qtcassert.h>
 #include <utils/qtcprocess.h>
 
 #include <QRegularExpression>
@@ -59,13 +62,32 @@ WinRtPackageDeploymentStep::WinRtPackageDeploymentStep(BuildStepList *bsl)
 
 bool WinRtPackageDeploymentStep::init()
 {
-    Utils::FileName proFile = project()->projectFilePath();
-    m_targetFilePath
-            = target()->applicationTargets().targetForProject(proFile).toString()
-                + QLatin1String(".exe");
-    m_targetDirPath = m_targetFilePath.left(m_targetFilePath.lastIndexOf(QLatin1Char('/')) + 1);
-    // ### Actually, targetForProject is supposed to return the file path including the file
-    // extension. Whenever this will eventually work, we have to remove the .exe suffix here.
+    WinRtRunConfiguration *rc = qobject_cast<WinRtRunConfiguration *>(
+                target()->activeRunConfiguration());
+    QTC_ASSERT(rc, return false);
+
+    const Utils::FileName activeProjectFilePath = Utils::FileName::fromString(rc->proFilePath());
+    Utils::FileName appTargetFilePath;
+    foreach (const BuildTargetInfo &buildTarget, target()->applicationTargets().list) {
+        if (buildTarget.projectFilePath == activeProjectFilePath) {
+            appTargetFilePath = buildTarget.targetFilePath;
+            break;
+        }
+    }
+
+    m_targetFilePath = appTargetFilePath.toString();
+    if (m_targetFilePath.isEmpty()) {
+        // ### raise error in 3.3
+        // raiseError(tr("No executable to deploy found in %1.").arg(rc->proFilePath()));
+        return false;
+    }
+
+    // ### Ideally, the file paths in applicationTargets() should already have the .exe suffix.
+    // Whenever this will eventually work, we can drop appending the .exe suffix here.
+    if (!m_targetFilePath.endsWith(QLatin1String(".exe"), Qt::CaseInsensitive))
+        m_targetFilePath.append(QLatin1String(".exe"));
+
+    m_targetDirPath = appTargetFilePath.parentDir().toString();
 
     const QtSupport::BaseQtVersion *qt = QtSupport::QtKitInformation::qtVersion(target()->kit());
     if (!qt)
-- 
GitLab