diff --git a/src/libs/utils/macroexpander.cpp b/src/libs/utils/macroexpander.cpp index 63360c93f09..fdaf4c7aebc 100644 --- a/src/libs/utils/macroexpander.cpp +++ b/src/libs/utils/macroexpander.cpp @@ -19,8 +19,6 @@ namespace Utils { namespace Internal { -static Q_LOGGING_CATEGORY(expanderLog, "qtc.utils.macroexpander", QtWarningMsg) - const char kFilePathPostfix[] = ":FilePath"; const char kPathPostfix[] = ":Path"; const char kNativeFilePathPostfix[] = ":NativeFilePath"; @@ -413,7 +411,8 @@ QVariant MacroExpander::expandVariant(const QVariant &v) const return v; } -QString MacroExpander::expandProcessArgs(const QString &argsWithVariables, Utils::OsType osType) const +expected_str MacroExpander::expandProcessArgs( + const QString &argsWithVariables, Utils::OsType osType) const { QString result = argsWithVariables; const bool ok = ProcessArgs::expandMacros( @@ -421,7 +420,10 @@ QString MacroExpander::expandProcessArgs(const QString &argsWithVariables, Utils [this](const QString &str, int *pos, QString *ret) { return d->findMacro(str, pos, ret); }, osType); - QTC_ASSERT(ok, qCDebug(expanderLog) << "Expanding failed: " << argsWithVariables); + if (!ok) { + return make_unexpected( + Tr::tr("Failed to expand macros in process arguments: %1").arg(argsWithVariables)); + } return result; } diff --git a/src/libs/utils/macroexpander.h b/src/libs/utils/macroexpander.h index 5608b39e7a5..d080a9942ee 100644 --- a/src/libs/utils/macroexpander.h +++ b/src/libs/utils/macroexpander.h @@ -37,7 +37,7 @@ public: QByteArray expand(const QByteArray &stringWithVariables) const; QVariant expandVariant(const QVariant &v) const; - QString expandProcessArgs( + expected_str expandProcessArgs( const QString &argsWithVariables, Utils::OsType osType = Utils::HostOsInfo::hostOs()) const; using PrefixFunction = std::function; diff --git a/src/plugins/coreplugin/dialogs/externaltoolconfig.cpp b/src/plugins/coreplugin/dialogs/externaltoolconfig.cpp index 0adf830204f..95d37354da6 100644 --- a/src/plugins/coreplugin/dialogs/externaltoolconfig.cpp +++ b/src/plugins/coreplugin/dialogs/externaltoolconfig.cpp @@ -923,7 +923,12 @@ void ExternalToolConfig::addCategory() void ExternalToolConfig::updateEffectiveArguments() { - m_arguments->setToolTip(Utils::globalMacroExpander()->expandProcessArgs(m_arguments->text())); + const expected_str result = Utils::globalMacroExpander()->expandProcessArgs( + m_arguments->text()); + if (result) + m_arguments->setToolTip(*result); + else + m_arguments->setToolTip(result.error()); } void ExternalToolConfig::editEnvironmentChanges() diff --git a/src/plugins/coreplugin/externaltool.cpp b/src/plugins/coreplugin/externaltool.cpp index 87cc4d043fa..80bde5b67fc 100644 --- a/src/plugins/coreplugin/externaltool.cpp +++ b/src/plugins/coreplugin/externaltool.cpp @@ -598,7 +598,10 @@ bool ExternalToolRunner::resolve() } } - m_resolvedArguments = expander->expandProcessArgs(m_tool->arguments()); + const expected_str args = expander->expandProcessArgs(m_tool->arguments()); + QTC_ASSERT_EXPECTED(args, return false); + + m_resolvedArguments = *args; m_resolvedInput = expander->expand(m_tool->input()); m_resolvedWorkingDirectory = expander->expand(m_tool->workingDirectory()); diff --git a/src/plugins/projectexplorer/runconfigurationaspects.cpp b/src/plugins/projectexplorer/runconfigurationaspects.cpp index fa6d86a44b9..b7e5886cfb5 100644 --- a/src/plugins/projectexplorer/runconfigurationaspects.cpp +++ b/src/plugins/projectexplorer/runconfigurationaspects.cpp @@ -328,9 +328,11 @@ QString ArgumentsAspect::arguments() const return m_arguments; m_currentlyExpanding = true; - const QString expanded = macroExpander()->expandProcessArgs(m_arguments); + const expected_str expanded = macroExpander()->expandProcessArgs(m_arguments); + QTC_ASSERT_EXPECTED(expanded, return m_arguments); + m_currentlyExpanding = false; - return expanded; + return *expanded; } /*! @@ -962,7 +964,7 @@ X11ForwardingAspect::X11ForwardingAspect(AspectContainer *container) QString X11ForwardingAspect::display() const { - return !isChecked() ? QString() : macroExpander()->expandProcessArgs(value()); + return !isChecked() ? QString() : macroExpander()->expand(value()); } diff --git a/src/plugins/qmakeprojectmanager/qmakebuildconfiguration.cpp b/src/plugins/qmakeprojectmanager/qmakebuildconfiguration.cpp index 4a5ce922a44..5d5d1caa455 100644 --- a/src/plugins/qmakeprojectmanager/qmakebuildconfiguration.cpp +++ b/src/plugins/qmakeprojectmanager/qmakebuildconfiguration.cpp @@ -241,6 +241,7 @@ void QmakeBuildConfiguration::updateProblemLabel() bool targetMismatch = false; bool incompatibleBuild = false; bool allGood = false; + bool invalidArguments = false; // we only show if we actually have a qmake and makestep QString errorString; if (qmakeStep() && makeStep()) { @@ -258,6 +259,9 @@ void QmakeBuildConfiguration::updateProblemLabel() case QmakeBuildConfiguration::MakefileForWrongProject: targetMismatch = true; break; + case QmakeBuildConfiguration::InvalidArguments: + invalidArguments = true; + break; } } @@ -305,6 +309,10 @@ void QmakeBuildConfiguration::updateProblemLabel() } else if (unalignedBuildDir) { buildDirectoryAspect()->setProblem(unalignedBuildDirWarning()); return; + } else if (invalidArguments) { + buildDirectoryAspect()->setProblem( + Tr::tr("Starting qmake failed with the following error: %1").arg(errorString)); + return; } buildDirectoryAspect()->setProblem({}); @@ -516,8 +524,16 @@ QmakeBuildConfiguration::MakefileState QmakeBuildConfiguration::compareToImportF // and compare that on its own FilePath workingDirectory = makefile.parentDir(); QStringList actualArgs; - QString allArgs = macroExpander()->expandProcessArgs(qs->allArguments( - QtKitAspect::qtVersion(target()->kit()), QMakeStep::ArgumentFlag::Expand)); + expected_str expandResult = macroExpander()->expandProcessArgs( + qs->allArguments(QtKitAspect::qtVersion(target()->kit()), QMakeStep::ArgumentFlag::Expand)); + + if (!expandResult) { + if (errorString) + *errorString = expandResult.error(); + return InvalidArguments; + } + + QString allArgs = *expandResult; // This copies the settings from allArgs to actualArgs (minus some we // are not interested in), splitting them up into individual strings: extractSpecFromArguments(&allArgs, workingDirectory, version, &actualArgs); diff --git a/src/plugins/qmakeprojectmanager/qmakebuildconfiguration.h b/src/plugins/qmakeprojectmanager/qmakebuildconfiguration.h index f83c8228ce0..0715311822d 100644 --- a/src/plugins/qmakeprojectmanager/qmakebuildconfiguration.h +++ b/src/plugins/qmakeprojectmanager/qmakebuildconfiguration.h @@ -61,7 +61,13 @@ public: Utils::FilePath makefile() const; - enum MakefileState { MakefileMatches, MakefileForWrongProject, MakefileIncompatible, MakefileMissing }; + enum MakefileState { + MakefileMatches, + MakefileForWrongProject, + MakefileIncompatible, + MakefileMissing, + InvalidArguments + }; MakefileState compareToImportFrom(const Utils::FilePath &makefile, QString *errorString = nullptr); static QString extractSpecFromArguments( QString *arguments, const Utils::FilePath &directory, const QtSupport::QtVersion *version,