Make QProcessEnvironment available on Apple Platforms and VxWorks

All Apple Platforms have public API to get the environment; there is no
reason to exclude it from the UIKit subset. It can be useful for
debugging in Xcode, in particular. Furthermore, VxWorks appears to have
support for the Unix environment API, so don't exclude it either.

[ChangeLog][QtCore] QProcessEnvironment is now available on iOS, tvOS,
watchOS, and VxWorks

Change-Id: Ife3745f9b0a588de521a714b4273c5c08eeef286
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
This commit is contained in:
Jake Petroules 2016-12-13 21:52:11 -08:00
parent 510e699d15
commit ff19ebcc2d
4 changed files with 63 additions and 14 deletions

View File

@ -449,7 +449,7 @@
"label": "QProcessEnvironment",
"purpose": "Provides a higher-level abstraction of environment variables.",
"section": "File I/O",
"condition": "!config.winrt && !config.uikit && !config.integrity && !config.vxworks",
"condition": "!config.winrt && !config.integrity",
"output": [ "publicFeature" ]
},
"temporaryfile": {

View File

@ -146,6 +146,8 @@ win32 {
}
mac {
SOURCES += io/qstorageinfo_mac.cpp
qtConfig(processenvironment): \
OBJECTIVE_SOURCES += io/qprocess_darwin.mm
OBJECTIVE_SOURCES += io/qstandardpaths_mac.mm
osx {
OBJECTIVE_SOURCES += io/qfilesystemwatcher_fsevents.mm

View File

@ -0,0 +1,58 @@
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the QtCore module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** 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 Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 3 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL3 included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 3 requirements
** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 2.0 or (at your option) the GNU General
** Public license version 3 or any later version approved by the KDE Free
** Qt Foundation. The licenses are as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
** 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-2.0.html and
** https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include <private/qprocess_p.h>
#import <Foundation/Foundation.h>
QT_BEGIN_NAMESPACE
QProcessEnvironment QProcessEnvironment::systemEnvironment()
{
__block QProcessEnvironment env;
[[[NSProcessInfo processInfo] environment]
enumerateKeysAndObjectsUsingBlock:^(NSString *name, NSString *value, BOOL *__unused stop) {
env.d->hash.insert(
QProcessEnvironmentPrivate::Key(QString::fromNSString(name).toLocal8Bit()),
QProcessEnvironmentPrivate::Value(QString::fromNSString(value).toLocal8Bit()));
}];
return env;
}
QT_END_NAMESPACE

View File

@ -119,21 +119,11 @@ QT_END_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
#if QT_CONFIG(processenvironment) && !defined(Q_OS_DARWIN)
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, '=');
@ -145,11 +135,10 @@ QProcessEnvironment QProcessEnvironment::systemEnvironment()
env.d->hash.insert(QProcessEnvironmentPrivate::Key(name),
QProcessEnvironmentPrivate::Value(value));
}
#endif
return env;
}
#endif // QT_CONFIG(processenvironment)
#endif // QT_CONFIG(processenvironment) && !defined(Q_OS_DARWIN)
#if QT_CONFIG(process)