forked from qt-creator/qt-creator
QmlDesigner: Cleanup mcu deploy step
Change-Id: I4f4fa4f9067613cb31c7408a89a25cf27f2093e3
Reviewed-by: Aleksei German <aleksei.german@qt.io>
(cherry picked from commit 3f32409748
)
Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
committed by
Aleksei German
parent
3850b6c981
commit
8401dc64b5
@@ -2,36 +2,37 @@
|
|||||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0+ OR GPL-3.0 WITH Qt-GPL-exception-1.0
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0+ OR GPL-3.0 WITH Qt-GPL-exception-1.0
|
||||||
|
|
||||||
#include "mcubuildstep.h"
|
#include "mcubuildstep.h"
|
||||||
|
#include "qmlprojectmanagertr.h"
|
||||||
|
|
||||||
#include "projectexplorer/buildstep.h"
|
#include <projectexplorer/buildstep.h>
|
||||||
#include "projectexplorer/buildsystem.h"
|
#include <projectexplorer/buildsteplist.h>
|
||||||
#include "projectexplorer/buildsteplist.h"
|
#include <projectexplorer/buildsystem.h>
|
||||||
#include "projectexplorer/deployconfiguration.h"
|
#include <projectexplorer/deployconfiguration.h>
|
||||||
#include "projectexplorer/kit.h"
|
#include <projectexplorer/kit.h>
|
||||||
#include "projectexplorer/target.h"
|
#include <projectexplorer/kitmanager.h>
|
||||||
#include "projectexplorer/kitmanager.h"
|
#include <projectexplorer/target.h>
|
||||||
|
#include <projectexplorer/task.h>
|
||||||
|
#include <projectexplorer/taskhub.h>
|
||||||
|
|
||||||
#include <coreplugin/messagebox.h>
|
|
||||||
#include <cmakeprojectmanager/cmakekitinformation.h>
|
#include <cmakeprojectmanager/cmakekitinformation.h>
|
||||||
|
|
||||||
#include "qtsupport/qtsupportconstants.h"
|
#include <mcusupport/mculegacyconstants.h>
|
||||||
#include "mcusupport/mcusupportconstants.h"
|
#include <mcusupport/mcusupportconstants.h>
|
||||||
#include "mcusupport/mculegacyconstants.h"
|
#include <qtsupport/qtsupportconstants.h>
|
||||||
|
|
||||||
#include "utils/aspects.h"
|
#include <utils/aspects.h>
|
||||||
#include "utils/filepath.h"
|
#include <utils/filepath.h>
|
||||||
|
|
||||||
#include <QVersionNumber>
|
#include <QVersionNumber>
|
||||||
|
|
||||||
namespace QmlProjectManager {
|
namespace QmlProjectManager {
|
||||||
|
|
||||||
const Utils::Id DeployMcuProcessStep::id = "QmlProject.Mcu.DeployStep";
|
const Utils::Id DeployMcuProcessStep::id = "QmlProject.Mcu.DeployStep";
|
||||||
const QString DeployMcuProcessStep::processCommandKey = "QmlProject.Mcu.ProcessStep.Command";
|
|
||||||
const QString DeployMcuProcessStep::processArgumentsKey = "QmlProject.Mcu.ProcessStep.Arguments";
|
|
||||||
const QString DeployMcuProcessStep::processWorkingDirectoryKey = "QmlProject.Mcu.ProcessStep.BuildDirectory";
|
|
||||||
|
|
||||||
void DeployMcuProcessStep::showError(const QString& text) {
|
void DeployMcuProcessStep::showError(const QString &text)
|
||||||
Core::AsynchronousMessageBox::critical(tr("Qt4MCU Deploy Step"), text);
|
{
|
||||||
|
ProjectExplorer::DeploymentTask task(ProjectExplorer::Task::Error, text);
|
||||||
|
ProjectExplorer::TaskHub::addTask(task);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO:
|
// TODO:
|
||||||
@@ -47,85 +48,72 @@ DeployMcuProcessStep::DeployMcuProcessStep(ProjectExplorer::BuildStepList *bc, U
|
|||||||
: AbstractProcessStep(bc, id)
|
: AbstractProcessStep(bc, id)
|
||||||
, m_tmpDir()
|
, m_tmpDir()
|
||||||
{
|
{
|
||||||
if (not buildSystem()) {
|
if (!buildSystem()) {
|
||||||
showError(QObject::tr("Failed to find valid build system"));
|
showError(Tr::tr("Failed to find valid build system"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (not m_tmpDir.isValid()) {
|
if (!m_tmpDir.isValid()) {
|
||||||
showError(QObject::tr("Failed to create valid build directory"));
|
showError(Tr::tr("Failed to create valid build directory"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto fixPath = [](const QString& path) -> QString {
|
|
||||||
return "\"" + QDir::toNativeSeparators(path) + "\"";
|
|
||||||
};
|
|
||||||
|
|
||||||
ProjectExplorer::Kit *kit = MCUBuildStepFactory::findMostRecentQulKit();
|
ProjectExplorer::Kit *kit = MCUBuildStepFactory::findMostRecentQulKit();
|
||||||
if (not kit)
|
if (!kit)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
QString root = findKitInformation(kit, McuSupport::Internal::Legacy::Constants::QUL_CMAKE_VAR);
|
QString root = findKitInformation(kit, McuSupport::Internal::Legacy::Constants::QUL_CMAKE_VAR);
|
||||||
|
auto rootPath = Utils::FilePath::fromString(root);
|
||||||
|
|
||||||
auto* cmd = addAspect<Utils::StringAspect>();
|
auto cmd = addAspect<Utils::StringAspect>();
|
||||||
cmd->setSettingsKey(processCommandKey);
|
cmd->setSettingsKey("QmlProject.Mcu.ProcessStep.Command");
|
||||||
cmd->setDisplayStyle(Utils::StringAspect::PathChooserDisplay);
|
cmd->setDisplayStyle(Utils::StringAspect::PathChooserDisplay);
|
||||||
cmd->setExpectedKind(Utils::PathChooser::Command);
|
cmd->setExpectedKind(Utils::PathChooser::Command);
|
||||||
cmd->setLabelText(tr("Command:"));
|
cmd->setLabelText(Tr::tr("Command:"));
|
||||||
cmd->setValue(QDir::toNativeSeparators(root + "/bin/qmlprojectexporter"));
|
cmd->setFilePath(rootPath.pathAppended("/bin/qmlprojectexporter"));
|
||||||
|
|
||||||
const char *importPathConstant = QtSupport::Constants::KIT_QML_IMPORT_PATH;
|
const char *importPathConstant = QtSupport::Constants::KIT_QML_IMPORT_PATH;
|
||||||
QString projectDir = buildSystem()->projectDirectory().toString();
|
Utils::FilePath projectDir = buildSystem()->projectDirectory();
|
||||||
QString qulIncludeDir = kit->value(importPathConstant).toString( );
|
Utils::FilePath qulIncludeDir = Utils::FilePath::fromVariant(kit->value(importPathConstant));
|
||||||
QStringList includeDirs {
|
QStringList includeDirs {
|
||||||
fixPath(qulIncludeDir),
|
Utils::ProcessArgs::quoteArg(qulIncludeDir.toString()),
|
||||||
fixPath(qulIncludeDir + "/Timeline"),
|
Utils::ProcessArgs::quoteArg(qulIncludeDir.pathAppended("Timeline").toString())
|
||||||
fixPath(projectDir + "/imports")
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const char *toolChainConstant = McuSupport::Internal::Constants::KIT_MCUTARGET_TOOLCHAIN_KEY;
|
const char *toolChainConstant = McuSupport::Internal::Constants::KIT_MCUTARGET_TOOLCHAIN_KEY;
|
||||||
QStringList arguments = {
|
QStringList arguments = {
|
||||||
fixPath(buildSystem()->projectFilePath().toString()),
|
Utils::ProcessArgs::quoteArg(buildSystem()->projectFilePath().toString()),
|
||||||
"--platform", findKitInformation(kit, "QUL_PLATFORM"),
|
"--platform", findKitInformation(kit, "QUL_PLATFORM"),
|
||||||
"--toolchain", kit->value(toolChainConstant).toString(),
|
"--toolchain", kit->value(toolChainConstant).toString(),
|
||||||
"--include-dirs", includeDirs.join(","),
|
"--include-dirs", includeDirs.join(","),
|
||||||
};
|
};
|
||||||
|
|
||||||
auto* args = addAspect<Utils::StringAspect>();
|
auto args = addAspect<Utils::StringAspect>();
|
||||||
args->setSettingsKey(processArgumentsKey);
|
args->setSettingsKey("QmlProject.Mcu.ProcessStep.Arguments");
|
||||||
args->setDisplayStyle(Utils::StringAspect::LineEditDisplay);
|
args->setDisplayStyle(Utils::StringAspect::LineEditDisplay);
|
||||||
args->setLabelText(tr("Arguments:"));
|
args->setLabelText(Tr::tr("Arguments:"));
|
||||||
args->setValue(arguments.join(" "));
|
args->setValue(Utils::ProcessArgs::joinArgs(arguments));
|
||||||
|
|
||||||
auto* outDir = addAspect<Utils::StringAspect>();
|
auto outDir = addAspect<Utils::StringAspect>();
|
||||||
outDir->setSettingsKey(processWorkingDirectoryKey);
|
outDir->setSettingsKey("QmlProject.Mcu.ProcessStep.BuildDirectory");
|
||||||
outDir->setDisplayStyle(Utils::StringAspect::PathChooserDisplay);
|
outDir->setDisplayStyle(Utils::StringAspect::PathChooserDisplay);
|
||||||
outDir->setExpectedKind(Utils::PathChooser::Directory);
|
outDir->setExpectedKind(Utils::PathChooser::Directory);
|
||||||
outDir->setLabelText(tr("Build directory:"));
|
outDir->setLabelText(Tr::tr("Build directory:"));
|
||||||
outDir->setPlaceHolderText(fixPath(m_tmpDir.path()));
|
outDir->setPlaceHolderText(m_tmpDir.path());
|
||||||
|
|
||||||
setCommandLineProvider([this, cmd, args, outDir, fixPath]() -> Utils::CommandLine {
|
setCommandLineProvider([this, cmd, args, outDir]() -> Utils::CommandLine {
|
||||||
auto directory = outDir->value();
|
auto directory = outDir->value();
|
||||||
if (directory.isEmpty())
|
if (directory.isEmpty())
|
||||||
directory = fixPath(m_tmpDir.path());
|
directory = m_tmpDir.path();
|
||||||
|
|
||||||
QString outArg = " --outdir " + directory;
|
Utils::CommandLine cmdLine(cmd->filePath());
|
||||||
return {cmd->filePath(), args->value() + outArg, Utils::CommandLine::Raw};
|
cmdLine.addArgs(args->value(), Utils::CommandLine::Raw);
|
||||||
|
cmdLine.addArg("--outdir");
|
||||||
|
cmdLine.addArg(directory);
|
||||||
|
return cmdLine;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DeployMcuProcessStep::init()
|
|
||||||
{
|
|
||||||
if (!AbstractProcessStep::init())
|
|
||||||
return false;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void DeployMcuProcessStep::doRun()
|
|
||||||
{
|
|
||||||
AbstractProcessStep::doRun();
|
|
||||||
}
|
|
||||||
|
|
||||||
QString DeployMcuProcessStep::findKitInformation(ProjectExplorer::Kit *kit, const QString &key)
|
QString DeployMcuProcessStep::findKitInformation(ProjectExplorer::Kit *kit, const QString &key)
|
||||||
{
|
{
|
||||||
// This is (kind of) stolen from mcukitmanager.cpp. Might make sense to unify.
|
// This is (kind of) stolen from mcukitmanager.cpp. Might make sense to unify.
|
||||||
@@ -139,17 +127,16 @@ QString DeployMcuProcessStep::findKitInformation(ProjectExplorer::Kit* kit, cons
|
|||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
MCUBuildStepFactory::MCUBuildStepFactory()
|
MCUBuildStepFactory::MCUBuildStepFactory()
|
||||||
: BuildStepFactory()
|
: BuildStepFactory()
|
||||||
{
|
{
|
||||||
setDisplayName("Qt4MCU Deploy Step");
|
setDisplayName(Tr::tr("Qt4MCU Deploy Step"));
|
||||||
registerStep<DeployMcuProcessStep>(DeployMcuProcessStep::id);
|
registerStep<DeployMcuProcessStep>(DeployMcuProcessStep::id);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MCUBuildStepFactory::attachToTarget(ProjectExplorer::Target *target)
|
void MCUBuildStepFactory::attachToTarget(ProjectExplorer::Target *target)
|
||||||
{
|
{
|
||||||
if (not target)
|
if (!target)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
ProjectExplorer::DeployConfiguration *deployConfiguration = target->activeDeployConfiguration();
|
ProjectExplorer::DeployConfiguration *deployConfiguration = target->activeDeployConfiguration();
|
||||||
@@ -157,8 +144,8 @@ void MCUBuildStepFactory::attachToTarget(ProjectExplorer::Target *target)
|
|||||||
if (stepList->contains(DeployMcuProcessStep::id))
|
if (stepList->contains(DeployMcuProcessStep::id))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (not findMostRecentQulKit()) {
|
if (!findMostRecentQulKit()) {
|
||||||
DeployMcuProcessStep::showError(QObject::tr("Failed to find valid Qt4MCU kit"));
|
DeployMcuProcessStep::showError(Tr::tr("Failed to find valid Qt4MCU kit"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -178,20 +165,22 @@ ProjectExplorer::Kit* MCUBuildStepFactory::findMostRecentQulKit()
|
|||||||
return QVersionNumber::fromString(kit->value(sdkVersion).toString());
|
return QVersionNumber::fromString(kit->value(sdkVersion).toString());
|
||||||
};
|
};
|
||||||
|
|
||||||
ProjectExplorer::Kit* kit = nullptr;
|
ProjectExplorer::Kit *mcuKit = nullptr;
|
||||||
for (auto k : ProjectExplorer::KitManager::kits())
|
for (auto availableKit : ProjectExplorer::KitManager::kits()) {
|
||||||
{
|
if (!availableKit)
|
||||||
auto qulVersion = kitQulVersion(k);
|
continue;
|
||||||
|
|
||||||
|
auto qulVersion = kitQulVersion(availableKit);
|
||||||
if (qulVersion.isNull())
|
if (qulVersion.isNull())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (not kit)
|
if (!mcuKit)
|
||||||
kit = k;
|
mcuKit = availableKit;
|
||||||
|
|
||||||
if (qulVersion > kitQulVersion(kit))
|
if (qulVersion > kitQulVersion(mcuKit))
|
||||||
kit = k;
|
mcuKit = availableKit;
|
||||||
}
|
}
|
||||||
return kit;
|
return mcuKit;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace QmlProjectManager
|
} // namespace QmlProjectManager
|
||||||
|
@@ -2,10 +2,11 @@
|
|||||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0+ OR GPL-3.0 WITH Qt-GPL-exception-1.0
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0+ OR GPL-3.0 WITH Qt-GPL-exception-1.0
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "projectexplorer/kit.h"
|
|
||||||
#include "projectexplorer/project.h"
|
|
||||||
#include <projectexplorer/abstractprocessstep.h>
|
#include <projectexplorer/abstractprocessstep.h>
|
||||||
#include <projectexplorer/buildstep.h>
|
#include <projectexplorer/buildstep.h>
|
||||||
|
#include <projectexplorer/kit.h>
|
||||||
|
#include <projectexplorer/project.h>
|
||||||
|
|
||||||
#include <utils/id.h>
|
#include <utils/id.h>
|
||||||
|
|
||||||
#include <QTemporaryDir>
|
#include <QTemporaryDir>
|
||||||
@@ -21,13 +22,7 @@ public:
|
|||||||
DeployMcuProcessStep(ProjectExplorer::BuildStepList *bc, Utils::Id id);
|
DeployMcuProcessStep(ProjectExplorer::BuildStepList *bc, Utils::Id id);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool init() override;
|
|
||||||
void doRun() override;
|
|
||||||
QString findKitInformation(ProjectExplorer::Kit *kit, const QString &key);
|
QString findKitInformation(ProjectExplorer::Kit *kit, const QString &key);
|
||||||
|
|
||||||
static const QString processCommandKey;
|
|
||||||
static const QString processArgumentsKey;
|
|
||||||
static const QString processWorkingDirectoryKey;
|
|
||||||
QTemporaryDir m_tmpDir;
|
QTemporaryDir m_tmpDir;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user