diff --git a/src/libs/utils/commandline.cpp b/src/libs/utils/commandline.cpp index e6740afb9e2..409c85f04da 100644 --- a/src/libs/utils/commandline.cpp +++ b/src/libs/utils/commandline.cpp @@ -26,6 +26,7 @@ #include "commandline.h" #include "environment.h" +#include "macroexpander.h" #include "qtcassert.h" #include "stringutils.h" @@ -1434,6 +1435,21 @@ CommandLine::CommandLine(const FilePath &exe, const QString &args, RawType) addArgs(args, Raw); } +CommandLine CommandLine::fromUserInput(const QString &cmdline, MacroExpander *expander) +{ + CommandLine cmd; + const int pos = cmdline.indexOf(' '); + if (pos == -1) { + cmd.m_executable = FilePath::fromString(cmdline); + } else { + cmd.m_executable = FilePath::fromString(cmdline.left(pos)); + cmd.m_arguments = cmdline.right(cmdline.length() - pos - 1); + if (expander) + cmd.m_arguments = expander->expand(cmd.m_arguments); + } + return cmd; +} + void CommandLine::addArg(const QString &arg) { ProcessArgs::addArg(&m_arguments, arg, m_executable.osType()); diff --git a/src/libs/utils/commandline.h b/src/libs/utils/commandline.h index 61c997bccd4..50634b1d809 100644 --- a/src/libs/utils/commandline.h +++ b/src/libs/utils/commandline.h @@ -37,6 +37,7 @@ namespace Utils { class AbstractMacroExpander; class CommandLine; class Environment; +class MacroExpander; class QTCREATOR_UTILS_EXPORT ProcessArgs { @@ -138,6 +139,8 @@ public: CommandLine(const FilePath &exe, const QStringList &args); CommandLine(const FilePath &exe, const QString &unparsedArgs, RawType); + static CommandLine fromUserInput(const QString &cmdline, MacroExpander *expander = nullptr); + void addArg(const QString &arg); void addArgs(const QStringList &inArgs); diff --git a/src/plugins/coreplugin/locator/executefilter.cpp b/src/plugins/coreplugin/locator/executefilter.cpp index fd31446636d..7d9a78b0637 100644 --- a/src/plugins/coreplugin/locator/executefilter.cpp +++ b/src/plugins/coreplugin/locator/executefilter.cpp @@ -102,15 +102,8 @@ void ExecuteFilter::accept(LocatorFilterEntry selection, workingDirectory = Utils::globalMacroExpander()->value("CurrentDocument:Project:Path", &found); ExecuteData d; - d.workingDirectory = workingDirectory; - const int pos = value.indexOf(' '); - if (pos == -1) { - d.executable = value; - } else { - d.executable = value.left(pos); - d.arguments = Utils::globalMacroExpander()->expand( - value.right(value.length() - pos - 1)); - } + d.command = CommandLine::fromUserInput(value, Utils::globalMacroExpander()); + d.workingDirectory = FilePath::fromString(workingDirectory); if (m_process) { const QString info(tr("Previous command is still running (\"%1\").\nDo you want to kill it?") @@ -166,10 +159,9 @@ void ExecuteFilter::runHeadCommand() { if (!m_taskQueue.isEmpty()) { const ExecuteData &d = m_taskQueue.head(); - const Utils::FilePath fullPath = Utils::Environment::systemEnvironment().searchInPath(d.executable); - if (fullPath.isEmpty()) { + if (d.command.executable().isEmpty()) { MessageManager::writeDisrupting( - tr("Could not find executable for \"%1\".").arg(d.executable)); + tr("Could not find executable for \"%1\".").arg(d.command.executable().toUserOutput())); m_taskQueue.dequeue(); runHeadCommand(); return; @@ -178,7 +170,7 @@ void ExecuteFilter::runHeadCommand() QTC_CHECK(!m_process); createProcess(); m_process->setWorkingDirectory(d.workingDirectory); - m_process->setCommand({fullPath, d.arguments, Utils::CommandLine::Raw}); + m_process->setCommand(d.command); m_process->start(); if (!m_process->waitForStarted(1000)) { MessageManager::writeFlashing( @@ -221,7 +213,5 @@ QString ExecuteFilter::headCommand() const if (m_taskQueue.isEmpty()) return QString(); const ExecuteData &data = m_taskQueue.head(); - if (data.arguments.isEmpty()) - return data.executable; - return data.executable + ' ' + data.arguments; + return data.command.toUserOutput(); } diff --git a/src/plugins/coreplugin/locator/executefilter.h b/src/plugins/coreplugin/locator/executefilter.h index cba5270f682..d787a2f6ecd 100644 --- a/src/plugins/coreplugin/locator/executefilter.h +++ b/src/plugins/coreplugin/locator/executefilter.h @@ -39,11 +39,11 @@ namespace Internal { class ExecuteFilter : public Core::ILocatorFilter { Q_OBJECT + struct ExecuteData { - QString executable; - QString arguments; - QString workingDirectory; + Utils::CommandLine command; + Utils::FilePath workingDirectory; }; public: