2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2016-01-15 14:58:39 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** 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
|
2016-01-15 14:58:39 +01:00
|
|
|
** 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.
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2016-01-15 14:58:39 +01:00
|
|
|
** 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.
|
2010-12-17 16:01:08 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2008-12-02 16:19:05 +01:00
|
|
|
|
2016-03-18 07:55:01 +01:00
|
|
|
#pragma once
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2014-07-15 23:32:11 +03:00
|
|
|
#include "fileutils.h"
|
2013-08-15 16:54:51 +02:00
|
|
|
#include "hostosinfo.h"
|
2010-09-23 10:35:23 +02:00
|
|
|
#include "utils_global.h"
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QMap>
|
|
|
|
|
#include <QStringList>
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2017-04-19 14:39:16 +02:00
|
|
|
#include <functional>
|
|
|
|
|
|
2017-06-23 16:54:45 +02:00
|
|
|
QT_FORWARD_DECLARE_CLASS(QDebug)
|
2013-03-18 14:47:33 +01:00
|
|
|
QT_FORWARD_DECLARE_CLASS(QProcessEnvironment)
|
|
|
|
|
|
2010-09-23 10:35:23 +02:00
|
|
|
namespace Utils {
|
2017-06-23 16:54:45 +02:00
|
|
|
class Environment;
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2010-09-23 10:35:23 +02:00
|
|
|
class QTCREATOR_UTILS_EXPORT EnvironmentItem
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2010-09-23 10:35:23 +02:00
|
|
|
public:
|
2017-06-23 16:54:45 +02:00
|
|
|
enum Operation { Set, Unset, Prepend, Append };
|
|
|
|
|
|
|
|
|
|
EnvironmentItem(const QString &n, const QString &v, Operation op = Set)
|
|
|
|
|
: name(n), value(v), operation(op)
|
2008-12-02 12:01:29 +01:00
|
|
|
{}
|
|
|
|
|
|
2017-06-23 16:54:45 +02:00
|
|
|
void apply(Environment *e) const { apply(e, operation); }
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
QString name;
|
|
|
|
|
QString value;
|
2017-06-23 16:54:45 +02:00
|
|
|
Operation operation;
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2010-10-30 21:13:16 +02:00
|
|
|
bool operator==(const EnvironmentItem &other) const
|
2009-05-27 13:37:21 +02:00
|
|
|
{
|
2017-06-23 16:54:45 +02:00
|
|
|
return operation == other.operation && name == other.name && value == other.value;
|
2009-05-27 13:37:21 +02:00
|
|
|
}
|
|
|
|
|
|
2011-12-06 16:45:07 +01:00
|
|
|
static void sort(QList<EnvironmentItem> *list);
|
2011-05-24 12:04:24 +02:00
|
|
|
static QList<EnvironmentItem> fromStringList(const QStringList &list);
|
|
|
|
|
static QStringList toStringList(const QList<EnvironmentItem> &list);
|
2017-06-23 16:54:45 +02:00
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
void apply(Environment *e, Operation op) const;
|
2008-12-02 12:01:29 +01:00
|
|
|
};
|
|
|
|
|
|
2017-06-23 16:54:45 +02:00
|
|
|
QTCREATOR_UTILS_EXPORT QDebug operator<<(QDebug debug, const EnvironmentItem &i);
|
|
|
|
|
|
2011-05-24 12:04:24 +02:00
|
|
|
class QTCREATOR_UTILS_EXPORT Environment
|
|
|
|
|
{
|
2008-12-02 12:01:29 +01:00
|
|
|
public:
|
|
|
|
|
typedef QMap<QString, QString>::const_iterator const_iterator;
|
|
|
|
|
|
2013-08-15 16:54:51 +02:00
|
|
|
explicit Environment(OsType osType = HostOsInfo::hostOs()) : m_osType(osType) {}
|
|
|
|
|
explicit Environment(const QStringList &env, OsType osType = HostOsInfo::hostOs());
|
2008-12-02 12:01:29 +01:00
|
|
|
static Environment systemEnvironment();
|
2016-04-07 13:06:01 +02:00
|
|
|
static void setupEnglishOutput(Environment *environment);
|
|
|
|
|
static void setupEnglishOutput(QProcessEnvironment *environment);
|
|
|
|
|
static void setupEnglishOutput(QStringList *environment);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2009-01-13 17:25:09 +01:00
|
|
|
QStringList toStringList() const;
|
2013-01-15 13:45:46 +01:00
|
|
|
QProcessEnvironment toProcessEnvironment() const;
|
2008-12-02 12:01:29 +01:00
|
|
|
QString value(const QString &key) const;
|
|
|
|
|
void set(const QString &key, const QString &value);
|
|
|
|
|
void unset(const QString &key);
|
2011-05-24 12:04:24 +02:00
|
|
|
void modify(const QList<EnvironmentItem> &list);
|
2011-02-15 15:32:20 +01:00
|
|
|
/// Return the Environment changes necessary to modify this into the other environment.
|
2017-06-23 16:54:45 +02:00
|
|
|
QList<EnvironmentItem> diff(const Environment &other, bool checkAppendPrepend = false) const;
|
2013-06-11 18:09:51 +02:00
|
|
|
bool hasKey(const QString &key) const;
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2012-08-31 16:47:53 +02:00
|
|
|
QString userName() const;
|
|
|
|
|
|
2009-09-29 11:39:55 +02:00
|
|
|
void appendOrSet(const QString &key, const QString &value, const QString &sep = QString());
|
|
|
|
|
void prependOrSet(const QString &key, const QString &value, const QString &sep = QString());
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
void appendOrSetPath(const QString &value);
|
|
|
|
|
void prependOrSetPath(const QString &value);
|
|
|
|
|
|
2011-04-29 13:25:25 +02:00
|
|
|
void prependOrSetLibrarySearchPath(const QString &value);
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
void clear();
|
|
|
|
|
int size() const;
|
|
|
|
|
|
|
|
|
|
QString key(Environment::const_iterator it) const;
|
|
|
|
|
QString value(Environment::const_iterator it) const;
|
|
|
|
|
|
|
|
|
|
Environment::const_iterator constBegin() const;
|
|
|
|
|
Environment::const_iterator constEnd() const;
|
2010-10-18 21:14:45 +02:00
|
|
|
Environment::const_iterator constFind(const QString &name) const;
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2017-04-19 14:39:16 +02:00
|
|
|
using PathFilter = std::function<bool(const QString &)>;
|
2014-07-15 23:32:11 +03:00
|
|
|
FileName searchInPath(const QString &executable,
|
2016-10-04 11:29:30 +02:00
|
|
|
const QStringList &additionalDirs = QStringList(),
|
2017-04-19 14:39:16 +02:00
|
|
|
const PathFilter &func = PathFilter()) const;
|
2016-10-04 11:29:30 +02:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
QStringList path() const;
|
2015-07-15 14:21:45 +02:00
|
|
|
QStringList appendExeExtensions(const QString &executable) const;
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2017-03-23 17:17:58 +01:00
|
|
|
bool isSameExecutable(const QString &exe1, const QString &exe2) const;
|
|
|
|
|
|
2011-05-24 12:04:24 +02:00
|
|
|
QString expandVariables(const QString &input) const;
|
|
|
|
|
QStringList expandVariables(const QStringList &input) const;
|
2010-09-22 15:10:20 +02:00
|
|
|
|
2010-01-11 10:25:15 +01:00
|
|
|
bool operator!=(const Environment &other) const;
|
|
|
|
|
bool operator==(const Environment &other) const;
|
2011-05-24 12:04:24 +02:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
private:
|
2017-04-19 14:47:48 +02:00
|
|
|
FileName searchInDirectory(const QStringList &execs, QString directory,
|
|
|
|
|
QSet<QString> &alreadyChecked) const;
|
2008-12-02 12:01:29 +01:00
|
|
|
QMap<QString, QString> m_values;
|
2013-08-15 16:54:51 +02:00
|
|
|
OsType m_osType;
|
2008-12-02 12:01:29 +01:00
|
|
|
};
|
|
|
|
|
|
2010-09-23 10:35:23 +02:00
|
|
|
} // namespace Utils
|