| 1 |
// Copyright (C) 2016 The Qt Company Ltd. |
| 2 |
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 |
| 3 |
|
| 4 |
#ifndef QMAKEGLOBALS_H |
| 5 |
#define QMAKEGLOBALS_H |
| 6 |
|
| 7 |
#include "qmake_global.h" |
| 8 |
#include "proitems.h" |
| 9 |
|
| 10 |
#ifdef QT_BUILD_QMAKE |
| 11 |
# include <property.h> |
| 12 |
#endif |
| 13 |
|
| 14 |
#include <qhash.h> |
| 15 |
#include <qstringlist.h> |
| 16 |
#if QT_CONFIG(process) |
| 17 |
# include <qprocess.h> |
| 18 |
#endif |
| 19 |
#ifdef PROEVALUATOR_THREAD_SAFE |
| 20 |
# include <qmutex.h> |
| 21 |
# include <qwaitcondition.h> |
| 22 |
#endif |
| 23 |
|
| 24 |
QT_BEGIN_NAMESPACE |
| 25 |
|
| 26 |
class QMakeEvaluator; |
| 27 |
|
| 28 |
enum QMakeEvalPhase { QMakeEvalEarly, QMakeEvalBefore, QMakeEvalAfter, QMakeEvalLate }; |
| 29 |
|
| 30 |
class QMakeBaseKey |
| 31 |
{ |
| 32 |
public: |
| 33 |
QMakeBaseKey(const QString &_root, const QString &_stash, bool _hostBuild); |
| 34 |
|
| 35 |
QString root; |
| 36 |
QString stash; |
| 37 |
bool hostBuild; |
| 38 |
}; |
| 39 |
|
| 40 |
size_t qHash(const QMakeBaseKey &key); |
| 41 |
bool operator==(const QMakeBaseKey &one, const QMakeBaseKey &two); |
| 42 |
|
| 43 |
class QMakeBaseEnv |
| 44 |
{ |
| 45 |
public: |
| 46 |
QMakeBaseEnv(); |
| 47 |
~QMakeBaseEnv(); |
| 48 |
|
| 49 |
#ifdef PROEVALUATOR_THREAD_SAFE |
| 50 |
QMutex mutex; |
| 51 |
QWaitCondition cond; |
| 52 |
bool inProgress; |
| 53 |
// The coupling of this flag to thread safety exists because for other |
| 54 |
// use cases failure is immediately fatal anyway. |
| 55 |
bool isOk; |
| 56 |
#endif |
| 57 |
QMakeEvaluator *evaluator; |
| 58 |
}; |
| 59 |
|
| 60 |
class QMAKE_EXPORT QMakeCmdLineParserState |
| 61 |
{ |
| 62 |
public: |
| 63 |
QMakeCmdLineParserState(const QString &_pwd) : pwd(_pwd), phase(QMakeEvalBefore) {} |
| 64 |
QString pwd; |
| 65 |
QStringList cmds[4], configs[4]; |
| 66 |
QStringList extraargs; |
| 67 |
QMakeEvalPhase phase; |
| 68 |
|
| 69 |
void flush() { phase = QMakeEvalBefore; } |
| 70 |
}; |
| 71 |
|
| 72 |
class QMAKE_EXPORT QMakeGlobals |
| 73 |
{ |
| 74 |
public: |
| 75 |
QMakeGlobals(); |
| 76 |
~QMakeGlobals(); |
| 77 |
|
| 78 |
bool do_cache; |
| 79 |
QString dir_sep; |
| 80 |
QString dirlist_sep; |
| 81 |
QString cachefile; |
| 82 |
#ifdef PROEVALUATOR_SETENV |
| 83 |
QProcessEnvironment environment; |
| 84 |
#endif |
| 85 |
QString qmake_abslocation; |
| 86 |
QStringList qmake_args, qmake_extra_args; |
| 87 |
|
| 88 |
QString qtconf; |
| 89 |
QString qmakespec, xqmakespec; |
| 90 |
QString user_template, user_template_prefix; |
| 91 |
QString extra_cmds[4]; |
| 92 |
|
| 93 |
#ifdef PROEVALUATOR_DEBUG |
| 94 |
int debugLevel; |
| 95 |
#endif |
| 96 |
|
| 97 |
enum ArgumentReturn { ArgumentUnknown, ArgumentMalformed, ArgumentsOk }; |
| 98 |
ArgumentReturn addCommandLineArguments(QMakeCmdLineParserState &state, |
| 99 |
QStringList &args, int *pos); |
| 100 |
void commitCommandLineArguments(QMakeCmdLineParserState &state); |
| 101 |
void setCommandLineArguments(const QString &pwd, const QStringList &args); |
| 102 |
void useEnvironment(); |
| 103 |
void setDirectories(const QString &input_dir, const QString &output_dir); |
| 104 |
#ifdef QT_BUILD_QMAKE |
| 105 |
void setQMakeProperty(QMakeProperty *prop) { property = prop; } |
| 106 |
void reloadProperties() { property->reload(); } |
| 107 |
ProString propertyValue(const ProKey &name) const { return property->value(name); } |
| 108 |
#else |
| 109 |
static void parseProperties(const QByteArray &data, QHash<ProKey, ProString> &props); |
| 110 |
# ifdef PROEVALUATOR_INIT_PROPS |
| 111 |
bool initProperties(); |
| 112 |
# else |
| 113 |
void setProperties(const QHash<ProKey, ProString> &props) { properties = props; } |
| 114 |
# endif |
| 115 |
ProString propertyValue(const ProKey &name) const { return properties.value(name); } |
| 116 |
#endif |
| 117 |
|
| 118 |
QString expandEnvVars(const QString &str) const; |
| 119 |
QString shadowedPath(const QString &fileName) const; |
| 120 |
QStringList splitPathList(const QString &value) const; |
| 121 |
|
| 122 |
private: |
| 123 |
QString getEnv(const QString &) const; |
| 124 |
QStringList getPathListEnv(const QString &var) const; |
| 125 |
|
| 126 |
QString cleanSpec(QMakeCmdLineParserState &state, const QString &spec); |
| 127 |
|
| 128 |
QString source_root, build_root; |
| 129 |
|
| 130 |
#ifdef QT_BUILD_QMAKE |
| 131 |
QMakeProperty *property; |
| 132 |
#else |
| 133 |
QHash<ProKey, ProString> properties; |
| 134 |
#endif |
| 135 |
|
| 136 |
#ifdef PROEVALUATOR_THREAD_SAFE |
| 137 |
QMutex mutex; |
| 138 |
#endif |
| 139 |
QHash<QMakeBaseKey, QMakeBaseEnv *> baseEnvs; |
| 140 |
|
| 141 |
friend class QMakeEvaluator; |
| 142 |
}; |
| 143 |
|
| 144 |
QT_END_NAMESPACE |
| 145 |
|
| 146 |
#endif // QMAKEGLOBALS_H |