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:
Knud Dollereder
2023-04-21 15:30:28 +02:00
committed by Aleksei German
parent 3850b6c981
commit 8401dc64b5
2 changed files with 83 additions and 99 deletions

View File

@@ -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,86 +48,73 @@ 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 { ProjectExplorer::Kit *kit = MCUBuildStepFactory::findMostRecentQulKit();
return "\"" + QDir::toNativeSeparators(path) + "\""; if (!kit)
};
ProjectExplorer::Kit* kit = MCUBuildStepFactory::findMostRecentQulKit();
if (not 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() QString DeployMcuProcessStep::findKitInformation(ProjectExplorer::Kit *kit, const QString &key)
{
if (!AbstractProcessStep::init())
return false;
return true;
}
void DeployMcuProcessStep::doRun()
{
AbstractProcessStep::doRun();
}
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.
using namespace CMakeProjectManager; using namespace CMakeProjectManager;
@@ -139,59 +127,60 @@ 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();
ProjectExplorer::BuildStepList* stepList = deployConfiguration->stepList(); ProjectExplorer::BuildStepList *stepList = deployConfiguration->stepList();
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;
} }
for (BuildStepFactory *factory : BuildStepFactory::allBuildStepFactories()) { for (BuildStepFactory *factory : BuildStepFactory::allBuildStepFactories()) {
if (factory->stepId() == DeployMcuProcessStep::id) { if (factory->stepId() == DeployMcuProcessStep::id) {
ProjectExplorer::BuildStep* deployConfig = factory->create(stepList); ProjectExplorer::BuildStep *deployConfig = factory->create(stepList);
stepList->appendStep(deployConfig); stepList->appendStep(deployConfig);
} }
} }
} }
ProjectExplorer::Kit* MCUBuildStepFactory::findMostRecentQulKit() ProjectExplorer::Kit *MCUBuildStepFactory::findMostRecentQulKit()
{ {
// Stolen from mcukitmanager.cpp // Stolen from mcukitmanager.cpp
auto kitQulVersion = [](const ProjectExplorer::Kit *kit) -> QVersionNumber { auto kitQulVersion = [](const ProjectExplorer::Kit *kit) -> QVersionNumber {
const char* sdkVersion = McuSupport::Internal::Constants::KIT_MCUTARGET_SDKVERSION_KEY; const char *sdkVersion = McuSupport::Internal::Constants::KIT_MCUTARGET_SDKVERSION_KEY;
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);
if (qulVersion.isNull( ))
continue; continue;
if (not kit) auto qulVersion = kitQulVersion(availableKit);
kit = k; if (qulVersion.isNull())
continue;
if (qulVersion > kitQulVersion(kit)) if (!mcuKit)
kit = k; mcuKit = availableKit;
if (qulVersion > kitQulVersion(mcuKit))
mcuKit = availableKit;
} }
return kit; return mcuKit;
} }
} // namespace QmlProjectManager } // namespace QmlProjectManager

View File

@@ -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>
@@ -16,18 +17,12 @@ class DeployMcuProcessStep : public ProjectExplorer::AbstractProcessStep
{ {
public: public:
static const Utils::Id id; static const Utils::Id id;
static void showError(const QString& text); static void showError(const QString &text);
DeployMcuProcessStep(ProjectExplorer::BuildStepList *bc, Utils::Id id); DeployMcuProcessStep(ProjectExplorer::BuildStepList *bc, Utils::Id id);
private: private:
bool init() override; QString findKitInformation(ProjectExplorer::Kit *kit, const QString &key);
void doRun() override;
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;
}; };
@@ -36,7 +31,7 @@ class MCUBuildStepFactory : public ProjectExplorer::BuildStepFactory
public: public:
MCUBuildStepFactory(); MCUBuildStepFactory();
static void attachToTarget(ProjectExplorer::Target *target); static void attachToTarget(ProjectExplorer::Target *target);
static ProjectExplorer::Kit* findMostRecentQulKit( ); static ProjectExplorer::Kit *findMostRecentQulKit();
}; };
} // namespace QmlProjectManager } // namespace QmlProjectManager