IncrediBuild: Rework IBConsoleBuildStep

- partially move towards using ProjectConfigurationAspect infrastructure
- fix display of default make arguments
- code cosmetics

Change-Id: I5ce3eb531c65b53d66411e959bcf79408418d5a1
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
hjk
2020-07-28 18:49:06 +02:00
parent 7f2b062045
commit 632f102424
11 changed files with 252 additions and 611 deletions

View File

@@ -26,20 +26,30 @@
#include "ibconsolebuildstep.h"
#include "cmakecommandbuilder.h"
#include "ibconsolestepconfigwidget.h"
#include "incredibuildconstants.h"
#include "incredibuildconstants.h"
#include "makecommandbuilder.h"
#include "ui_ibconsolebuildstep.h"
#include <coreplugin/variablechooser.h>
#include <projectexplorer/abstractprocessstep.h>
#include <projectexplorer/buildconfiguration.h>
#include <projectexplorer/gnumakeparser.h>
#include <projectexplorer/kit.h>
#include <projectexplorer/processparameters.h>
#include <projectexplorer/projectconfigurationaspects.h>
#include <projectexplorer/projectexplorerconstants.h>
#include <projectexplorer/target.h>
#include <utils/environment.h>
#include <utils/pathchooser.h>
#include <QComboBox>
#include <QFormLayout>
#include <QLabel>
#include <QLineEdit>
using namespace ProjectExplorer;
using namespace Utils;
namespace IncrediBuild {
namespace Internal {
@@ -52,27 +62,218 @@ const QLatin1String IBCONSOLE_FORCEREMOTE("IncrediBuild.IBConsole.ForceRemote");
const QLatin1String IBCONSOLE_ALTERNATE("IncrediBuild.IBConsole.Alternate");
}
IBConsoleBuildStep::IBConsoleBuildStep(ProjectExplorer::BuildStepList *buildStepList, Utils::Id id)
: ProjectExplorer::AbstractProcessStep(buildStepList, id)
class IBConsoleBuildStep;
class IBConsoleStepConfigWidget : public BuildStepConfigWidget
{
Q_DECLARE_TR_FUNCTIONS(IncrediBuild::Internal::IBConsoleBuildStep)
public:
explicit IBConsoleStepConfigWidget(IBConsoleBuildStep *ibConsoleStep);
private:
void commandBuilderChanged();
void commandArgsChanged();
void makePathEdited();
IBConsoleBuildStep *m_buildStep;
QLineEdit *makeArgumentsLineEdit;
QComboBox *commandBuilder;
PathChooser *makePathChooser;
};
class IBConsoleBuildStep final : public AbstractProcessStep
{
Q_DECLARE_TR_FUNCTIONS(IncrediBuild::Internal::IBConsoleBuildStep)
public:
IBConsoleBuildStep(BuildStepList *buildStepList, Id id);
bool init() final;
BuildStepConfigWidget *createConfigWidget() final;
bool fromMap(const QVariantMap &map) final;
QVariantMap toMap() const final;
void setCommandBuilder(const QString &commandBuilder);
void tryToMigrate();
void setupOutputFormatter(OutputFormatter *formatter) final;
public:
BaseIntegerAspect *m_nice{nullptr};
BaseBoolAspect *m_keepJobNum{nullptr};
BaseBoolAspect *m_forceRemote{nullptr};
BaseBoolAspect *m_alternate{nullptr};
BuildStepList *m_earlierSteps{};
bool m_loadedFromMap{false};
CommandBuilder m_customCommandBuilder{this}; // "Custom Command"- needs to be first in the list.
MakeCommandBuilder m_makeCommandBuilder{this};
CMakeCommandBuilder m_cmakeCommandBuilder{this};
CommandBuilder *m_commandBuilders[3] {
&m_customCommandBuilder,
&m_makeCommandBuilder,
&m_cmakeCommandBuilder
};
CommandBuilder *m_activeCommandBuilder{m_commandBuilders[0]};
};
IBConsoleStepConfigWidget::IBConsoleStepConfigWidget(IBConsoleBuildStep *ibConsoleStep)
: BuildStepConfigWidget(ibConsoleStep)
, m_buildStep(ibConsoleStep)
{
setDisplayName(tr("IncrediBuild for Linux"));
setSummaryText("<b>" + displayName() + "</b>");
QFont font;
font.setBold(true);
font.setWeight(75);
auto section1 = new QLabel("Target and configuration", this);
section1->setFont(font);
auto commandHelperLabel = new QLabel(tr("Command Helper:"), this);
commandHelperLabel->setToolTip(tr("Select an helper to establish the build command."));
makePathChooser = new PathChooser(this);
makeArgumentsLineEdit = new QLineEdit(this);
const QString defaultCommand = m_buildStep->m_activeCommandBuilder->defaultCommand();
makePathChooser->lineEdit()->setPlaceholderText(defaultCommand);
const QString command = m_buildStep->m_activeCommandBuilder->command();
if (command != defaultCommand)
makePathChooser->setPath(command);
makePathChooser->setExpectedKind(PathChooser::Kind::ExistingCommand);
makePathChooser->setBaseDirectory(FilePath::fromString(PathChooser::homePath()));
makePathChooser->setHistoryCompleter(QLatin1String("IncrediBuild.IBConsole.MakeCommand.History"));
connect(makePathChooser, &PathChooser::rawPathChanged, this, &IBConsoleStepConfigWidget::makePathEdited);
QString defaultArgs;
for (const QString &a : m_buildStep->m_activeCommandBuilder->defaultArguments())
defaultArgs += "\"" + a + "\" ";
QString args;
for (const QString &a : m_buildStep->m_activeCommandBuilder->arguments())
args += "\"" + a + "\" ";
makeArgumentsLineEdit->setPlaceholderText(defaultArgs);
if (args != defaultArgs)
makeArgumentsLineEdit->setText(args);
connect(makeArgumentsLineEdit, &QLineEdit::textEdited, this, &IBConsoleStepConfigWidget::commandArgsChanged);
auto section2 = new QLabel(this);
section2->setText(tr("IncrediBuild Distribution control"));
section2->setFont(font);
commandBuilder = new QComboBox(this);
for (CommandBuilder *p : m_buildStep->m_commandBuilders)
commandBuilder->addItem(p->displayName());
commandBuilder->setCurrentText(m_buildStep->m_activeCommandBuilder->displayName());
connect(commandBuilder, &QComboBox::currentTextChanged, this, &IBConsoleStepConfigWidget::commandBuilderChanged);
const auto emphasize = [](const QString &msg) { return QString("<i>" + msg); };
auto infoLabel1 = new QLabel(emphasize(tr("Enter the appropriate arguments to your build "
"command.")), this);
auto infoLabel2 = new QLabel(emphasize(tr("Make sure the build command's "
"multi-job parameter value is large enough (such as "
"-j200 for the JOM or Make build tools)")), this);
LayoutBuilder builder(this);
builder.addRow(section1);
builder.startNewRow().addItems(commandHelperLabel, commandBuilder);
builder.startNewRow().addItems(tr("Make command:"), makePathChooser);
builder.startNewRow().addItems(tr("Make arguments:"), makeArgumentsLineEdit);
builder.addRow(infoLabel1);
builder.addRow(infoLabel2);
builder.addRow(ibConsoleStep->m_keepJobNum);
builder.addRow(section2);
builder.addRow(ibConsoleStep->m_nice);
builder.addRow(ibConsoleStep->m_forceRemote);
builder.addRow(ibConsoleStep->m_alternate);
Core::VariableChooser::addSupportForChildWidgets(this, ibConsoleStep->macroExpander());
}
void IBConsoleStepConfigWidget::commandBuilderChanged()
{
m_buildStep->setCommandBuilder(commandBuilder->currentText());
QString defaultArgs;
for (const QString &a : m_buildStep->m_activeCommandBuilder->defaultArguments())
defaultArgs += "\"" + a + "\" ";
QString args;
for (const QString &a : m_buildStep->m_activeCommandBuilder->arguments())
args += "\"" + a + "\" ";
if (args == defaultArgs)
args.clear();
makeArgumentsLineEdit->setPlaceholderText(defaultArgs);
makeArgumentsLineEdit->setText(args);
const QString defaultCommand = m_buildStep->m_activeCommandBuilder->defaultCommand();
QString command = m_buildStep->m_activeCommandBuilder->command();
if (command != defaultCommand)
command.clear();
makePathChooser->lineEdit()->setPlaceholderText(defaultCommand);
makePathChooser->setPath(command);
}
void IBConsoleStepConfigWidget::commandArgsChanged()
{
m_buildStep->m_activeCommandBuilder->arguments(makeArgumentsLineEdit->text());
}
void IBConsoleStepConfigWidget::makePathEdited()
{
m_buildStep->m_activeCommandBuilder->command(makePathChooser->rawPath());
}
// IBConsoleBuildStep
IBConsoleBuildStep::IBConsoleBuildStep(BuildStepList *buildStepList, Id id)
: AbstractProcessStep(buildStepList, id)
, m_earlierSteps(buildStepList)
{
setDisplayName("IncrediBuild for Linux");
initCommandBuilders();
}
IBConsoleBuildStep::~IBConsoleBuildStep()
{
for (CommandBuilder* p : m_commandBuildersList) {
delete p;
p = nullptr;
}
m_nice = addAspect<BaseIntegerAspect>();
m_nice->setSettingsKey(Constants::IBCONSOLE_NICE);
m_nice->setToolTip(tr("Specify nice value. Nice Value should be numeric and between -20 and 19"));
m_nice->setLabel(tr("Nice value:"));
m_nice->setRange(-20, 19);
m_keepJobNum = addAspect<BaseBoolAspect>();
m_keepJobNum->setSettingsKey(Constants::IBCONSOLE_KEEPJOBNUM);
m_keepJobNum->setLabel(tr("Keep Original Jobs Num:"));
m_keepJobNum->setToolTip(tr("Setting this option to true, forces IncrediBuild to not override "
"the -j command line switch. The default IncrediBuild behavior is "
"to set a high value to the -j command line switch which controls "
"the number of processes that the build tools executed by Qt will "
"execute in parallel (the default IncrediBuild behavior will set "
"this value to 200)."));
m_forceRemote = addAspect<BaseBoolAspect>();
m_forceRemote->setSettingsKey(Constants::IBCONSOLE_ALTERNATE);
m_forceRemote->setLabel(tr("Force remote:"));
m_alternate = addAspect<BaseBoolAspect>();
m_alternate->setSettingsKey(Constants::IBCONSOLE_FORCEREMOTE);
m_alternate->setLabel(tr("Alternate tasks preference:"));
}
void IBConsoleBuildStep::tryToMigrate()
{
// This is called when creating a fresh build step.
// Attempt to detect build system from pre-existing steps.
for (CommandBuilder* p : m_commandBuildersList) {
for (CommandBuilder *p : m_commandBuilders) {
if (p->canMigrate(m_earlierSteps)) {
m_activeCommandBuilder = p;
break;
@@ -80,7 +281,7 @@ void IBConsoleBuildStep::tryToMigrate()
}
}
void IBConsoleBuildStep::setupOutputFormatter(Utils::OutputFormatter *formatter)
void IBConsoleBuildStep::setupOutputFormatter(OutputFormatter *formatter)
{
formatter->addLineParser(new GnuMakeParser());
formatter->addLineParsers(target()->kit()->createOutputParsers());
@@ -91,13 +292,9 @@ void IBConsoleBuildStep::setupOutputFormatter(Utils::OutputFormatter *formatter)
bool IBConsoleBuildStep::fromMap(const QVariantMap &map)
{
m_loadedFromMap = true;
m_nice = map.value(Constants::IBCONSOLE_NICE, QVariant(0)).toInt();
m_keepJobNum = map.value(Constants::IBCONSOLE_KEEPJOBNUM, QVariant(false)).toBool();
m_forceRemote = map.value(Constants::IBCONSOLE_FORCEREMOTE, QVariant(false)).toBool();
m_forceRemote = map.value(Constants::IBCONSOLE_ALTERNATE, QVariant(false)).toBool();
// Command builder. Default to the first in list, which should be the "Custom Command"
commandBuilder(map.value(Constants::IBCONSOLE_COMMANDBUILDER, QVariant(m_commandBuildersList.front()->displayName())).toString());
setCommandBuilder(map.value(Constants::IBCONSOLE_COMMANDBUILDER, QVariant(m_commandBuilders[0]->displayName())).toString());
bool result = m_activeCommandBuilder->fromMap(map);
return result && AbstractProcessStep::fromMap(map);
@@ -108,11 +305,7 @@ QVariantMap IBConsoleBuildStep::toMap() const
QVariantMap map = AbstractProcessStep::toMap();
map[IncrediBuild::Constants::INCREDIBUILD_BUILDSTEP_TYPE] = QVariant(IncrediBuild::Constants::IBCONSOLE_BUILDSTEP_ID);
map[Constants::IBCONSOLE_NICE] = QVariant(m_nice);
map[Constants::IBCONSOLE_KEEPJOBNUM] = QVariant(m_keepJobNum);
map[Constants::IBCONSOLE_ALTERNATE] = QVariant(m_forceRemote);
map[Constants::IBCONSOLE_FORCEREMOTE] = QVariant(m_forceRemote);
map[Constants::IBCONSOLE_COMMANDBUILDER] = QVariant(commandBuilder()->displayName());
map[Constants::IBCONSOLE_COMMANDBUILDER] = QVariant(m_activeCommandBuilder->displayName());
m_activeCommandBuilder->toMap(&map);
return map;
@@ -122,69 +315,47 @@ bool IBConsoleBuildStep::init()
{
QStringList args;
if (m_nice != 0)
args.append(QString("--nice %0 ").arg(m_nice));
if (m_nice->value() != 0)
args.append(QString("--nice %0 ").arg(m_nice->value()));
if (m_alternate)
if (m_alternate->value())
args.append("--alternate");
if (m_forceRemote)
if (m_forceRemote->value())
args.append("--force-remote");
m_activeCommandBuilder->keepJobNum(m_keepJobNum);
m_activeCommandBuilder->keepJobNum(m_keepJobNum->value());
args.append(m_activeCommandBuilder->fullCommandFlag());
Utils::CommandLine cmdLine("ib_console", args);
CommandLine cmdLine("ib_console", args);
ProcessParameters *procParams = processParameters();
procParams->setCommandLine(cmdLine);
procParams->setEnvironment(Utils::Environment::systemEnvironment());
procParams->setEnvironment(Environment::systemEnvironment());
BuildConfiguration *buildConfig = buildConfiguration();
if (buildConfig) {
procParams->setWorkingDirectory(buildConfig->buildDirectory());
procParams->setEnvironment(buildConfig->environment());
Utils::MacroExpander *macroExpander = buildConfig->macroExpander();
if (macroExpander)
procParams->setMacroExpander(macroExpander);
procParams->setMacroExpander(buildConfig->macroExpander());
}
return AbstractProcessStep::init();
}
BuildStepConfigWidget* IBConsoleBuildStep::createConfigWidget()
BuildStepConfigWidget *IBConsoleBuildStep::createConfigWidget()
{
// On first creation of the step, attempt to detect and migrate from preceding steps
if (!m_loadedFromMap)
tryToMigrate();
return new IBConsoleStepConfigWidget(this);
}
void IBConsoleBuildStep::initCommandBuilders()
void IBConsoleBuildStep::setCommandBuilder(const QString &commandBuilder)
{
if (m_commandBuildersList.empty()) {
m_commandBuildersList.push_back(new CommandBuilder(this)); // "Custom Command"- needs to be first in the list.
m_commandBuildersList.push_back(new MakeCommandBuilder(this));
m_commandBuildersList.push_back(new CMakeCommandBuilder(this));
}
// Default to "Custom Command".
if (!m_activeCommandBuilder)
m_activeCommandBuilder = m_commandBuildersList.front();
}
const QStringList& IBConsoleBuildStep::supportedCommandBuilders()
{
static QStringList list;
if (list.empty()) {
initCommandBuilders();
for (CommandBuilder* p : m_commandBuildersList)
list.push_back(p->displayName());
}
return list;
}
void IBConsoleBuildStep::commandBuilder(const QString &commandBuilder)
{
for (CommandBuilder* p : m_commandBuildersList) {
for (CommandBuilder *p : m_commandBuilders) {
if (p->displayName().compare(commandBuilder) == 0) {
m_activeCommandBuilder = p;
break;
@@ -192,5 +363,16 @@ void IBConsoleBuildStep::commandBuilder(const QString &commandBuilder)
}
}
// IBConsoleStepFactory
IBConsoleStepFactory::IBConsoleStepFactory()
{
registerStep<IBConsoleBuildStep>(IncrediBuild::Constants::IBCONSOLE_BUILDSTEP_ID);
setDisplayName(QObject::tr("IncrediBuild for Linux"));
setSupportedStepLists({ProjectExplorer::Constants::BUILDSTEPS_BUILD,
ProjectExplorer::Constants::BUILDSTEPS_CLEAN});
}
} // namespace Internal
} // namespace IncrediBuild