From fe9883a0c3788ee0da8edf0694da2d7c8a5d0bf9 Mon Sep 17 00:00:00 2001 From: Orgad Shaneh Date: Tue, 18 Dec 2018 23:38:07 +0200 Subject: [PATCH] ProjectExplorer: Show MAKEFLAGS warning icon only on mismatch If MAKEFLAGS is 4, and the jobs value is also 4, the warning is pointless. Change-Id: I2d104113dd1ceabaef52958655af8f71ab5111ed Reviewed-by: Eike Ziller --- src/plugins/projectexplorer/makestep.cpp | 38 ++++++++++++++++++++---- src/plugins/projectexplorer/makestep.h | 1 + 2 files changed, 34 insertions(+), 5 deletions(-) diff --git a/src/plugins/projectexplorer/makestep.cpp b/src/plugins/projectexplorer/makestep.cpp index 019d2c67bf0..3c91183a352 100644 --- a/src/plugins/projectexplorer/makestep.cpp +++ b/src/plugins/projectexplorer/makestep.cpp @@ -40,6 +40,7 @@ #include #include #include +#include #include #include @@ -198,10 +199,37 @@ void MakeStep::setJobCountOverrideMakeflags(bool override) m_overrideMakeflags = override; } -static bool argsContainsJobCount(const QString &str) +static Utils::optional argsJobCount(const QString &str) { const QStringList args = Utils::QtcProcess::splitArgs(str, Utils::HostOsInfo::hostOs()); - return Utils::anyOf(args, [](const QString &arg) { return arg.startsWith("-j"); }); + const int argIndex = Utils::indexOf(args, [](const QString &arg) { return arg.startsWith("-j"); }); + if (argIndex == -1) + return Utils::nullopt; + QString arg = args.at(argIndex); + bool requireNumber = false; + // -j [4] as separate arguments (or no value) + if (arg == "-j") { + if (args.size() <= argIndex + 1) + return 1000; // unlimited + arg = args.at(argIndex + 1); + } else { // -j4 + arg = arg.mid(2).trimmed(); + requireNumber = true; + } + bool ok = false; + const int res = arg.toInt(&ok); + if (!ok && requireNumber) + return Utils::nullopt; + return Utils::make_optional(ok && res > 0 ? res : 1000); +} + +bool MakeStep::makeflagsJobCountMismatch() const +{ + const Utils::Environment env = environment(buildConfiguration()); + if (!env.hasKey(MAKEFLAGS)) + return false; + Utils::optional makeFlagsJobCount = argsJobCount(env.value(MAKEFLAGS)); + return makeFlagsJobCount.has_value() && *makeFlagsJobCount != m_userJobCount; } bool MakeStep::makeflagsContainsJobCount() const @@ -209,12 +237,12 @@ bool MakeStep::makeflagsContainsJobCount() const const Utils::Environment env = environment(buildConfiguration()); if (!env.hasKey(MAKEFLAGS)) return false; - return argsContainsJobCount(env.value(MAKEFLAGS)); + return argsJobCount(env.value(MAKEFLAGS)).has_value(); } bool MakeStep::userArgsContainsJobCount() const { - return argsContainsJobCount(m_makeArguments); + return argsJobCount(m_makeArguments).has_value(); } Utils::Environment MakeStep::environment(BuildConfiguration *bc) const @@ -452,7 +480,7 @@ void MakeStepConfigWidget::updateDetails() m_ui->userJobCount->setValue(m_makeStep->jobCount()); m_ui->overrideMakeflags->setCheckState( m_makeStep->jobCountOverridesMakeflags() ? Qt::Checked : Qt::Unchecked); - m_ui->nonOverrideWarning->setVisible(m_makeStep->makeflagsContainsJobCount() + m_ui->nonOverrideWarning->setVisible(m_makeStep->makeflagsJobCountMismatch() && !m_makeStep->jobCountOverridesMakeflags()); ProcessParameters param; diff --git a/src/plugins/projectexplorer/makestep.h b/src/plugins/projectexplorer/makestep.h index 156a4fe35de..4069f9a0f56 100644 --- a/src/plugins/projectexplorer/makestep.h +++ b/src/plugins/projectexplorer/makestep.h @@ -76,6 +76,7 @@ public: void setJobCountOverrideMakeflags(bool override); bool makeflagsContainsJobCount() const; bool userArgsContainsJobCount() const; + bool makeflagsJobCountMismatch() const; Utils::Environment environment(BuildConfiguration *bc) const;