2019-04-12 14:49:59 +02:00
|
|
|
/****************************************************************************
|
|
|
|
|
**
|
|
|
|
|
** Copyright (C) 2019 The Qt Company Ltd.
|
|
|
|
|
** 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 "makeinstallstep.h"
|
|
|
|
|
|
2019-05-22 15:59:07 +02:00
|
|
|
#include <projectexplorer/buildconfiguration.h>
|
2019-04-12 14:49:59 +02:00
|
|
|
#include <projectexplorer/buildsteplist.h>
|
2019-10-25 09:55:32 +02:00
|
|
|
#include <projectexplorer/buildsystem.h>
|
2019-04-12 14:49:59 +02:00
|
|
|
#include <projectexplorer/deployconfiguration.h>
|
|
|
|
|
#include <projectexplorer/processparameters.h>
|
|
|
|
|
#include <projectexplorer/runconfigurationaspects.h>
|
|
|
|
|
#include <projectexplorer/target.h>
|
|
|
|
|
#include <projectexplorer/task.h>
|
|
|
|
|
#include <utils/fileutils.h>
|
|
|
|
|
#include <utils/qtcassert.h>
|
|
|
|
|
#include <utils/qtcprocess.h>
|
|
|
|
|
|
|
|
|
|
#include <QDirIterator>
|
|
|
|
|
#include <QFileInfo>
|
|
|
|
|
#include <QFormLayout>
|
|
|
|
|
#include <QTemporaryDir>
|
|
|
|
|
|
|
|
|
|
using namespace ProjectExplorer;
|
|
|
|
|
using namespace Utils;
|
|
|
|
|
|
|
|
|
|
namespace RemoteLinux {
|
|
|
|
|
|
|
|
|
|
const char MakeAspectId[] = "RemoteLinux.MakeInstall.Make";
|
|
|
|
|
const char InstallRootAspectId[] = "RemoteLinux.MakeInstall.InstallRoot";
|
|
|
|
|
const char CleanInstallRootAspectId[] = "RemoteLinux.MakeInstall.CleanInstallRoot";
|
|
|
|
|
const char FullCommandLineAspectId[] = "RemoteLinux.MakeInstall.FullCommandLine";
|
2019-12-11 12:52:07 +01:00
|
|
|
const char CustomCommandLineAspectId[] = "RemoteLinux.MakeInstall.CustomCommandLine";
|
2019-04-12 14:49:59 +02:00
|
|
|
|
2019-12-20 17:05:30 +01:00
|
|
|
MakeInstallStep::MakeInstallStep(BuildStepList *parent, Core::Id id) : MakeStep(parent, id)
|
2019-04-12 14:49:59 +02:00
|
|
|
{
|
|
|
|
|
setDefaultDisplayName(displayName());
|
|
|
|
|
|
|
|
|
|
const auto makeAspect = addAspect<ExecutableAspect>();
|
|
|
|
|
makeAspect->setId(MakeAspectId);
|
|
|
|
|
makeAspect->setSettingsKey(MakeAspectId);
|
|
|
|
|
makeAspect->setDisplayStyle(BaseStringAspect::PathChooserDisplay);
|
|
|
|
|
makeAspect->setLabelText(tr("Command:"));
|
|
|
|
|
connect(makeAspect, &ExecutableAspect::changed,
|
|
|
|
|
this, &MakeInstallStep::updateCommandFromAspect);
|
|
|
|
|
|
|
|
|
|
const auto installRootAspect = addAspect<BaseStringAspect>();
|
|
|
|
|
installRootAspect->setId(InstallRootAspectId);
|
|
|
|
|
installRootAspect->setSettingsKey(InstallRootAspectId);
|
|
|
|
|
installRootAspect->setDisplayStyle(BaseStringAspect::PathChooserDisplay);
|
|
|
|
|
installRootAspect->setExpectedKind(PathChooser::Directory);
|
|
|
|
|
installRootAspect->setLabelText(tr("Install root:"));
|
|
|
|
|
connect(installRootAspect, &BaseStringAspect::changed,
|
|
|
|
|
this, &MakeInstallStep::updateArgsFromAspect);
|
|
|
|
|
|
|
|
|
|
const auto cleanInstallRootAspect = addAspect<BaseBoolAspect>();
|
|
|
|
|
cleanInstallRootAspect->setId(CleanInstallRootAspectId);
|
|
|
|
|
cleanInstallRootAspect->setSettingsKey(CleanInstallRootAspectId);
|
2019-12-11 12:52:07 +01:00
|
|
|
cleanInstallRootAspect->setLabel(tr("Clean install root first:"),
|
|
|
|
|
BaseBoolAspect::LabelPlacement::InExtraLabel);
|
2019-04-12 14:49:59 +02:00
|
|
|
cleanInstallRootAspect->setValue(false);
|
|
|
|
|
|
|
|
|
|
const auto commandLineAspect = addAspect<BaseStringAspect>();
|
|
|
|
|
commandLineAspect->setId(FullCommandLineAspectId);
|
|
|
|
|
commandLineAspect->setDisplayStyle(BaseStringAspect::LabelDisplay);
|
|
|
|
|
commandLineAspect->setLabelText(tr("Full command line:"));
|
|
|
|
|
|
2019-12-11 12:52:07 +01:00
|
|
|
const auto customCommandLineAspect = addAspect<BaseStringAspect>();
|
|
|
|
|
customCommandLineAspect->setId(CustomCommandLineAspectId);
|
|
|
|
|
customCommandLineAspect->setSettingsKey(CustomCommandLineAspectId);
|
|
|
|
|
customCommandLineAspect->setDisplayStyle(BaseStringAspect::LineEditDisplay);
|
|
|
|
|
customCommandLineAspect->setLabelText(tr("Custom command line:"));
|
|
|
|
|
customCommandLineAspect->makeCheckable(BaseStringAspect::CheckBoxPlacement::Top,
|
|
|
|
|
tr("Use custom command line instead:"),
|
|
|
|
|
"RemoteLinux.MakeInstall.EnableCustomCommandLine");
|
|
|
|
|
connect(customCommandLineAspect, &BaseStringAspect::checkedChanged,
|
|
|
|
|
this, &MakeInstallStep::updateCommandFromAspect);
|
|
|
|
|
connect(customCommandLineAspect, &BaseStringAspect::checkedChanged,
|
|
|
|
|
this, &MakeInstallStep::updateArgsFromAspect);
|
|
|
|
|
connect(customCommandLineAspect, &BaseStringAspect::checkedChanged,
|
|
|
|
|
this, &MakeInstallStep::updateFromCustomCommandLineAspect);
|
|
|
|
|
connect(customCommandLineAspect, &BaseStringAspect::changed,
|
|
|
|
|
this, &MakeInstallStep::updateFromCustomCommandLineAspect);
|
|
|
|
|
|
2019-04-12 14:49:59 +02:00
|
|
|
QTemporaryDir tmpDir;
|
2019-08-27 13:50:15 +02:00
|
|
|
installRootAspect->setFilePath(FilePath::fromString(tmpDir.path()));
|
2019-04-12 14:49:59 +02:00
|
|
|
const MakeInstallCommand cmd = target()->makeInstallCommand(tmpDir.path());
|
|
|
|
|
QTC_ASSERT(!cmd.command.isEmpty(), return);
|
|
|
|
|
makeAspect->setExecutable(cmd.command);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Core::Id MakeInstallStep::stepId()
|
|
|
|
|
{
|
|
|
|
|
return "RemoteLinux.MakeInstall";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString MakeInstallStep::displayName()
|
|
|
|
|
{
|
|
|
|
|
return tr("Install into temporary host directory");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BuildStepConfigWidget *MakeInstallStep::createConfigWidget()
|
|
|
|
|
{
|
|
|
|
|
return BuildStep::createConfigWidget();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool MakeInstallStep::init()
|
|
|
|
|
{
|
|
|
|
|
if (!MakeStep::init())
|
|
|
|
|
return false;
|
|
|
|
|
const QString rootDirPath = installRoot().toString();
|
|
|
|
|
if (rootDirPath.isEmpty()) {
|
2019-05-28 13:49:26 +02:00
|
|
|
emit addTask(Task(Task::Error, tr("You must provide an install root."), FilePath(), -1,
|
2019-04-12 14:49:59 +02:00
|
|
|
Constants::TASK_CATEGORY_BUILDSYSTEM));
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
QDir rootDir(rootDirPath);
|
|
|
|
|
if (cleanInstallRoot() && !rootDir.removeRecursively()) {
|
2019-06-25 08:56:25 +02:00
|
|
|
emit addTask(Task(Task::Error, tr("The install root \"%1\" could not be cleaned.")
|
2019-04-12 14:49:59 +02:00
|
|
|
.arg(installRoot().toUserOutput()),
|
2019-05-28 13:49:26 +02:00
|
|
|
FilePath(), -1, Constants::TASK_CATEGORY_BUILDSYSTEM));
|
2019-04-12 14:49:59 +02:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
if (!rootDir.exists() && !QDir::root().mkpath(rootDirPath)) {
|
2019-06-25 08:56:25 +02:00
|
|
|
emit addTask(Task(Task::Error, tr("The install root \"%1\" could not be created.")
|
2019-04-12 14:49:59 +02:00
|
|
|
.arg(installRoot().toUserOutput()),
|
2019-05-28 13:49:26 +02:00
|
|
|
FilePath(), -1, Constants::TASK_CATEGORY_BUILDSYSTEM));
|
2019-04-12 14:49:59 +02:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
if (this == deployConfiguration()->stepList()->steps().last()) {
|
|
|
|
|
emit addTask(Task(Task::Warning, tr("The \"make install\" step should probably not be "
|
|
|
|
|
"last in the list of deploy steps. "
|
2019-05-28 13:49:26 +02:00
|
|
|
"Consider moving it up."), FilePath(), -1,
|
2019-04-12 14:49:59 +02:00
|
|
|
Constants::TASK_CATEGORY_BUILDSYSTEM));
|
|
|
|
|
}
|
|
|
|
|
const MakeInstallCommand cmd = target()->makeInstallCommand(installRoot().toString());
|
|
|
|
|
if (cmd.environment.size() > 0) {
|
|
|
|
|
Environment env = processParameters()->environment();
|
2019-07-09 17:41:30 +02:00
|
|
|
for (auto it = cmd.environment.constBegin(); it != cmd.environment.constEnd(); ++it) {
|
2019-08-16 16:42:14 +02:00
|
|
|
if (cmd.environment.isEnabled(it)) {
|
|
|
|
|
const QString key = cmd.environment.key(it);
|
|
|
|
|
env.set(key, cmd.environment.expandedValueForKey(key));
|
|
|
|
|
}
|
2019-07-09 17:41:30 +02:00
|
|
|
}
|
2019-04-12 14:49:59 +02:00
|
|
|
processParameters()->setEnvironment(env);
|
|
|
|
|
}
|
2019-05-22 15:59:07 +02:00
|
|
|
m_noInstallTarget = false;
|
2019-12-05 16:19:42 +01:00
|
|
|
|
|
|
|
|
const auto buildStep = buildConfiguration()->buildSteps()->firstOfType<AbstractProcessStep>();
|
2019-06-21 08:31:37 +02:00
|
|
|
m_isCmakeProject = buildStep
|
|
|
|
|
&& buildStep->processParameters()->command().executable().toString()
|
2019-05-22 15:59:07 +02:00
|
|
|
.contains("cmake");
|
2019-12-05 16:19:42 +01:00
|
|
|
|
2019-04-12 14:49:59 +02:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MakeInstallStep::finish(bool success)
|
|
|
|
|
{
|
|
|
|
|
if (success) {
|
|
|
|
|
m_deploymentData = DeploymentData();
|
|
|
|
|
m_deploymentData.setLocalInstallRoot(installRoot());
|
|
|
|
|
QDirIterator dit(installRoot().toString(), QDir::Files, QDirIterator::Subdirectories);
|
|
|
|
|
while (dit.hasNext()) {
|
|
|
|
|
dit.next();
|
|
|
|
|
const QFileInfo fi = dit.fileInfo();
|
|
|
|
|
m_deploymentData.addFile(fi.filePath(),
|
|
|
|
|
fi.dir().path().mid(installRoot().toString().length()));
|
|
|
|
|
}
|
2019-10-25 09:55:32 +02:00
|
|
|
buildSystem()->setDeploymentData(m_deploymentData);
|
2019-05-22 15:59:07 +02:00
|
|
|
} else if (m_noInstallTarget && m_isCmakeProject) {
|
|
|
|
|
emit addTask(Task(Task::Warning, tr("You need to add an install statement to your "
|
|
|
|
|
"CMakeLists.txt file for deployment to work."),
|
2019-05-28 13:49:26 +02:00
|
|
|
FilePath(), -1, ProjectExplorer::Constants::TASK_CATEGORY_DEPLOYMENT));
|
2019-04-12 14:49:59 +02:00
|
|
|
}
|
|
|
|
|
MakeStep::finish(success);
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-22 15:59:07 +02:00
|
|
|
void MakeInstallStep::stdError(const QString &line)
|
|
|
|
|
{
|
|
|
|
|
// When using Makefiles: "No rule to make target 'install'"
|
|
|
|
|
// When using ninja: "ninja: error: unknown target 'install'"
|
|
|
|
|
if (line.contains("target 'install'"))
|
|
|
|
|
m_noInstallTarget = true;
|
|
|
|
|
MakeStep::stdError(line);
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-28 13:49:26 +02:00
|
|
|
FilePath MakeInstallStep::installRoot() const
|
2019-04-12 14:49:59 +02:00
|
|
|
{
|
2019-08-27 13:50:15 +02:00
|
|
|
return static_cast<BaseStringAspect *>(aspect(InstallRootAspectId))->filePath();
|
2019-04-12 14:49:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool MakeInstallStep::cleanInstallRoot() const
|
|
|
|
|
{
|
|
|
|
|
return static_cast<BaseBoolAspect *>(aspect(CleanInstallRootAspectId))->value();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MakeInstallStep::updateCommandFromAspect()
|
|
|
|
|
{
|
2019-12-11 12:52:07 +01:00
|
|
|
if (customCommandLineAspect()->isChecked())
|
|
|
|
|
return;
|
2019-05-15 13:59:43 +02:00
|
|
|
setMakeCommand(aspect<ExecutableAspect>()->executable());
|
2019-04-12 14:49:59 +02:00
|
|
|
updateFullCommandLine();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MakeInstallStep::updateArgsFromAspect()
|
|
|
|
|
{
|
2019-12-11 12:52:07 +01:00
|
|
|
if (customCommandLineAspect()->isChecked())
|
|
|
|
|
return;
|
2019-04-12 14:49:59 +02:00
|
|
|
setUserArguments(QtcProcess::joinArgs(target()->makeInstallCommand(
|
2019-08-27 13:50:15 +02:00
|
|
|
static_cast<BaseStringAspect *>(aspect(InstallRootAspectId))->filePath().toString())
|
2019-04-12 14:49:59 +02:00
|
|
|
.arguments));
|
|
|
|
|
updateFullCommandLine();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MakeInstallStep::updateFullCommandLine()
|
|
|
|
|
{
|
2019-05-29 17:23:42 +02:00
|
|
|
// FIXME: Only executable?
|
2019-04-12 14:49:59 +02:00
|
|
|
static_cast<BaseStringAspect *>(aspect(FullCommandLineAspectId))->setValue(
|
2019-05-15 13:59:43 +02:00
|
|
|
QDir::toNativeSeparators(
|
2019-10-07 12:08:48 +03:00
|
|
|
QtcProcess::quoteArg(makeExecutable().toString()))
|
2019-04-12 14:49:59 +02:00
|
|
|
+ ' ' + userArguments());
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-11 12:52:07 +01:00
|
|
|
void MakeInstallStep::updateFromCustomCommandLineAspect()
|
|
|
|
|
{
|
|
|
|
|
const BaseStringAspect * const aspect = customCommandLineAspect();
|
|
|
|
|
if (!aspect->isChecked())
|
|
|
|
|
return;
|
|
|
|
|
const QStringList tokens = QtcProcess::splitArgs(aspect->value());
|
|
|
|
|
setMakeCommand(tokens.isEmpty() ? FilePath() : FilePath::fromString(tokens.first()));
|
|
|
|
|
setUserArguments(QtcProcess::joinArgs(tokens.mid(1)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BaseStringAspect *MakeInstallStep::customCommandLineAspect() const
|
|
|
|
|
{
|
|
|
|
|
return static_cast<BaseStringAspect *>(aspect(CustomCommandLineAspectId));
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-12 14:49:59 +02:00
|
|
|
bool MakeInstallStep::fromMap(const QVariantMap &map)
|
|
|
|
|
{
|
|
|
|
|
if (!MakeStep::fromMap(map))
|
|
|
|
|
return false;
|
|
|
|
|
updateCommandFromAspect();
|
|
|
|
|
updateArgsFromAspect();
|
2019-12-11 12:52:07 +01:00
|
|
|
updateFromCustomCommandLineAspect();
|
2019-04-12 14:49:59 +02:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace RemoteLinux
|