From ff19ebcc2d9c9668af24fe8add9f70c160776367 Mon Sep 17 00:00:00 2001 From: Jake Petroules Date: Tue, 13 Dec 2016 21:52:11 -0800 Subject: Make QProcessEnvironment available on Apple Platforms and VxWorks MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Reviewed-by: Timur Pocheptsov Reviewed-by: Morten Johan Sørvig --- src/corelib/configure.json | 2 +- src/corelib/io/io.pri | 2 ++ src/corelib/io/qprocess_darwin.mm | 58 +++++++++++++++++++++++++++++++++++++++ src/corelib/io/qprocess_unix.cpp | 15 ++-------- 4 files changed, 63 insertions(+), 14 deletions(-) create mode 100644 src/corelib/io/qprocess_darwin.mm (limited to 'src') diff --git a/src/corelib/configure.json b/src/corelib/configure.json index 6faedb6051..d4a511781c 100644 --- a/src/corelib/configure.json +++ b/src/corelib/configure.json @@ -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": { diff --git a/src/corelib/io/io.pri b/src/corelib/io/io.pri index 0414ae966a..78416cdf5e 100644 --- a/src/corelib/io/io.pri +++ b/src/corelib/io/io.pri @@ -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 diff --git a/src/corelib/io/qprocess_darwin.mm b/src/corelib/io/qprocess_darwin.mm new file mode 100644 index 0000000000..dd7a8275b9 --- /dev/null +++ b/src/corelib/io/qprocess_darwin.mm @@ -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 + +#import + +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 diff --git a/src/corelib/io/qprocess_unix.cpp b/src/corelib/io/qprocess_unix.cpp index 39ec370d9c..deca5c50ff 100644 --- a/src/corelib/io/qprocess_unix.cpp +++ b/src/corelib/io/qprocess_unix.cpp @@ -119,21 +119,11 @@ QT_END_NAMESPACE QT_BEGIN_NAMESPACE -#if QT_CONFIG(processenvironment) - -QT_BEGIN_INCLUDE_NAMESPACE -#if defined(Q_OS_MACOS) -# include -# 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) -- cgit v1.2.3