Introduce a configure option for QProcessEnvironment
This decouples QProcess and QProcessEnvironment, since the latter may actually be available on platforms where the former is not. Change-Id: I3dc799ffdf94486b64143ed01a369897fff44a96 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
parent
66c2b87547
commit
b9f56751cb
@ -445,6 +445,13 @@
|
|||||||
"condition": "!config.winrt && !config.uikit && !config.integrity && !config.vxworks",
|
"condition": "!config.winrt && !config.uikit && !config.integrity && !config.vxworks",
|
||||||
"output": [ "publicFeature", "feature" ]
|
"output": [ "publicFeature", "feature" ]
|
||||||
},
|
},
|
||||||
|
"processenvironment": {
|
||||||
|
"label": "QProcessEnvironment",
|
||||||
|
"purpose": "Provides a higher-level abstraction of environment variables.",
|
||||||
|
"section": "File I/O",
|
||||||
|
"condition": "!config.winrt && !config.uikit && !config.integrity && !config.vxworks",
|
||||||
|
"output": [ "publicFeature" ]
|
||||||
|
},
|
||||||
"temporaryfile": {
|
"temporaryfile": {
|
||||||
"label": "QTemporaryFile",
|
"label": "QTemporaryFile",
|
||||||
"purpose": "Provides an I/O device that operates on temporary files.",
|
"purpose": "Provides an I/O device that operates on temporary files.",
|
||||||
|
@ -99,7 +99,7 @@ QT_END_NAMESPACE
|
|||||||
#include <private/qcore_unix_p.h>
|
#include <private/qcore_unix_p.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef QT_NO_PROCESS
|
#if QT_CONFIG(processenvironment)
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
|
|
||||||
@ -430,6 +430,10 @@ void QProcessEnvironment::insert(const QProcessEnvironment &e)
|
|||||||
d->insert(*e.d);
|
d->insert(*e.d);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif // QT_CONFIG(processenvironment)
|
||||||
|
|
||||||
|
#if QT_CONFIG(process)
|
||||||
|
|
||||||
void QProcessPrivate::Channel::clear()
|
void QProcessPrivate::Channel::clear()
|
||||||
{
|
{
|
||||||
switch (type) {
|
switch (type) {
|
||||||
|
@ -48,8 +48,9 @@
|
|||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
|
|
||||||
|
class QProcessPrivate;
|
||||||
|
|
||||||
#ifndef QT_NO_PROCESS
|
#if QT_CONFIG(processenvironment)
|
||||||
|
|
||||||
#if !defined(Q_OS_WIN) || defined(Q_CLANG_QDOC)
|
#if !defined(Q_OS_WIN) || defined(Q_CLANG_QDOC)
|
||||||
typedef qint64 Q_PID;
|
typedef qint64 Q_PID;
|
||||||
@ -61,7 +62,6 @@ typedef struct _STARTUPINFOW Q_STARTUPINFO;
|
|||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
class QProcessPrivate;
|
|
||||||
class QProcessEnvironmentPrivate;
|
class QProcessEnvironmentPrivate;
|
||||||
|
|
||||||
class Q_CORE_EXPORT QProcessEnvironment
|
class Q_CORE_EXPORT QProcessEnvironment
|
||||||
@ -105,6 +105,10 @@ private:
|
|||||||
|
|
||||||
Q_DECLARE_SHARED(QProcessEnvironment)
|
Q_DECLARE_SHARED(QProcessEnvironment)
|
||||||
|
|
||||||
|
#endif // QT_CONFIG(processenvironment)
|
||||||
|
|
||||||
|
#if QT_CONFIG(process)
|
||||||
|
|
||||||
class Q_CORE_EXPORT QProcess : public QIODevice
|
class Q_CORE_EXPORT QProcess : public QIODevice
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
@ -70,8 +70,6 @@ typedef int Q_PIPE;
|
|||||||
#define INVALID_Q_PIPE -1
|
#define INVALID_Q_PIPE -1
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef QT_NO_PROCESS
|
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
|
|
||||||
class QSocketNotifier;
|
class QSocketNotifier;
|
||||||
@ -80,6 +78,8 @@ class QWindowsPipeWriter;
|
|||||||
class QWinEventNotifier;
|
class QWinEventNotifier;
|
||||||
class QTimer;
|
class QTimer;
|
||||||
|
|
||||||
|
#if QT_CONFIG(processenvironment)
|
||||||
|
|
||||||
#ifdef Q_OS_WIN
|
#ifdef Q_OS_WIN
|
||||||
class QProcEnvKey : public QString
|
class QProcEnvKey : public QString
|
||||||
{
|
{
|
||||||
@ -233,6 +233,10 @@ template<> Q_INLINE_TEMPLATE void QSharedDataPointer<QProcessEnvironmentPrivate>
|
|||||||
d = x;
|
d = x;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif // QT_CONFIG(processenvironment)
|
||||||
|
|
||||||
|
#if QT_CONFIG(process)
|
||||||
|
|
||||||
class QProcessPrivate : public QIODevicePrivate
|
class QProcessPrivate : public QIODevicePrivate
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -386,8 +390,8 @@ public:
|
|||||||
void setErrorAndEmit(QProcess::ProcessError error, const QString &description = QString());
|
void setErrorAndEmit(QProcess::ProcessError error, const QString &description = QString());
|
||||||
};
|
};
|
||||||
|
|
||||||
QT_END_NAMESPACE
|
|
||||||
|
|
||||||
#endif // QT_NO_PROCESS
|
#endif // QT_NO_PROCESS
|
||||||
|
|
||||||
|
QT_END_NAMESPACE
|
||||||
|
|
||||||
#endif // QPROCESS_P_H
|
#endif // QPROCESS_P_H
|
||||||
|
@ -41,9 +41,7 @@
|
|||||||
//#define QPROCESS_DEBUG
|
//#define QPROCESS_DEBUG
|
||||||
#include "qdebug.h"
|
#include "qdebug.h"
|
||||||
|
|
||||||
#ifndef QT_NO_PROCESS
|
#if QT_CONFIG(process) && defined(QPROCESS_DEBUG)
|
||||||
|
|
||||||
#if defined QPROCESS_DEBUG
|
|
||||||
#include "private/qtools_p.h"
|
#include "private/qtools_p.h"
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
|
||||||
@ -114,10 +112,47 @@ QT_END_NAMESPACE
|
|||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
#if QT_CONFIG(process)
|
||||||
#include <forkfd.h>
|
#include <forkfd.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
|
|
||||||
|
#if QT_CONFIG(processenvironment)
|
||||||
|
|
||||||
|
QT_BEGIN_INCLUDE_NAMESPACE
|
||||||
|
#if defined(Q_OS_MACOS)
|
||||||
|
# include <crt_externs.h>
|
||||||
|
# define environ (*_NSGetEnviron())
|
||||||
|
#else
|
||||||
|
extern char **environ;
|
||||||
|
#endif
|
||||||
|
QT_END_INCLUDE_NAMESPACE
|
||||||
|
|
||||||
|
QProcessEnvironment QProcessEnvironment::systemEnvironment()
|
||||||
|
{
|
||||||
|
QProcessEnvironment env;
|
||||||
|
#if !defined(QT_PLATFORM_UIKIT)
|
||||||
|
const char *entry;
|
||||||
|
for (int count = 0; (entry = environ[count]); ++count) {
|
||||||
|
const char *equal = strchr(entry, '=');
|
||||||
|
if (!equal)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
QByteArray name(entry, equal - entry);
|
||||||
|
QByteArray value(equal + 1);
|
||||||
|
env.d->hash.insert(QProcessEnvironmentPrivate::Key(name),
|
||||||
|
QProcessEnvironmentPrivate::Value(value));
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
return env;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // QT_CONFIG(processenvironment)
|
||||||
|
|
||||||
|
#if QT_CONFIG(process)
|
||||||
|
|
||||||
// POSIX requires PIPE_BUF to be 512 or larger
|
// POSIX requires PIPE_BUF to be 512 or larger
|
||||||
// so we will use 512
|
// so we will use 512
|
||||||
static const int errorBufferMax = 512;
|
static const int errorBufferMax = 512;
|
||||||
@ -310,34 +345,6 @@ bool QProcessPrivate::openChannel(Channel &channel)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QT_BEGIN_INCLUDE_NAMESPACE
|
|
||||||
#if defined(Q_OS_MACX)
|
|
||||||
# include <crt_externs.h>
|
|
||||||
# define environ (*_NSGetEnviron())
|
|
||||||
#else
|
|
||||||
extern char **environ;
|
|
||||||
#endif
|
|
||||||
QT_END_INCLUDE_NAMESPACE
|
|
||||||
|
|
||||||
QProcessEnvironment QProcessEnvironment::systemEnvironment()
|
|
||||||
{
|
|
||||||
QProcessEnvironment env;
|
|
||||||
#if !defined(QT_PLATFORM_UIKIT)
|
|
||||||
const char *entry;
|
|
||||||
for (int count = 0; (entry = environ[count]); ++count) {
|
|
||||||
const char *equal = strchr(entry, '=');
|
|
||||||
if (!equal)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
QByteArray name(entry, equal - entry);
|
|
||||||
QByteArray value(equal + 1);
|
|
||||||
env.d->hash.insert(QProcessEnvironmentPrivate::Key(name),
|
|
||||||
QProcessEnvironmentPrivate::Value(value));
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
return env;
|
|
||||||
}
|
|
||||||
|
|
||||||
static char **_q_dupEnvironment(const QProcessEnvironmentPrivate::Hash &environment, int *envc)
|
static char **_q_dupEnvironment(const QProcessEnvironmentPrivate::Hash &environment, int *envc)
|
||||||
{
|
{
|
||||||
*envc = 0;
|
*envc = 0;
|
||||||
@ -1044,6 +1051,6 @@ bool QProcessPrivate::startDetached(const QString &program, const QStringList &a
|
|||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
QT_END_NAMESPACE
|
|
||||||
|
|
||||||
#endif // QT_NO_PROCESS
|
#endif // QT_NO_PROCESS
|
||||||
|
|
||||||
|
QT_END_NAMESPACE
|
||||||
|
@ -38,6 +38,7 @@
|
|||||||
**
|
**
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
|
//#define QPROCESS_DEBUG
|
||||||
#include "qprocess.h"
|
#include "qprocess.h"
|
||||||
#include "qprocess_p.h"
|
#include "qprocess_p.h"
|
||||||
#include "qwindowspipereader_p.h"
|
#include "qwindowspipereader_p.h"
|
||||||
@ -59,11 +60,35 @@
|
|||||||
#define PIPE_REJECT_REMOTE_CLIENTS 0x08
|
#define PIPE_REJECT_REMOTE_CLIENTS 0x08
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef QT_NO_PROCESS
|
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
|
|
||||||
//#define QPROCESS_DEBUG
|
#if QT_CONFIG(processenvironment)
|
||||||
|
|
||||||
|
QProcessEnvironment QProcessEnvironment::systemEnvironment()
|
||||||
|
{
|
||||||
|
QProcessEnvironment env;
|
||||||
|
// Calls to setenv() affect the low-level environment as well.
|
||||||
|
// This is not the case the other way round.
|
||||||
|
if (wchar_t *envStrings = GetEnvironmentStringsW()) {
|
||||||
|
for (const wchar_t *entry = envStrings; *entry; ) {
|
||||||
|
const int entryLen = int(wcslen(entry));
|
||||||
|
// + 1 to permit magic cmd variable names starting with =
|
||||||
|
if (const wchar_t *equal = wcschr(entry + 1, L'=')) {
|
||||||
|
int nameLen = equal - entry;
|
||||||
|
QString name = QString::fromWCharArray(entry, nameLen);
|
||||||
|
QString value = QString::fromWCharArray(equal + 1, entryLen - nameLen - 1);
|
||||||
|
env.d->hash.insert(QProcessEnvironmentPrivate::Key(name), value);
|
||||||
|
}
|
||||||
|
entry += entryLen + 1;
|
||||||
|
}
|
||||||
|
FreeEnvironmentStringsW(envStrings);
|
||||||
|
}
|
||||||
|
return env;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // QT_CONFIG(processenvironment)
|
||||||
|
|
||||||
|
#if QT_CONFIG(process)
|
||||||
|
|
||||||
static void qt_create_pipe(Q_PIPE *pipe, bool isInputPipe)
|
static void qt_create_pipe(Q_PIPE *pipe, bool isInputPipe)
|
||||||
{
|
{
|
||||||
@ -369,28 +394,6 @@ static QString qt_create_commandline(const QString &program, const QStringList &
|
|||||||
return args;
|
return args;
|
||||||
}
|
}
|
||||||
|
|
||||||
QProcessEnvironment QProcessEnvironment::systemEnvironment()
|
|
||||||
{
|
|
||||||
QProcessEnvironment env;
|
|
||||||
// Calls to setenv() affect the low-level environment as well.
|
|
||||||
// This is not the case the other way round.
|
|
||||||
if (wchar_t *envStrings = GetEnvironmentStringsW()) {
|
|
||||||
for (const wchar_t *entry = envStrings; *entry; ) {
|
|
||||||
const int entryLen = int(wcslen(entry));
|
|
||||||
// + 1 to permit magic cmd variable names starting with =
|
|
||||||
if (const wchar_t *equal = wcschr(entry + 1, L'=')) {
|
|
||||||
int nameLen = equal - entry;
|
|
||||||
QString name = QString::fromWCharArray(entry, nameLen);
|
|
||||||
QString value = QString::fromWCharArray(equal + 1, entryLen - nameLen - 1);
|
|
||||||
env.d->hash.insert(QProcessEnvironmentPrivate::Key(name), value);
|
|
||||||
}
|
|
||||||
entry += entryLen + 1;
|
|
||||||
}
|
|
||||||
FreeEnvironmentStringsW(envStrings);
|
|
||||||
}
|
|
||||||
return env;
|
|
||||||
}
|
|
||||||
|
|
||||||
static QByteArray qt_create_environment(const QProcessEnvironmentPrivate::Hash &environment)
|
static QByteArray qt_create_environment(const QProcessEnvironmentPrivate::Hash &environment)
|
||||||
{
|
{
|
||||||
QByteArray envlist;
|
QByteArray envlist;
|
||||||
@ -891,6 +894,6 @@ bool QProcessPrivate::startDetached(const QString &program, const QStringList &a
|
|||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
QT_END_NAMESPACE
|
|
||||||
|
|
||||||
#endif // QT_NO_PROCESS
|
#endif // QT_NO_PROCESS
|
||||||
|
|
||||||
|
QT_END_NAMESPACE
|
||||||
|
@ -59,9 +59,11 @@ SUBDIRS=\
|
|||||||
win32:!qtConfig(private_tests): SUBDIRS -= \
|
win32:!qtConfig(private_tests): SUBDIRS -= \
|
||||||
qfilesystementry
|
qfilesystementry
|
||||||
|
|
||||||
|
!qtConfig(processenvironment): SUBDIRS -= \
|
||||||
|
qprocessenvironment
|
||||||
|
|
||||||
winrt: SUBDIRS -= \
|
winrt: SUBDIRS -= \
|
||||||
qprocess \
|
qprocess \
|
||||||
qprocess-noapplication \
|
qprocess-noapplication \
|
||||||
qprocessenvironment \
|
|
||||||
qstorageinfo \
|
qstorageinfo \
|
||||||
qwinoverlappedionotifier
|
qwinoverlappedionotifier
|
||||||
|
Loading…
Reference in New Issue
Block a user