2019-08-14 11:48:13 +02:00
|
|
|
/****************************************************************************
|
|
|
|
|
**
|
2020-07-02 16:04:31 +02:00
|
|
|
** Copyright (C) 2020 The Qt Company Ltd.
|
2019-08-14 11:48:13 +02:00
|
|
|
** Contact: https://www.qt.io/licensing/
|
|
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator.
|
|
|
|
|
**
|
|
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
|
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
|
|
|
|
**
|
|
|
|
|
** GNU General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
|
|
|
|
**
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include "mcusupportrunconfiguration.h"
|
|
|
|
|
#include "mcusupportconstants.h"
|
|
|
|
|
|
|
|
|
|
#include <projectexplorer/buildconfiguration.h>
|
|
|
|
|
#include <projectexplorer/project.h>
|
|
|
|
|
#include <projectexplorer/target.h>
|
2020-09-18 12:11:40 +02:00
|
|
|
|
2019-10-07 16:22:59 +02:00
|
|
|
#include <cmakeprojectmanager/cmakekitinformation.h>
|
|
|
|
|
#include <cmakeprojectmanager/cmaketool.h>
|
2019-08-14 11:48:13 +02:00
|
|
|
|
2020-09-18 12:11:40 +02:00
|
|
|
#include <utils/aspects.h>
|
|
|
|
|
|
2019-08-14 11:48:13 +02:00
|
|
|
using namespace ProjectExplorer;
|
|
|
|
|
using namespace Utils;
|
|
|
|
|
|
|
|
|
|
namespace McuSupport {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
2019-11-27 23:28:59 +01:00
|
|
|
static FilePath cmakeFilePath(const Target *target)
|
2019-08-14 11:48:13 +02:00
|
|
|
{
|
2022-02-15 11:18:56 +01:00
|
|
|
const CMakeProjectManager::CMakeTool *tool = CMakeProjectManager::CMakeKitAspect::cmakeTool(
|
|
|
|
|
target->kit());
|
2019-11-27 23:28:59 +01:00
|
|
|
return tool->filePath();
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-16 16:54:19 +01:00
|
|
|
static QStringList flashAndRunArgs(const RunConfiguration *rc, const Target *target)
|
2019-11-27 23:28:59 +01:00
|
|
|
{
|
2021-12-16 16:54:19 +01:00
|
|
|
// Use buildKey if provided, fallback to projectName
|
2022-02-15 11:18:56 +01:00
|
|
|
const QString targetName = QLatin1String("flash_%1")
|
|
|
|
|
.arg(!rc->buildKey().isEmpty()
|
|
|
|
|
? rc->buildKey()
|
|
|
|
|
: target->project()->displayName());
|
2019-11-04 18:06:41 +01:00
|
|
|
|
2019-11-27 23:28:59 +01:00
|
|
|
return {"--build", ".", "--target", targetName};
|
2019-08-14 11:48:13 +02:00
|
|
|
}
|
|
|
|
|
|
2020-02-11 10:44:04 +01:00
|
|
|
class FlashAndRunConfiguration final : public RunConfiguration
|
2019-08-14 11:48:13 +02:00
|
|
|
{
|
2020-02-11 10:44:04 +01:00
|
|
|
Q_DECLARE_TR_FUNCTIONS(McuSupport::Internal::FlashAndRunConfiguration)
|
2019-10-07 16:22:59 +02:00
|
|
|
|
2020-02-11 10:44:04 +01:00
|
|
|
public:
|
2020-06-26 13:59:38 +02:00
|
|
|
FlashAndRunConfiguration(Target *target, Utils::Id id)
|
2020-02-11 10:44:04 +01:00
|
|
|
: RunConfiguration(target, id)
|
|
|
|
|
{
|
2020-08-13 09:16:00 +02:00
|
|
|
auto flashAndRunParameters = addAspect<StringAspect>();
|
2020-02-11 10:44:04 +01:00
|
|
|
flashAndRunParameters->setLabelText(tr("Flash and run CMake parameters:"));
|
2020-08-13 09:16:00 +02:00
|
|
|
flashAndRunParameters->setDisplayStyle(StringAspect::TextEditDisplay);
|
2020-02-11 10:44:04 +01:00
|
|
|
flashAndRunParameters->setSettingsKey("FlashAndRunConfiguration.Parameters");
|
2019-10-07 16:22:59 +02:00
|
|
|
|
2021-12-16 16:54:19 +01:00
|
|
|
setUpdater([target, flashAndRunParameters, this] {
|
|
|
|
|
flashAndRunParameters->setValue(flashAndRunArgs(this, target).join(' '));
|
2020-02-11 10:44:04 +01:00
|
|
|
});
|
2019-10-07 16:22:59 +02:00
|
|
|
|
2020-02-11 10:44:04 +01:00
|
|
|
update();
|
|
|
|
|
|
|
|
|
|
connect(target->project(), &Project::displayNameChanged, this, &RunConfiguration::update);
|
|
|
|
|
}
|
|
|
|
|
};
|
2019-08-14 11:48:13 +02:00
|
|
|
|
|
|
|
|
class FlashAndRunWorker : public SimpleTargetRunner
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
FlashAndRunWorker(RunControl *runControl)
|
|
|
|
|
: SimpleTargetRunner(runControl)
|
|
|
|
|
{
|
|
|
|
|
setStarter([this, runControl] {
|
2019-11-27 23:28:59 +01:00
|
|
|
const Target *target = runControl->target();
|
2019-08-14 11:48:13 +02:00
|
|
|
Runnable r;
|
2021-08-10 09:19:30 +02:00
|
|
|
r.command = {cmakeFilePath(target),
|
|
|
|
|
runControl->runConfiguration()->aspect<StringAspect>()->value(),
|
|
|
|
|
CommandLine::Raw};
|
2021-08-02 18:02:10 +02:00
|
|
|
r.workingDirectory = target->activeBuildConfiguration()->buildDirectory();
|
2019-10-31 16:01:35 +01:00
|
|
|
r.environment = target->activeBuildConfiguration()->environment();
|
2022-02-23 16:58:20 +01:00
|
|
|
SimpleTargetRunner::doStart(r);
|
2019-08-14 11:48:13 +02:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
RunWorkerFactory::WorkerCreator makeFlashAndRunWorker()
|
|
|
|
|
{
|
|
|
|
|
return RunWorkerFactory::make<FlashAndRunWorker>();
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-22 16:48:46 +01:00
|
|
|
McuSupportRunConfigurationFactory::McuSupportRunConfigurationFactory()
|
2021-12-16 16:54:19 +01:00
|
|
|
: RunConfigurationFactory()
|
2019-08-14 11:48:13 +02:00
|
|
|
{
|
|
|
|
|
registerRunConfiguration<FlashAndRunConfiguration>(Constants::RUNCONFIGURATION);
|
|
|
|
|
addSupportedTargetDeviceType(Constants::DEVICE_TYPE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace McuSupport
|