forked from qt-creator/qt-creator
ProjectExplorer: Add WorkspaceProjectRunConfig
Change-Id: I66f25165f652f371130555279eddc0437b011887 Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
@@ -9,6 +9,9 @@
|
|||||||
#include "projectexplorertr.h"
|
#include "projectexplorertr.h"
|
||||||
#include "projectmanager.h"
|
#include "projectmanager.h"
|
||||||
#include "projecttree.h"
|
#include "projecttree.h"
|
||||||
|
#include "runconfiguration.h"
|
||||||
|
#include "runconfigurationaspects.h"
|
||||||
|
#include "runcontrol.h"
|
||||||
#include "target.h"
|
#include "target.h"
|
||||||
#include "treescanner.h"
|
#include "treescanner.h"
|
||||||
|
|
||||||
@@ -24,6 +27,7 @@
|
|||||||
const QLatin1StringView FOLDER_MIMETYPE{"inode/directory"};
|
const QLatin1StringView FOLDER_MIMETYPE{"inode/directory"};
|
||||||
const QLatin1StringView WORKSPACE_MIMETYPE{"text/x-workspace-project"};
|
const QLatin1StringView WORKSPACE_MIMETYPE{"text/x-workspace-project"};
|
||||||
const QLatin1StringView WORKSPACE_PROJECT_ID{"ProjectExplorer.WorkspaceProject"};
|
const QLatin1StringView WORKSPACE_PROJECT_ID{"ProjectExplorer.WorkspaceProject"};
|
||||||
|
const QLatin1StringView WORKSPACE_PROJECT_RUNCONFIG_ID{"WorkspaceProject.RunConfiguration:"};
|
||||||
|
|
||||||
const QLatin1StringView PROJECT_NAME_KEY{"project.name"};
|
const QLatin1StringView PROJECT_NAME_KEY{"project.name"};
|
||||||
const QLatin1StringView FILES_EXCLUDE_KEY{"files.exclude"};
|
const QLatin1StringView FILES_EXCLUDE_KEY{"files.exclude"};
|
||||||
@@ -100,7 +104,7 @@ public:
|
|||||||
if (projectNameValue.isString())
|
if (projectNameValue.isString())
|
||||||
project()->setDisplayName(projectNameValue.toString());
|
project()->setDisplayName(projectNameValue.toString());
|
||||||
const QJsonArray excludesJson = json.value(FILES_EXCLUDE_KEY).toArray();
|
const QJsonArray excludesJson = json.value(FILES_EXCLUDE_KEY).toArray();
|
||||||
for (QJsonValue excludeJson : excludesJson) {
|
for (const QJsonValue &excludeJson : excludesJson) {
|
||||||
if (excludeJson.isString()) {
|
if (excludeJson.isString()) {
|
||||||
FilePath absolute = projectPath.pathAppended(excludeJson.toString());
|
FilePath absolute = projectPath.pathAppended(excludeJson.toString());
|
||||||
if (absolute.isDir())
|
if (absolute.isDir())
|
||||||
@@ -111,6 +115,46 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QList<BuildTargetInfo> targetInfos;
|
||||||
|
|
||||||
|
const QJsonArray targets = json.value("targets").toArray();
|
||||||
|
int i = 0;
|
||||||
|
for (const QJsonValue &target : targets) {
|
||||||
|
i++;
|
||||||
|
QTC_ASSERT(target.isObject(), continue);
|
||||||
|
const QJsonObject targetObject = target.toObject();
|
||||||
|
|
||||||
|
QJsonArray args = targetObject["arguments"].toArray();
|
||||||
|
QStringList arguments = Utils::transform<QStringList>(args, [](const QJsonValue &arg) {
|
||||||
|
return arg.toString();
|
||||||
|
});
|
||||||
|
FilePath workingDirectory = FilePath::fromUserInput(
|
||||||
|
targetObject["workingDirectory"].toString());
|
||||||
|
|
||||||
|
if (!workingDirectory.isDir())
|
||||||
|
workingDirectory = FilePath::currentWorkingPath();
|
||||||
|
|
||||||
|
const QString name = targetObject["name"].toString();
|
||||||
|
const FilePath executable = FilePath::fromUserInput(
|
||||||
|
targetObject["executable"].toString());
|
||||||
|
|
||||||
|
if (name.isEmpty() || executable.isEmpty())
|
||||||
|
continue;
|
||||||
|
|
||||||
|
BuildTargetInfo bti;
|
||||||
|
bti.buildKey = name + QString::number(i);
|
||||||
|
bti.displayName = name;
|
||||||
|
bti.displayNameUniquifier = QString(" (%1)").arg(i);
|
||||||
|
bti.targetFilePath = executable;
|
||||||
|
bti.projectFilePath = projectPath;
|
||||||
|
bti.workingDirectory = workingDirectory;
|
||||||
|
bti.additionalData = QVariantMap{{"arguments", arguments}};
|
||||||
|
|
||||||
|
targetInfos << bti;
|
||||||
|
}
|
||||||
|
|
||||||
|
setApplicationTargets(targetInfos);
|
||||||
|
|
||||||
m_parseGuard = guardParsingRun();
|
m_parseGuard = guardParsingRun();
|
||||||
m_scanner.asyncScanForFiles(target()->project()->projectDirectory());
|
m_scanner.asyncScanForFiles(target()->project()->projectDirectory());
|
||||||
}
|
}
|
||||||
@@ -123,6 +167,86 @@ private:
|
|||||||
TreeScanner m_scanner;
|
TreeScanner m_scanner;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class WorkspaceRunConfiguration : public RunConfiguration
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
WorkspaceRunConfiguration(Target *target, Id id)
|
||||||
|
: RunConfiguration(target, id)
|
||||||
|
{
|
||||||
|
hint.setText(
|
||||||
|
Tr::tr("You can edit this configuration inside the .qtcreator/project.json file."));
|
||||||
|
|
||||||
|
const BuildTargetInfo bti = buildTargetInfo();
|
||||||
|
executable.setLabelText(Tr::tr("Executable:"));
|
||||||
|
executable.setReadOnly(true);
|
||||||
|
executable.setValue(bti.targetFilePath);
|
||||||
|
executable.setMacroExpanderProvider(
|
||||||
|
[this]() -> MacroExpander * { return const_cast<MacroExpander *>(macroExpander()); });
|
||||||
|
|
||||||
|
auto argumentsAsString = [this]() {
|
||||||
|
return CommandLine{
|
||||||
|
"", buildTargetInfo().additionalData.toMap()["arguments"].toStringList()}
|
||||||
|
.arguments();
|
||||||
|
};
|
||||||
|
|
||||||
|
arguments.setLabelText(Tr::tr("Arguments:"));
|
||||||
|
arguments.setReadOnly(true);
|
||||||
|
arguments.setMacroExpander(macroExpander());
|
||||||
|
arguments.setArguments(argumentsAsString());
|
||||||
|
|
||||||
|
workingDirectory.setLabelText(Tr::tr("Working directory:"));
|
||||||
|
workingDirectory.setReadOnly(true);
|
||||||
|
workingDirectory.setDefaultWorkingDirectory(bti.workingDirectory);
|
||||||
|
|
||||||
|
setCommandLineGetter([this] {
|
||||||
|
const BuildTargetInfo bti = buildTargetInfo();
|
||||||
|
CommandLine cmdLine{
|
||||||
|
macroExpander()->expand(bti.targetFilePath),
|
||||||
|
Utils::transform(
|
||||||
|
bti.additionalData.toMap()["arguments"].toStringList(),
|
||||||
|
[this](const QString &arg) { return macroExpander()->expand(arg); })};
|
||||||
|
|
||||||
|
return cmdLine;
|
||||||
|
});
|
||||||
|
|
||||||
|
setUpdater([this, argumentsAsString] {
|
||||||
|
const BuildTargetInfo bti = buildTargetInfo();
|
||||||
|
executable.setValue(bti.targetFilePath);
|
||||||
|
arguments.setArguments(argumentsAsString());
|
||||||
|
workingDirectory.setDefaultWorkingDirectory(bti.workingDirectory);
|
||||||
|
});
|
||||||
|
|
||||||
|
connect(target, &Target::buildSystemUpdated, this, &RunConfiguration::update);
|
||||||
|
}
|
||||||
|
|
||||||
|
TextDisplay hint{this};
|
||||||
|
FilePathAspect executable{this};
|
||||||
|
ArgumentsAspect arguments{this};
|
||||||
|
WorkingDirectoryAspect workingDirectory{this};
|
||||||
|
};
|
||||||
|
|
||||||
|
class WorkspaceProjectRunConfigurationFactory : public RunConfigurationFactory
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
WorkspaceProjectRunConfigurationFactory()
|
||||||
|
{
|
||||||
|
registerRunConfiguration<WorkspaceRunConfiguration>(
|
||||||
|
Id::fromString(WORKSPACE_PROJECT_RUNCONFIG_ID));
|
||||||
|
addSupportedProjectType(Id::fromString(WORKSPACE_PROJECT_ID));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
class WorkspaceProjectRunWorkerFactory : public RunWorkerFactory
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
WorkspaceProjectRunWorkerFactory()
|
||||||
|
{
|
||||||
|
setProduct<SimpleTargetRunner>();
|
||||||
|
addSupportedRunMode(Constants::NORMAL_RUN_MODE);
|
||||||
|
addSupportedRunConfig(Id::fromString(WORKSPACE_PROJECT_RUNCONFIG_ID));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
class WorkspaceProject : public Project
|
class WorkspaceProject : public Project
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@@ -203,6 +327,9 @@ void setupWorkspaceProject(QObject *guard)
|
|||||||
QTC_ASSERT(project, return);
|
QTC_ASSERT(project, return);
|
||||||
project->excludeNode(node);
|
project->excludeNode(node);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
static WorkspaceProjectRunConfigurationFactory theRunConfigurationFactory;
|
||||||
|
static WorkspaceProjectRunWorkerFactory theRunWorkerFactory;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace ProjectExplorer
|
} // namespace ProjectExplorer
|
||||||
|
Reference in New Issue
Block a user