forked from qt-creator/qt-creator
Utils: Move ProcessArgs class into filepair of its own
There's not much interaction between ProcessArgs and QtcProcess and both .cpp are still quite big, with non-trivial bits. Change-Id: Id84202f6c34057bf87cc8f27fbb45f78f105e9a5 Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
@@ -30,8 +30,8 @@
|
|||||||
#include "sshsettings.h"
|
#include "sshsettings.h"
|
||||||
|
|
||||||
#include <utils/fileutils.h>
|
#include <utils/fileutils.h>
|
||||||
|
#include <utils/processargs.h>
|
||||||
#include <utils/qtcassert.h>
|
#include <utils/qtcassert.h>
|
||||||
#include <utils/qtcprocess.h>
|
|
||||||
|
|
||||||
#include <QByteArrayList>
|
#include <QByteArrayList>
|
||||||
#include <QFileInfo>
|
#include <QFileInfo>
|
||||||
|
@@ -36,7 +36,7 @@
|
|||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
|
|
||||||
#include <utils/algorithm.h>
|
#include <utils/algorithm.h>
|
||||||
#include <utils/qtcprocess.h>
|
#include <utils/processargs.h>
|
||||||
|
|
||||||
using namespace Utils;
|
using namespace Utils;
|
||||||
|
|
||||||
|
@@ -115,6 +115,7 @@ add_qtc_library(Utils
|
|||||||
porting.h
|
porting.h
|
||||||
portlist.cpp portlist.h
|
portlist.cpp portlist.h
|
||||||
predicates.h
|
predicates.h
|
||||||
|
processargs.cpp processargs.h
|
||||||
processhandle.cpp processhandle.h
|
processhandle.cpp processhandle.h
|
||||||
progressindicator.cpp progressindicator.h
|
progressindicator.cpp progressindicator.h
|
||||||
projectintropage.cpp projectintropage.h projectintropage.ui
|
projectintropage.cpp projectintropage.h projectintropage.ui
|
||||||
|
@@ -28,6 +28,7 @@
|
|||||||
#include <utils/algorithm.h>
|
#include <utils/algorithm.h>
|
||||||
#include <utils/environment.h>
|
#include <utils/environment.h>
|
||||||
#include <utils/hostosinfo.h>
|
#include <utils/hostosinfo.h>
|
||||||
|
#include <utils/processargs.h>
|
||||||
#include <utils/qtcassert.h>
|
#include <utils/qtcassert.h>
|
||||||
#include <utils/qtcprocess.h>
|
#include <utils/qtcprocess.h>
|
||||||
#include <utils/winutils.h>
|
#include <utils/winutils.h>
|
||||||
|
@@ -27,8 +27,8 @@
|
|||||||
#include "savefile.h"
|
#include "savefile.h"
|
||||||
|
|
||||||
#include "algorithm.h"
|
#include "algorithm.h"
|
||||||
|
#include "processargs.h"
|
||||||
#include "qtcassert.h"
|
#include "qtcassert.h"
|
||||||
#include "qtcprocess.h"
|
|
||||||
|
|
||||||
#include <QDataStream>
|
#include <QDataStream>
|
||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
|
@@ -26,8 +26,9 @@
|
|||||||
#include "macroexpander.h"
|
#include "macroexpander.h"
|
||||||
|
|
||||||
#include "algorithm.h"
|
#include "algorithm.h"
|
||||||
|
#include "fileutils.h"
|
||||||
|
#include "processargs.h"
|
||||||
#include "qtcassert.h"
|
#include "qtcassert.h"
|
||||||
#include "qtcprocess.h"
|
|
||||||
#include "stringutils.h"
|
#include "stringutils.h"
|
||||||
|
|
||||||
#include <QCoreApplication>
|
#include <QCoreApplication>
|
||||||
|
1412
src/libs/utils/processargs.cpp
Normal file
1412
src/libs/utils/processargs.cpp
Normal file
File diff suppressed because it is too large
Load Diff
133
src/libs/utils/processargs.h
Normal file
133
src/libs/utils/processargs.h
Normal file
@@ -0,0 +1,133 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
**
|
||||||
|
** Copyright (C) 2016 The Qt Company Ltd.
|
||||||
|
** Contact: https://www.qt.io/licensing/
|
||||||
|
**
|
||||||
|
** This file is part of Qt Creator.
|
||||||
|
**
|
||||||
|
** Commercial License Usage
|
||||||
|
** Licensees holding valid commercial Qt licenses may use this file in
|
||||||
|
** accordance with the commercial license agreement provided with the
|
||||||
|
** Software or, alternatively, in accordance with the terms contained in
|
||||||
|
** a written agreement between you and The Qt Company. For licensing terms
|
||||||
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
||||||
|
** information use the contact form at https://www.qt.io/contact-us.
|
||||||
|
**
|
||||||
|
** GNU General Public License Usage
|
||||||
|
** Alternatively, this file may be used under the terms of the GNU
|
||||||
|
** General Public License version 3 as published by the Free Software
|
||||||
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
||||||
|
** included in the packaging of this file. Please review the following
|
||||||
|
** information to ensure the GNU General Public License requirements will
|
||||||
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
||||||
|
**
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "utils_global.h"
|
||||||
|
|
||||||
|
#include "hostosinfo.h"
|
||||||
|
|
||||||
|
#include <QStringList>
|
||||||
|
|
||||||
|
namespace Utils {
|
||||||
|
|
||||||
|
class AbstractMacroExpander;
|
||||||
|
class Environment;
|
||||||
|
|
||||||
|
class QTCREATOR_UTILS_EXPORT ProcessArgs
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
static ProcessArgs createWindowsArgs(const QString &args);
|
||||||
|
static ProcessArgs createUnixArgs(const QStringList &args);
|
||||||
|
|
||||||
|
QString toWindowsArgs() const;
|
||||||
|
QStringList toUnixArgs() const;
|
||||||
|
QString toString() const;
|
||||||
|
|
||||||
|
enum SplitError {
|
||||||
|
SplitOk = 0, //! All went just fine
|
||||||
|
BadQuoting, //! Command contains quoting errors
|
||||||
|
FoundMeta //! Command contains complex shell constructs
|
||||||
|
};
|
||||||
|
|
||||||
|
//! Quote a single argument for usage in a unix shell command
|
||||||
|
static QString quoteArgUnix(const QString &arg);
|
||||||
|
//! Quote a single argument for usage in a shell command
|
||||||
|
static QString quoteArg(const QString &arg, OsType osType = HostOsInfo::hostOs());
|
||||||
|
//! Quote a single argument and append it to a shell command
|
||||||
|
static void addArg(QString *args, const QString &arg, OsType osType = HostOsInfo::hostOs());
|
||||||
|
//! Join an argument list into a shell command
|
||||||
|
static QString joinArgs(const QStringList &args, OsType osType = HostOsInfo::hostOs());
|
||||||
|
//! Prepare argument of a shell command for feeding into QProcess
|
||||||
|
static ProcessArgs prepareArgs(const QString &cmd, SplitError *err,
|
||||||
|
OsType osType = HostOsInfo::hostOs(),
|
||||||
|
const Environment *env = nullptr, const QString *pwd = nullptr,
|
||||||
|
bool abortOnMeta = true);
|
||||||
|
//! Prepare a shell command for feeding into QProcess
|
||||||
|
static bool prepareCommand(const QString &command, const QString &arguments,
|
||||||
|
QString *outCmd, ProcessArgs *outArgs, OsType osType = HostOsInfo::hostOs(),
|
||||||
|
const Environment *env = nullptr, const QString *pwd = nullptr);
|
||||||
|
//! Quote and append each argument to a shell command
|
||||||
|
static void addArgs(QString *args, const QStringList &inArgs);
|
||||||
|
//! Append already quoted arguments to a shell command
|
||||||
|
static void addArgs(QString *args, const QString &inArgs);
|
||||||
|
//! Split a shell command into separate arguments.
|
||||||
|
static QStringList splitArgs(const QString &cmd, OsType osType = HostOsInfo::hostOs(),
|
||||||
|
bool abortOnMeta = false, SplitError *err = nullptr,
|
||||||
|
const Environment *env = nullptr, const QString *pwd = nullptr);
|
||||||
|
//! Safely replace the expandos in a shell command
|
||||||
|
static bool expandMacros(QString *cmd, AbstractMacroExpander *mx,
|
||||||
|
OsType osType = HostOsInfo::hostOs());
|
||||||
|
static QString expandMacros(const QString &str, AbstractMacroExpander *mx,
|
||||||
|
OsType osType = HostOsInfo::hostOs());
|
||||||
|
|
||||||
|
/*! Iterate over arguments from a command line.
|
||||||
|
* Assumes that the name of the actual command is *not* part of the line.
|
||||||
|
* Terminates after the first command if the command line is complex.
|
||||||
|
*/
|
||||||
|
class QTCREATOR_UTILS_EXPORT ArgIterator {
|
||||||
|
public:
|
||||||
|
ArgIterator(QString *str, OsType osType = HostOsInfo::hostOs())
|
||||||
|
: m_str(str), m_osType(osType)
|
||||||
|
{}
|
||||||
|
//! Get the next argument. Returns false on encountering end of first command.
|
||||||
|
bool next();
|
||||||
|
//! True iff the argument is a plain string, possibly after unquoting.
|
||||||
|
bool isSimple() const { return m_simple; }
|
||||||
|
//! Return the string value of the current argument if it is simple, otherwise empty.
|
||||||
|
QString value() const { return m_value; }
|
||||||
|
//! Delete the last argument fetched via next() from the command line.
|
||||||
|
void deleteArg();
|
||||||
|
//! Insert argument into the command line after the last one fetched via next().
|
||||||
|
//! This may be used before the first call to next() to insert at the front.
|
||||||
|
void appendArg(const QString &str);
|
||||||
|
private:
|
||||||
|
QString *m_str, m_value;
|
||||||
|
int m_pos = 0;
|
||||||
|
int m_prev = -1;
|
||||||
|
bool m_simple;
|
||||||
|
OsType m_osType;
|
||||||
|
};
|
||||||
|
|
||||||
|
class QTCREATOR_UTILS_EXPORT ConstArgIterator {
|
||||||
|
public:
|
||||||
|
ConstArgIterator(const QString &str, OsType osType = HostOsInfo::hostOs())
|
||||||
|
: m_str(str), m_ait(&m_str, osType)
|
||||||
|
{}
|
||||||
|
bool next() { return m_ait.next(); }
|
||||||
|
bool isSimple() const { return m_ait.isSimple(); }
|
||||||
|
QString value() const { return m_ait.value(); }
|
||||||
|
private:
|
||||||
|
QString m_str;
|
||||||
|
ArgIterator m_ait;
|
||||||
|
};
|
||||||
|
|
||||||
|
private:
|
||||||
|
QString m_windowsArgs;
|
||||||
|
QStringList m_unixArgs;
|
||||||
|
bool m_isWindows;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace Utils
|
File diff suppressed because it is too large
Load Diff
@@ -28,6 +28,7 @@
|
|||||||
#include "utils_global.h"
|
#include "utils_global.h"
|
||||||
|
|
||||||
#include "environment.h"
|
#include "environment.h"
|
||||||
|
#include "processargs.h"
|
||||||
|
|
||||||
#include <QProcess>
|
#include <QProcess>
|
||||||
#include <QTextCodec>
|
#include <QTextCodec>
|
||||||
@@ -38,7 +39,6 @@ QT_FORWARD_DECLARE_CLASS(QDebug)
|
|||||||
|
|
||||||
namespace Utils {
|
namespace Utils {
|
||||||
|
|
||||||
class AbstractMacroExpander;
|
|
||||||
class CommandLine;
|
class CommandLine;
|
||||||
class Environment;
|
class Environment;
|
||||||
|
|
||||||
@@ -160,98 +160,4 @@ public:
|
|||||||
~SynchronousProcess() override;
|
~SynchronousProcess() override;
|
||||||
};
|
};
|
||||||
|
|
||||||
class QTCREATOR_UTILS_EXPORT ProcessArgs
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
static ProcessArgs createWindowsArgs(const QString &args);
|
|
||||||
static ProcessArgs createUnixArgs(const QStringList &args);
|
|
||||||
|
|
||||||
QString toWindowsArgs() const;
|
|
||||||
QStringList toUnixArgs() const;
|
|
||||||
QString toString() const;
|
|
||||||
|
|
||||||
enum SplitError {
|
|
||||||
SplitOk = 0, //! All went just fine
|
|
||||||
BadQuoting, //! Command contains quoting errors
|
|
||||||
FoundMeta //! Command contains complex shell constructs
|
|
||||||
};
|
|
||||||
|
|
||||||
//! Quote a single argument for usage in a unix shell command
|
|
||||||
static QString quoteArgUnix(const QString &arg);
|
|
||||||
//! Quote a single argument for usage in a shell command
|
|
||||||
static QString quoteArg(const QString &arg, OsType osType = HostOsInfo::hostOs());
|
|
||||||
//! Quote a single argument and append it to a shell command
|
|
||||||
static void addArg(QString *args, const QString &arg, OsType osType = HostOsInfo::hostOs());
|
|
||||||
//! Join an argument list into a shell command
|
|
||||||
static QString joinArgs(const QStringList &args, OsType osType = HostOsInfo::hostOs());
|
|
||||||
//! Prepare argument of a shell command for feeding into QProcess
|
|
||||||
static ProcessArgs prepareArgs(const QString &cmd, SplitError *err,
|
|
||||||
OsType osType = HostOsInfo::hostOs(),
|
|
||||||
const Environment *env = nullptr, const QString *pwd = nullptr,
|
|
||||||
bool abortOnMeta = true);
|
|
||||||
//! Prepare a shell command for feeding into QProcess
|
|
||||||
static bool prepareCommand(const QString &command, const QString &arguments,
|
|
||||||
QString *outCmd, ProcessArgs *outArgs, OsType osType = HostOsInfo::hostOs(),
|
|
||||||
const Environment *env = nullptr, const QString *pwd = nullptr);
|
|
||||||
//! Quote and append each argument to a shell command
|
|
||||||
static void addArgs(QString *args, const QStringList &inArgs);
|
|
||||||
//! Append already quoted arguments to a shell command
|
|
||||||
static void addArgs(QString *args, const QString &inArgs);
|
|
||||||
//! Split a shell command into separate arguments. ArgIterator is usually a better choice.
|
|
||||||
static QStringList splitArgs(const QString &cmd, OsType osType = HostOsInfo::hostOs(),
|
|
||||||
bool abortOnMeta = false, SplitError *err = nullptr,
|
|
||||||
const Environment *env = nullptr, const QString *pwd = nullptr);
|
|
||||||
//! Safely replace the expandos in a shell command
|
|
||||||
static bool expandMacros(QString *cmd, AbstractMacroExpander *mx,
|
|
||||||
OsType osType = HostOsInfo::hostOs());
|
|
||||||
static QString expandMacros(const QString &str, AbstractMacroExpander *mx,
|
|
||||||
OsType osType = HostOsInfo::hostOs());
|
|
||||||
|
|
||||||
/*! Iterate over arguments from a command line.
|
|
||||||
* Assumes that the name of the actual command is *not* part of the line.
|
|
||||||
* Terminates after the first command if the command line is complex.
|
|
||||||
*/
|
|
||||||
class QTCREATOR_UTILS_EXPORT ArgIterator {
|
|
||||||
public:
|
|
||||||
ArgIterator(QString *str, OsType osType = HostOsInfo::hostOs())
|
|
||||||
: m_str(str), m_osType(osType)
|
|
||||||
{}
|
|
||||||
//! Get the next argument. Returns false on encountering end of first command.
|
|
||||||
bool next();
|
|
||||||
//! True iff the argument is a plain string, possibly after unquoting.
|
|
||||||
bool isSimple() const { return m_simple; }
|
|
||||||
//! Return the string value of the current argument if it is simple, otherwise empty.
|
|
||||||
QString value() const { return m_value; }
|
|
||||||
//! Delete the last argument fetched via next() from the command line.
|
|
||||||
void deleteArg();
|
|
||||||
//! Insert argument into the command line after the last one fetched via next().
|
|
||||||
//! This may be used before the first call to next() to insert at the front.
|
|
||||||
void appendArg(const QString &str);
|
|
||||||
private:
|
|
||||||
QString *m_str, m_value;
|
|
||||||
int m_pos = 0;
|
|
||||||
int m_prev = -1;
|
|
||||||
bool m_simple;
|
|
||||||
OsType m_osType;
|
|
||||||
};
|
|
||||||
|
|
||||||
class QTCREATOR_UTILS_EXPORT ConstArgIterator {
|
|
||||||
public:
|
|
||||||
ConstArgIterator(const QString &str, OsType osType = HostOsInfo::hostOs())
|
|
||||||
: m_str(str), m_ait(&m_str, osType)
|
|
||||||
{}
|
|
||||||
bool next() { return m_ait.next(); }
|
|
||||||
bool isSimple() const { return m_ait.isSimple(); }
|
|
||||||
QString value() const { return m_ait.value(); }
|
|
||||||
private:
|
|
||||||
QString m_str;
|
|
||||||
ArgIterator m_ait;
|
|
||||||
};
|
|
||||||
|
|
||||||
private:
|
|
||||||
QString m_windowsArgs;
|
|
||||||
QStringList m_unixArgs;
|
|
||||||
bool m_isWindows;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace Utils
|
} // namespace Utils
|
||||||
|
@@ -34,6 +34,7 @@ SOURCES += \
|
|||||||
$$PWD/namevalueitem.cpp \
|
$$PWD/namevalueitem.cpp \
|
||||||
$$PWD/namevaluemodel.cpp \
|
$$PWD/namevaluemodel.cpp \
|
||||||
$$PWD/namevaluesdialog.cpp \
|
$$PWD/namevaluesdialog.cpp \
|
||||||
|
$$PWD/processargs.cpp \
|
||||||
$$PWD/qrcparser.cpp \
|
$$PWD/qrcparser.cpp \
|
||||||
$$PWD/qtcprocess.cpp \
|
$$PWD/qtcprocess.cpp \
|
||||||
$$PWD/reloadpromptutils.cpp \
|
$$PWD/reloadpromptutils.cpp \
|
||||||
@@ -155,7 +156,7 @@ HEADERS += \
|
|||||||
$$PWD/namevalueitem.h \
|
$$PWD/namevalueitem.h \
|
||||||
$$PWD/namevaluemodel.h \
|
$$PWD/namevaluemodel.h \
|
||||||
$$PWD/namevaluesdialog.h \
|
$$PWD/namevaluesdialog.h \
|
||||||
$$PWD/pointeralgorithm.h \
|
$$PWD/processargs.h \
|
||||||
$$PWD/qrcparser.h \
|
$$PWD/qrcparser.h \
|
||||||
$$PWD/qtcprocess.h \
|
$$PWD/qtcprocess.h \
|
||||||
$$PWD/span.h \
|
$$PWD/span.h \
|
||||||
|
@@ -203,6 +203,8 @@ Project {
|
|||||||
"porting.h",
|
"porting.h",
|
||||||
"portlist.cpp",
|
"portlist.cpp",
|
||||||
"portlist.h",
|
"portlist.h",
|
||||||
|
"processargs.cpp",
|
||||||
|
"processargs.h",
|
||||||
"processhandle.cpp",
|
"processhandle.cpp",
|
||||||
"processhandle.h",
|
"processhandle.h",
|
||||||
"progressindicator.cpp",
|
"progressindicator.cpp",
|
||||||
|
@@ -34,7 +34,7 @@
|
|||||||
#include <utils/consoleprocess.h>
|
#include <utils/consoleprocess.h>
|
||||||
#include <utils/environment.h>
|
#include <utils/environment.h>
|
||||||
#include <utils/hostosinfo.h>
|
#include <utils/hostosinfo.h>
|
||||||
#include <utils/qtcprocess.h>
|
#include <utils/processargs.h>
|
||||||
#include <utils/textfileformat.h>
|
#include <utils/textfileformat.h>
|
||||||
#include <utils/unixutils.h>
|
#include <utils/unixutils.h>
|
||||||
|
|
||||||
|
@@ -34,8 +34,8 @@
|
|||||||
#include <utils/fancylineedit.h>
|
#include <utils/fancylineedit.h>
|
||||||
#include <utils/macroexpander.h>
|
#include <utils/macroexpander.h>
|
||||||
#include <utils/pathchooser.h>
|
#include <utils/pathchooser.h>
|
||||||
|
#include <utils/processargs.h>
|
||||||
#include <utils/qtcassert.h>
|
#include <utils/qtcassert.h>
|
||||||
#include <utils/qtcprocess.h>
|
|
||||||
#include <utils/stringutils.h>
|
#include <utils/stringutils.h>
|
||||||
#include <utils/variablechooser.h>
|
#include <utils/variablechooser.h>
|
||||||
|
|
||||||
|
@@ -86,7 +86,7 @@ extend_qtc_executable(sdktool
|
|||||||
persistentsettings.cpp persistentsettings.h
|
persistentsettings.cpp persistentsettings.h
|
||||||
porting.h
|
porting.h
|
||||||
qtcassert.cpp qtcassert.h
|
qtcassert.cpp qtcassert.h
|
||||||
qtcprocess.cpp qtcprocess.h
|
processargs.cpp processargs.h
|
||||||
savefile.cpp savefile.h
|
savefile.cpp savefile.h
|
||||||
stringutils.cpp stringutils.h
|
stringutils.cpp stringutils.h
|
||||||
)
|
)
|
||||||
|
@@ -38,7 +38,7 @@ SOURCES += \
|
|||||||
$$UTILS/namevalueitem.cpp \
|
$$UTILS/namevalueitem.cpp \
|
||||||
$$UTILS/persistentsettings.cpp \
|
$$UTILS/persistentsettings.cpp \
|
||||||
$$UTILS/qtcassert.cpp \
|
$$UTILS/qtcassert.cpp \
|
||||||
$$UTILS/qtcprocess.cpp \
|
$$UTILS/processargs.cpp \
|
||||||
$$UTILS/savefile.cpp \
|
$$UTILS/savefile.cpp \
|
||||||
$$UTILS/stringutils.cpp
|
$$UTILS/stringutils.cpp
|
||||||
|
|
||||||
@@ -71,7 +71,7 @@ HEADERS += \
|
|||||||
$$UTILS/namevalueitem.h \
|
$$UTILS/namevalueitem.h \
|
||||||
$$UTILS/persistentsettings.h \
|
$$UTILS/persistentsettings.h \
|
||||||
$$UTILS/qtcassert.h \
|
$$UTILS/qtcassert.h \
|
||||||
$$UTILS/qtcprocess.h \
|
$$UTILS/processargs.h \
|
||||||
$$UTILS/savefile.h \
|
$$UTILS/savefile.h \
|
||||||
$$UTILS/porting.h
|
$$UTILS/porting.h
|
||||||
|
|
||||||
|
@@ -75,8 +75,8 @@ QtcTool {
|
|||||||
"namevalueitem.cpp", "namevalueitem.h",
|
"namevalueitem.cpp", "namevalueitem.h",
|
||||||
"persistentsettings.cpp", "persistentsettings.h",
|
"persistentsettings.cpp", "persistentsettings.h",
|
||||||
"porting.h",
|
"porting.h",
|
||||||
|
"processargs.cpp", "processargs.h",
|
||||||
"qtcassert.cpp", "qtcassert.h",
|
"qtcassert.cpp", "qtcassert.h",
|
||||||
"qtcprocess.cpp", "qtcprocess.h",
|
|
||||||
"savefile.cpp", "savefile.h",
|
"savefile.cpp", "savefile.h",
|
||||||
"stringutils.cpp"
|
"stringutils.cpp"
|
||||||
]
|
]
|
||||||
|
Reference in New Issue
Block a user