From 20a63d6c7e080f52a5749bbc7a0997d4d5753f46 Mon Sep 17 00:00:00 2001 From: hjk Date: Thu, 12 Aug 2021 13:04:22 +0200 Subject: [PATCH] Utils: Drop OsType parameter from CommandLine functions The type is implicitly given by the command's executble FilePath. Also, rename the rarely used addArgs(const CommandLine &) overload to addCommandLineAsArgs() and make it strip scheme and host from the wrapped executable as there are no uses expected where keeping them would be the right thing. Change-Id: Id0b76778e7e01ac16e477f36bf30bb28d96bb177 Reviewed-by: Artem Sokolovskii Reviewed-by: Christian Stenger --- src/libs/utils/commandline.cpp | 18 +++++++++--------- src/libs/utils/commandline.h | 9 +++++---- src/plugins/debugger/gdb/gdbengine.cpp | 2 +- src/plugins/docker/dockerdevice.cpp | 6 ++---- .../projectexplorer/applicationlauncher.cpp | 2 +- src/plugins/qnx/qnxanalyzesupport.cpp | 3 +-- .../remotelinuxqmltoolingsupport.cpp | 2 +- 7 files changed, 20 insertions(+), 22 deletions(-) diff --git a/src/libs/utils/commandline.cpp b/src/libs/utils/commandline.cpp index de0128c3be2..e6740afb9e2 100644 --- a/src/libs/utils/commandline.cpp +++ b/src/libs/utils/commandline.cpp @@ -1434,23 +1434,23 @@ CommandLine::CommandLine(const FilePath &exe, const QString &args, RawType) addArgs(args, Raw); } -void CommandLine::addArg(const QString &arg, OsType osType) +void CommandLine::addArg(const QString &arg) { - ProcessArgs::addArg(&m_arguments, arg, osType); + ProcessArgs::addArg(&m_arguments, arg, m_executable.osType()); } -void CommandLine::addArgs(const QStringList &inArgs, OsType osType) +void CommandLine::addArgs(const QStringList &inArgs) { for (const QString &arg : inArgs) - addArg(arg, osType); + addArg(arg); } // Adds cmd's executable and arguments one by one to this commandline. // Useful for 'sudo', 'nice', etc -void CommandLine::addArgs(const CommandLine &cmd, OsType osType) +void CommandLine::addCommandLineAsArgs(const CommandLine &cmd) { - addArg(cmd.executable().toString()); - addArgs(cmd.splitArguments(osType)); + addArg(cmd.executable().path()); + addArgs(cmd.splitArguments()); } void CommandLine::addArgs(const QString &inArgs, RawType) @@ -1466,9 +1466,9 @@ QString CommandLine::toUserOutput() const return res; } -QStringList CommandLine::splitArguments(OsType osType) const +QStringList CommandLine::splitArguments() const { - return ProcessArgs::splitArgs(m_arguments, osType); + return ProcessArgs::splitArgs(m_arguments, m_executable.osType()); } } // namespace Utils diff --git a/src/libs/utils/commandline.h b/src/libs/utils/commandline.h index d287bb04bb4..61c997bccd4 100644 --- a/src/libs/utils/commandline.h +++ b/src/libs/utils/commandline.h @@ -138,9 +138,10 @@ public: CommandLine(const FilePath &exe, const QStringList &args); CommandLine(const FilePath &exe, const QString &unparsedArgs, RawType); - void addArg(const QString &arg, OsType osType = HostOsInfo::hostOs()); - void addArgs(const QStringList &inArgs, OsType osType = HostOsInfo::hostOs()); - void addArgs(const CommandLine &cmd, OsType osType = HostOsInfo::hostOs()); + void addArg(const QString &arg); + void addArgs(const QStringList &inArgs); + + void addCommandLineAsArgs(const CommandLine &cmd); void addArgs(const QString &inArgs, RawType); @@ -152,7 +153,7 @@ public: QString arguments() const { return m_arguments; } void setArguments(const QString &args) { m_arguments = args; } - QStringList splitArguments(OsType osType = HostOsInfo::hostOs()) const; + QStringList splitArguments() const; bool isEmpty() const { return m_executable.isEmpty(); } diff --git a/src/plugins/debugger/gdb/gdbengine.cpp b/src/plugins/debugger/gdb/gdbengine.cpp index 271dcb45ebe..fac1181af03 100644 --- a/src/plugins/debugger/gdb/gdbengine.cpp +++ b/src/plugins/debugger/gdb/gdbengine.cpp @@ -3841,7 +3841,7 @@ void GdbEngine::setupEngine() Environment gdbEnv = rp.debugger.environment; if (rp.runAsRoot) { CommandLine wrapped("sudo", {"-A"}); - wrapped.addArgs(gdbCommand); + wrapped.addCommandLineAsArgs(gdbCommand); gdbCommand = wrapped; RunControl::provideAskPassEntry(gdbEnv); } diff --git a/src/plugins/docker/dockerdevice.cpp b/src/plugins/docker/dockerdevice.cpp index d829a70b87b..acf3dd209de 100644 --- a/src/plugins/docker/dockerdevice.cpp +++ b/src/plugins/docker/dockerdevice.cpp @@ -1430,7 +1430,6 @@ void DockerDevice::runProcess(QtcProcess &process) const } const FilePath workingDir = process.workingDirectory(); - const CommandLine origCmd = process.commandLine(); const Environment env = process.environment(); CommandLine cmd{"docker", {"exec"}}; @@ -1450,8 +1449,7 @@ void DockerDevice::runProcess(QtcProcess &process) const // } } cmd.addArg(d->m_container); - cmd.addArg(origCmd.executable().path()); // Cut off the docker://.../ bits. - cmd.addArgs(origCmd.splitArguments(osType())); + cmd.addCommandLineAsArgs(process.commandLine()); LOG("Run" << cmd.toUserOutput() << " in " << workingDir.toUserOutput()); @@ -1491,7 +1489,7 @@ bool DockerDevicePrivate::runInContainer(const CommandLine &cmd) const if (!DockerPlugin::isDaemonRunning().value_or(false)) return false; CommandLine dcmd{"docker", {"exec", m_container}}; - dcmd.addArgs(cmd); + dcmd.addCommandLineAsArgs(cmd); QtcProcess proc; proc.setCommand(dcmd); diff --git a/src/plugins/projectexplorer/applicationlauncher.cpp b/src/plugins/projectexplorer/applicationlauncher.cpp index 8644ec99483..c0e5d70e6ed 100644 --- a/src/plugins/projectexplorer/applicationlauncher.cpp +++ b/src/plugins/projectexplorer/applicationlauncher.cpp @@ -393,7 +393,7 @@ void ApplicationLauncherPrivate::start(const Runnable &runnable, const IDevice:: CommandLine cmdLine = runnable.command; if (m_runAsRoot) { CommandLine wrapped("sudo", {"-A"}); - wrapped.addArgs(cmdLine); + wrapped.addCommandLineAsArgs(cmdLine); cmdLine = wrapped; } diff --git a/src/plugins/qnx/qnxanalyzesupport.cpp b/src/plugins/qnx/qnxanalyzesupport.cpp index 05b45e155c6..a7bfd50cffe 100644 --- a/src/plugins/qnx/qnxanalyzesupport.cpp +++ b/src/plugins/qnx/qnxanalyzesupport.cpp @@ -61,8 +61,7 @@ QnxQmlProfilerSupport::QnxQmlProfilerSupport(RunControl *runControl) profiler->recordData("QmlServerUrl", serverUrl); Runnable r = runControl->runnable(); - r.command.addArg(QmlDebug::qmlDebugTcpArguments(QmlDebug::QmlProfilerServices, serverUrl), - Utils::OsTypeOtherUnix); + r.command.addArg(QmlDebug::qmlDebugTcpArguments(QmlDebug::QmlProfilerServices, serverUrl)); doStart(r, runControl->device()); }); diff --git a/src/plugins/remotelinux/remotelinuxqmltoolingsupport.cpp b/src/plugins/remotelinux/remotelinuxqmltoolingsupport.cpp index a83edd88c45..674371278f6 100644 --- a/src/plugins/remotelinux/remotelinuxqmltoolingsupport.cpp +++ b/src/plugins/remotelinux/remotelinuxqmltoolingsupport.cpp @@ -58,7 +58,7 @@ RemoteLinuxQmlToolingSupport::RemoteLinuxQmlToolingSupport(RunControl *runContro QmlDebug::QmlDebugServicesPreset services = QmlDebug::servicesForRunMode(runControl->runMode()); Runnable r = runControl->runnable(); - r.command.addArg(QmlDebug::qmlDebugTcpArguments(services, serverUrl), OsTypeLinux); + r.command.addArg(QmlDebug::qmlDebugTcpArguments(services, serverUrl)); doStart(r, runControl->device()); });