1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
|
// Copyright (C) 2019 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include "desktoprunconfiguration.h"
#include "buildsystem.h"
#include "deploymentdata.h"
#include "projectexplorerconstants.h"
#include "projectexplorertr.h"
#include "runconfigurationaspects.h"
#include "runcontrol.h"
#include "target.h"
#include <cmakeprojectmanager/cmakeprojectconstants.h>
#include <qbsprojectmanager/qbsprojectmanagerconstants.h>
#include <qmakeprojectmanager/qmakeprojectmanagerconstants.h>
using namespace Utils;
using namespace ProjectExplorer::Constants;
namespace ProjectExplorer::Internal {
class DesktopRunConfiguration : public RunConfiguration
{
public:
DesktopRunConfiguration(BuildConfiguration *bc, Id id)
: RunConfiguration(bc, id)
{
environment.setSupportForBuildEnvironment(bc);
executable.setDeviceSelector(kit(), ExecutableAspect::RunDevice);
workingDir.setEnvironment(&environment);
connect(&useLibraryPaths, &UseLibraryPathsAspect::changed,
&environment, &EnvironmentAspect::environmentChanged);
if (HostOsInfo::isMacHost()) {
connect(&useDyldSuffix, &UseLibraryPathsAspect::changed,
&environment, &EnvironmentAspect::environmentChanged);
environment.addModifier([this](Environment &env) {
if (useDyldSuffix())
env.set(QLatin1String("DYLD_IMAGE_SUFFIX"), QLatin1String("_debug"));
});
} else {
useDyldSuffix.setVisible(false);
}
enableCategoriesFilterAspect.setEnabled(kit()->supportsQtCategoryFilter());
environment.addModifier([this](Environment &env) {
BuildTargetInfo bti = buildTargetInfo();
if (bti.runEnvModifier) {
Environment old = env;
bti.runEnvModifier(env, useLibraryPaths());
const EnvironmentItems diff = old.diff(env, true);
for (const EnvironmentItem &i : diff) {
switch (i.operation) {
case EnvironmentItem::SetEnabled:
case EnvironmentItem::Prepend:
case EnvironmentItem::Append:
env.addItem(std::make_tuple("_QTC_" + i.name, i.value));
break;
default:
break;
}
}
}
});
setUpdater([this] { updateTargetInformation(); });
}
private:
void updateTargetInformation();
FilePath executableToRun(const BuildTargetInfo &targetInfo) const;
LauncherAspect launcher{this};
EnvironmentAspect environment{this};
ExecutableAspect executable{this};
ArgumentsAspect arguments{this};
WorkingDirectoryAspect workingDir{this};
RunAsAspect runAs{this};
TerminalAspect terminal{this};
UseDyldSuffixAspect useDyldSuffix{this};
UseLibraryPathsAspect useLibraryPaths{this};
EnableCategoriesFilterAspect enableCategoriesFilterAspect{this};
};
void DesktopRunConfiguration::updateTargetInformation()
{
QTC_ASSERT(buildSystem(), return);
BuildTargetInfo bti = buildTargetInfo();
setDefaultDisplayName(bti.displayName);
auto terminalAspect = aspect<TerminalAspect>();
terminalAspect->setUseTerminalHint(bti.usesTerminal && bti.targetFilePath.isLocal());
terminalAspect->setEnabled(bti.targetFilePath.isLocal());
auto launcherAspect = aspect<LauncherAspect>();
launcherAspect->setVisible(false);
auto wda = aspect<WorkingDirectoryAspect>();
if (!bti.workingDirectory.isEmpty())
wda->setDefaultWorkingDirectory(bti.workingDirectory);
const FilePath executable = executableToRun(bti);
aspect<ExecutableAspect>()->setExecutable(executable);
const QStringList argumentsList = bti.additionalData.toMap()["arguments"].toStringList();
if (!argumentsList.isEmpty())
aspect<ArgumentsAspect>()->setArguments(
ProcessArgs::joinArgs(argumentsList, bti.targetFilePath.osType()));
if (bti.launchers.size() > 0) {
launcherAspect->setVisible(true);
// Use start program by default, if defined (see toBuildTarget() for details)
launcherAspect->setDefaultLauncher(bti.launchers.last());
launcherAspect->updateLaunchers(bti.launchers);
}
emit aspect<EnvironmentAspect>()->environmentChanged();
}
FilePath DesktopRunConfiguration::executableToRun(const BuildTargetInfo &targetInfo) const
{
const FilePath appInBuildDir = targetInfo.targetFilePath;
const DeploymentData deploymentData = buildSystem()->deploymentData();
if (deploymentData.localInstallRoot().isEmpty())
return appInBuildDir;
const QString deployedAppFilePath = deploymentData
.deployableForLocalFile(appInBuildDir).remoteFilePath();
if (deployedAppFilePath.isEmpty())
return appInBuildDir;
const FilePath appInLocalInstallDir = deploymentData.localInstallRoot() / deployedAppFilePath;
return appInLocalInstallDir.exists() ? appInLocalInstallDir : appInBuildDir;
}
// Factory
class DesktopRunConfigurationFactory final : public RunConfigurationFactory
{
public:
DesktopRunConfigurationFactory(const Utils::Id &runConfigId, const Utils::Id &projectTypeId)
{
registerRunConfiguration<DesktopRunConfiguration>(runConfigId);
addSupportedProjectType(projectTypeId);
setExecutionTypeId(STDPROCESS_EXECUTION_TYPE_ID);
}
};
void setupDesktopRunConfigurations()
{
static DesktopRunConfigurationFactory theQmakeRunConfigFactory
(Constants::QMAKE_RUNCONFIG_ID, QmakeProjectManager::Constants::QMAKEPROJECT_ID);
static DesktopRunConfigurationFactory theQbsRunConfigFactory
(Constants::QBS_RUNCONFIG_ID, QbsProjectManager::Constants::PROJECT_ID);
static DesktopRunConfigurationFactory theCmakeRunConfigFactory
(Constants::CMAKE_RUNCONFIG_ID, CMakeProjectManager::Constants::CMAKE_PROJECT_ID);
}
void setupDesktopRunWorker()
{
static ProcessRunnerFactory theDesktopRunWorkerFactory({
Constants::CMAKE_RUNCONFIG_ID,
Constants::QBS_RUNCONFIG_ID,
Constants::QMAKE_RUNCONFIG_ID
});
}
} // ProjectExplorer::Internal
|