Move CommandLine out of fileutils.h

to ProcessArgs and rename the files to commandline.*.
fileutils was a strange place for CommandLine, and this
reduces the dependencies needed for sdktool.

Change-Id: I9d7e8ffe8a3560f5d12934457b086f9446976883
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Eike Ziller
2021-05-11 14:34:56 +02:00
parent 0c8d8c6b2a
commit f18ac508e8
28 changed files with 139 additions and 124 deletions

View File

@@ -30,7 +30,7 @@
#include "sshsettings.h"
#include <utils/fileutils.h>
#include <utils/processargs.h>
#include <utils/commandline.h>
#include <utils/qtcassert.h>
#include <QByteArrayList>

View File

@@ -36,7 +36,7 @@
#include <QTimer>
#include <utils/algorithm.h>
#include <utils/processargs.h>
#include <utils/commandline.h>
using namespace Utils;

View File

@@ -28,7 +28,7 @@
#include "sshlogging_p.h"
#include "sshsettings.h"
#include <utils/fileutils.h>
#include <utils/commandline.h>
#include <utils/qtcassert.h>
#include <QDir>

View File

@@ -28,7 +28,9 @@
#include "ssh_global.h"
#include "sshprocess.h"
#include <utils/fileutils.h>
namespace Utils {
class CommandLine;
}
namespace QSsh {
class SshConnection;

View File

@@ -24,6 +24,7 @@ add_qtc_library(Utils
checkablemessagebox.cpp checkablemessagebox.h
classnamevalidatinglineedit.cpp classnamevalidatinglineedit.h
codegeneration.cpp codegeneration.h
commandline.cpp commandline.h
completinglineedit.cpp completinglineedit.h
completingtextedit.cpp completingtextedit.h
consoleprocess.cpp consoleprocess.h
@@ -115,7 +116,6 @@ add_qtc_library(Utils
porting.h
portlist.cpp portlist.h
predicates.h
processargs.cpp processargs.h
processhandle.cpp processhandle.h
progressindicator.cpp progressindicator.h
projectintropage.cpp projectintropage.h projectintropage.ui

View File

@@ -23,7 +23,7 @@
**
****************************************************************************/
#include "processargs.h"
#include "commandline.h"
#include "environment.h"
#include "qtcassert.h"
@@ -1409,4 +1409,74 @@ QString ProcessArgs::toString() const
return ProcessArgs::joinArgs(m_unixArgs, OsTypeLinux);
}
/*!
\class Utils::CommandLine
\brief The CommandLine class represents a command line of a QProcess or
similar utility.
*/
CommandLine::CommandLine() = default;
CommandLine::CommandLine(const QString &executable)
: m_executable(FilePath::fromString(executable))
{}
CommandLine::CommandLine(const FilePath &executable)
: m_executable(executable)
{}
CommandLine::CommandLine(const QString &exe, const QStringList &args)
: CommandLine(FilePath::fromString(exe), args)
{}
CommandLine::CommandLine(const FilePath &exe, const QStringList &args)
: m_executable(exe)
{
addArgs(args);
}
CommandLine::CommandLine(const FilePath &exe, const QString &args, RawType)
: m_executable(exe)
{
addArgs(args, Raw);
}
void CommandLine::addArg(const QString &arg, OsType osType)
{
ProcessArgs::addArg(&m_arguments, arg, osType);
}
void CommandLine::addArgs(const QStringList &inArgs, OsType osType)
{
for (const QString &arg : inArgs)
addArg(arg, osType);
}
// 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)
{
addArg(cmd.executable().toString());
addArgs(cmd.splitArguments(osType));
}
void CommandLine::addArgs(const QString &inArgs, RawType)
{
ProcessArgs::addArgs(&m_arguments, inArgs);
}
QString CommandLine::toUserOutput() const
{
QString res = m_executable.toUserOutput();
if (!m_arguments.isEmpty())
res += ' ' + m_arguments;
return res;
}
QStringList CommandLine::splitArguments(OsType osType) const
{
return ProcessArgs::splitArgs(m_arguments, osType);
}
} // namespace Utils

View File

@@ -27,6 +27,7 @@
#include "utils_global.h"
#include "fileutils.h"
#include "hostosinfo.h"
#include <QStringList>
@@ -130,4 +131,35 @@ private:
bool m_isWindows;
};
class QTCREATOR_UTILS_EXPORT CommandLine
{
public:
enum RawType { Raw };
CommandLine();
explicit CommandLine(const QString &executable);
explicit CommandLine(const FilePath &executable);
CommandLine(const QString &exe, const QStringList &args);
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 addArgs(const QString &inArgs, RawType);
QString toUserOutput() const;
FilePath executable() const { return m_executable; }
QString arguments() const { return m_arguments; }
QStringList splitArguments(OsType osType = HostOsInfo::hostOs()) const;
private:
FilePath m_executable;
QString m_arguments;
};
} // namespace Utils
Q_DECLARE_METATYPE(Utils::CommandLine)

View File

@@ -28,7 +28,7 @@
#include <utils/algorithm.h>
#include <utils/environment.h>
#include <utils/hostosinfo.h>
#include <utils/processargs.h>
#include <utils/commandline.h>
#include <utils/qtcassert.h>
#include <utils/qtcprocess.h>
#include <utils/winutils.h>

View File

@@ -27,7 +27,7 @@
#include "savefile.h"
#include "algorithm.h"
#include "processargs.h"
#include "commandline.h"
#include "qtcassert.h"
#include <QDataStream>
@@ -65,76 +65,6 @@ namespace Utils {
static DeviceFileHooks s_deviceHooks;
/*! \class Utils::CommandLine
\brief The CommandLine class represents a command line of a QProcess
or similar utility.
*/
CommandLine::CommandLine() = default;
CommandLine::CommandLine(const QString &executable)
: m_executable(FilePath::fromString(executable))
{}
CommandLine::CommandLine(const FilePath &executable)
: m_executable(executable)
{}
CommandLine::CommandLine(const QString &exe, const QStringList &args)
: CommandLine(FilePath::fromString(exe), args)
{}
CommandLine::CommandLine(const FilePath &exe, const QStringList &args)
: m_executable(exe)
{
addArgs(args);
}
CommandLine::CommandLine(const FilePath &exe, const QString &args, RawType)
: m_executable(exe)
{
addArgs(args, Raw);
}
void CommandLine::addArg(const QString &arg, OsType osType)
{
ProcessArgs::addArg(&m_arguments, arg, osType);
}
void CommandLine::addArgs(const QStringList &inArgs, OsType osType)
{
for (const QString &arg : inArgs)
addArg(arg, osType);
}
// 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)
{
addArg(cmd.executable().toString());
addArgs(cmd.splitArguments(osType));
}
void CommandLine::addArgs(const QString &inArgs, RawType)
{
ProcessArgs::addArgs(&m_arguments, inArgs);
}
QString CommandLine::toUserOutput() const
{
QString res = m_executable.toUserOutput();
if (!m_arguments.isEmpty())
res += ' ' + m_arguments;
return res;
}
QStringList CommandLine::splitArguments(OsType osType) const
{
return ProcessArgs::splitArgs(m_arguments, osType);
}
/*! \class Utils::FileUtils
\brief The FileUtils class contains file and directory related convenience

View File

@@ -172,35 +172,6 @@ QTCREATOR_UTILS_EXPORT QTextStream &operator<<(QTextStream &s, const FilePath &f
using FilePaths = QList<FilePath>;
class QTCREATOR_UTILS_EXPORT CommandLine
{
public:
enum RawType { Raw };
CommandLine();
explicit CommandLine(const QString &executable);
explicit CommandLine(const FilePath &executable);
CommandLine(const QString &exe, const QStringList &args);
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 addArgs(const QString &inArgs, RawType);
QString toUserOutput() const;
FilePath executable() const { return m_executable; }
QString arguments() const { return m_arguments; }
QStringList splitArguments(OsType osType = HostOsInfo::hostOs()) const;
private:
FilePath m_executable;
QString m_arguments;
};
class QTCREATOR_UTILS_EXPORT FileUtils {
public:
#ifdef QT_GUI_LIB
@@ -402,4 +373,3 @@ template<> struct QTCREATOR_UTILS_EXPORT hash<Utils::FilePath>
} // namespace std
Q_DECLARE_METATYPE(Utils::FilePath)
Q_DECLARE_METATYPE(Utils::CommandLine)

View File

@@ -27,7 +27,7 @@
#include "algorithm.h"
#include "fileutils.h"
#include "processargs.h"
#include "commandline.h"
#include "qtcassert.h"
#include "stringutils.h"

View File

@@ -28,7 +28,7 @@
#include "stringutils.h"
#include "executeondestruction.h"
#include "hostosinfo.h"
#include "processargs.h"
#include "commandline.h"
#include "qtcassert.h"
#include <QCoreApplication>

View File

@@ -28,7 +28,7 @@
#include "utils_global.h"
#include "environment.h"
#include "processargs.h"
#include "commandline.h"
#include <QProcess>
#include <QTextCodec>

View File

@@ -34,7 +34,7 @@ SOURCES += \
$$PWD/namevalueitem.cpp \
$$PWD/namevaluemodel.cpp \
$$PWD/namevaluesdialog.cpp \
$$PWD/processargs.cpp \
$$PWD/commandline.cpp \
$$PWD/qrcparser.cpp \
$$PWD/qtcprocess.cpp \
$$PWD/reloadpromptutils.cpp \
@@ -156,7 +156,7 @@ HEADERS += \
$$PWD/namevalueitem.h \
$$PWD/namevaluemodel.h \
$$PWD/namevaluesdialog.h \
$$PWD/processargs.h \
$$PWD/commandline.h \
$$PWD/qrcparser.h \
$$PWD/qtcprocess.h \
$$PWD/span.h \

View File

@@ -64,6 +64,8 @@ Project {
"classnamevalidatinglineedit.h",
"codegeneration.cpp",
"codegeneration.h",
"commandline.cpp",
"commandline.h",
"completinglineedit.cpp",
"completinglineedit.h",
"completingtextedit.cpp",
@@ -203,8 +205,6 @@ Project {
"porting.h",
"portlist.cpp",
"portlist.h",
"processargs.cpp",
"processargs.h",
"processhandle.cpp",
"processhandle.h",
"progressindicator.cpp",

View File

@@ -50,6 +50,7 @@
#include <extensionsystem/pluginspec.h>
#include <utils/algorithm.h>
#include <utils/checkablemessagebox.h>
#include <utils/commandline.h>
#include <utils/infobar.h>
#include <utils/macroexpander.h>
#include <utils/mimetypes/mimedatabase.h>

View File

@@ -34,7 +34,7 @@
#include <utils/consoleprocess.h>
#include <utils/environment.h>
#include <utils/hostosinfo.h>
#include <utils/processargs.h>
#include <utils/commandline.h>
#include <utils/textfileformat.h>
#include <utils/unixutils.h>

View File

@@ -34,7 +34,7 @@
#include <utils/fancylineedit.h>
#include <utils/macroexpander.h>
#include <utils/pathchooser.h>
#include <utils/processargs.h>
#include <utils/commandline.h>
#include <utils/qtcassert.h>
#include <utils/stringutils.h>
#include <utils/variablechooser.h>

View File

@@ -29,9 +29,8 @@
#include <coreplugin/dialogs/ioptionspage.h>
#include <utils/fileutils.h>
#include <QAbstractItemModel>
#include <QCoreApplication>
#include <QJsonObject>
#include <QLabel>
#include <QPointer>
@@ -44,6 +43,7 @@ class QLineEdit;
QT_END_NAMESPACE
namespace Utils {
class CommandLine;
class FilePath;
class PathChooser;
class FancyLineEdit;

View File

@@ -27,6 +27,7 @@
#include "versionhelper.h"
#include <utils/commandline.h>
#include <utils/environment.h>
#include <utils/fileutils.h>
#include <utils/id.h>

View File

@@ -29,6 +29,10 @@
#include <QProcess>
namespace Utils {
class CommandLine;
}
namespace ProjectExplorer {
class ProcessParameters;

View File

@@ -33,6 +33,10 @@
#include <QObject>
namespace Utils {
class CommandLine;
}
namespace ProjectExplorer {
class BuildConfiguration;

View File

@@ -27,6 +27,7 @@
#include "projectexplorer_export.h"
#include <utils/commandline.h>
#include <utils/environment.h>
#include <utils/fileutils.h>

View File

@@ -50,6 +50,7 @@
#include <coreplugin/coreconstants.h>
#include <utils/algorithm.h>
#include <utils/commandline.h>
#include <utils/macroexpander.h>
#include <utils/qtcassert.h>
#include <utils/stringutils.h>

View File

@@ -30,7 +30,7 @@
#include <projectexplorer/abstractprocessstep.h>
#include <utils/aspects.h>
#include <utils/fileutils.h>
#include <utils/commandline.h>
#include <memory>

View File

@@ -86,7 +86,6 @@ extend_qtc_executable(sdktool
persistentsettings.cpp persistentsettings.h
porting.h
qtcassert.cpp qtcassert.h
processargs.cpp processargs.h
savefile.cpp savefile.h
stringutils.cpp stringutils.h
)

View File

@@ -38,7 +38,7 @@ SOURCES += \
$$UTILS/namevalueitem.cpp \
$$UTILS/persistentsettings.cpp \
$$UTILS/qtcassert.cpp \
$$UTILS/processargs.cpp \
$$UTILS/commandline.cpp \
$$UTILS/savefile.cpp \
$$UTILS/stringutils.cpp
@@ -71,7 +71,7 @@ HEADERS += \
$$UTILS/namevalueitem.h \
$$UTILS/persistentsettings.h \
$$UTILS/qtcassert.h \
$$UTILS/processargs.h \
$$UTILS/commandline.h \
$$UTILS/savefile.h \
$$UTILS/porting.h

View File

@@ -68,6 +68,7 @@ QtcTool {
name: "Utils"
prefix: libsDir + "/utils/"
files: [
"commandline.cpp", "commandline.h",
"environment.cpp", "environment.h",
"fileutils.cpp", "fileutils.h",
"hostosinfo.cpp", "hostosinfo.h",
@@ -75,7 +76,6 @@ QtcTool {
"namevalueitem.cpp", "namevalueitem.h",
"persistentsettings.cpp", "persistentsettings.h",
"porting.h",
"processargs.cpp", "processargs.h",
"qtcassert.cpp", "qtcassert.h",
"savefile.cpp", "savefile.h",
"stringutils.cpp"