ProjectExplorer: Allow build and deploy steps to be run as root

Fixes: QTCREATORBUG-31012
Change-Id: Ie4e6c0da3e17176f61c61ead9d20f203d3c607dc
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Christian Kandeler
2024-07-08 14:21:57 +02:00
parent c66b02d37e
commit 38a2189757
4 changed files with 16 additions and 4 deletions

View File

@@ -4,9 +4,10 @@
#include "abstractprocessstep.h"
#include "processparameters.h"
#include "projectexplorer.h"
#include "projectexplorersettings.h"
#include "projectexplorertr.h"
#include "runconfigurationaspects.h"
#include "runcontrol.h"
#include <utils/outputformatter.h>
#include <utils/qtcprocess.h>
@@ -14,9 +15,6 @@
#include <QTextDecoder>
#include <algorithm>
#include <memory>
using namespace Tasking;
using namespace Utils;
@@ -186,6 +184,10 @@ bool AbstractProcessStep::setupProcess(Process &process)
Environment envWithPwd = d->m_param.environment();
envWithPwd.set("PWD", workingDir.path());
process.setProcessMode(d->m_param.processMode());
if (const auto runAsRoot = aspect<RunAsRootAspect>(); runAsRoot && runAsRoot->value()) {
RunControl::provideAskPassEntry(envWithPwd);
process.setRunAsRoot(true);
}
process.setEnvironment(envWithPwd);
process.setCommand({d->m_param.effectiveCommand(), d->m_param.effectiveArguments(),
CommandLine::Raw});

View File

@@ -313,6 +313,10 @@ QWidget *MakeStep::createConfigWidget()
if (m_disablingForSubDirsSupported)
builder.addRow({m_disabledForSubdirsAspect});
builder.addRow({m_buildTargetsAspect});
if (m_runAsRootAspect.isVisible()) {
m_runAsRootAspect.setLabelPlacement(BoolAspect::LabelPlacement::InExtraLabel);
builder.addRow({m_runAsRootAspect});
}
builder.setNoMargins();
auto widget = builder.emerge();

View File

@@ -4,6 +4,7 @@
#pragma once
#include "abstractprocessstep.h"
#include "runconfigurationaspects.h"
#include <utils/aspects.h>
#include <utils/fileutils.h>
@@ -66,6 +67,7 @@ protected:
Utils::TextDisplay m_nonOverrideWarning{this};
Utils::IntegerAspect m_jobCountAspect{this};
Utils::BoolAspect m_disabledForSubdirsAspect{this};
RunAsRootAspect m_runAsRootAspect{this};
private:
static int defaultJobCount();

View File

@@ -781,6 +781,10 @@ RunAsRootAspect::RunAsRootAspect(AspectContainer *container)
setId("RunAsRoot");
setSettingsKey("RunConfiguration.RunAsRoot");
setLabel(Tr::tr("Run as root user"), LabelPlacement::AtCheckBox);
// Not technically correct, but sensible approximation.
// Client code with more context can override.
setVisible(HostOsInfo::isAnyUnixHost());
}
Interpreter::Interpreter()