From 3d7cbe122c3011f11e953c50c60ac92e613bda0c Mon Sep 17 00:00:00 2001 From: Marcus Tillmanns Date: Thu, 16 Jan 2025 10:48:17 +0100 Subject: [PATCH] Utils: Add overloads for CommandLine with osType In the next commit we want to test these functions, so we need to make sure that we can specify their osType. We will also need these functions when we are combining command lines from different platforms e.g. on docker where the host might be windows, but the docker image is Linux (or vice versa). Task-number: QTCREATORBUG-32325 Change-Id: I7d01bdc5f292b6bf6b76d03856f6d4e588e371ab Reviewed-by: hjk --- src/libs/utils/commandline.cpp | 15 +++++++++++++++ src/libs/utils/commandline.h | 3 +++ 2 files changed, 18 insertions(+) diff --git a/src/libs/utils/commandline.cpp b/src/libs/utils/commandline.cpp index 1da60c3565c..0217d38fadf 100644 --- a/src/libs/utils/commandline.cpp +++ b/src/libs/utils/commandline.cpp @@ -628,6 +628,12 @@ void ProcessArgs::addArgs(QString *args, const QStringList &inArgs) addArg(args, arg); } +void ProcessArgs::addArgs(QString *args, const QStringList &inArgs, OsType osType) +{ + for (const QString &arg : inArgs) + addArg(args, arg, osType); +} + CommandLine &CommandLine::operator<<(const QString &arg) { addArg(arg); @@ -1543,6 +1549,15 @@ void CommandLine::addCommandLineAsSingleArg(const CommandLine &cmd) addArg(combined); } +void CommandLine::addCommandLineAsSingleArg(const CommandLine &cmd, OsType osType) +{ + QString combined; + ProcessArgs::addArg(&combined, cmd.executable().path(), osType); + ProcessArgs::addArgs(&combined, cmd.arguments()); + + addArg(combined, osType); +} + void CommandLine::addCommandLineWithAnd(const CommandLine &cmd) { if (m_executable.isEmpty()) { diff --git a/src/libs/utils/commandline.h b/src/libs/utils/commandline.h index 78f756a9f61..22731264c3d 100644 --- a/src/libs/utils/commandline.h +++ b/src/libs/utils/commandline.h @@ -53,6 +53,8 @@ public: const Environment *env = nullptr, const FilePath *pwd = nullptr); //! Quote and append each argument to a shell command static void addArgs(QString *args, const QStringList &inArgs); + //! Quote and append each argument to a shell command + static void addArgs(QString *args, const QStringList &inArgs, OsType osType); //! Append already quoted arguments to a shell command static void addArgs(QString *args, const QString &inArgs); //! Split a shell command into separate arguments. @@ -170,6 +172,7 @@ public: void addCommandLineAsArgs(const CommandLine &cmd, RawType); void addCommandLineAsSingleArg(const CommandLine &cmd); + void addCommandLineAsSingleArg(const CommandLine &cmd, OsType osType); void addCommandLineWithAnd(const CommandLine &cmd); QString toUserOutput() const;