2022-05-10 10:06:48 +00:00
|
|
|
// Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
2012-09-05 16:29:19 +00:00
|
|
|
|
|
|
|
#ifndef QMAKEEVALUATOR_H
|
|
|
|
#define QMAKEEVALUATOR_H
|
|
|
|
|
|
|
|
#if defined(PROEVALUATOR_FULL) && defined(PROEVALUATOR_THREAD_SAFE)
|
|
|
|
# error PROEVALUATOR_FULL is incompatible with PROEVALUATOR_THREAD_SAFE due to cache() implementation
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "qmakeparser.h"
|
2016-10-24 17:30:24 +00:00
|
|
|
#include "qmakevfs.h"
|
2012-09-05 16:29:19 +00:00
|
|
|
#include "ioutils.h"
|
|
|
|
|
|
|
|
#include <qlist.h>
|
2014-07-25 17:37:57 +00:00
|
|
|
#include <qmap.h>
|
2012-09-05 16:29:19 +00:00
|
|
|
#include <qset.h>
|
|
|
|
#include <qstack.h>
|
|
|
|
#include <qstring.h>
|
|
|
|
#include <qstringlist.h>
|
2013-06-03 17:08:10 +00:00
|
|
|
#include <qshareddata.h>
|
2017-03-02 10:29:08 +00:00
|
|
|
#if QT_CONFIG(process)
|
2012-09-05 16:29:19 +00:00
|
|
|
# include <qprocess.h>
|
2015-01-07 08:30:52 +00:00
|
|
|
#else
|
|
|
|
# include <qiodevice.h>
|
2012-09-05 16:29:19 +00:00
|
|
|
#endif
|
2013-06-03 17:08:10 +00:00
|
|
|
#ifdef PROEVALUATOR_THREAD_SAFE
|
|
|
|
# include <qmutex.h>
|
|
|
|
#endif
|
2012-09-05 16:29:19 +00:00
|
|
|
|
2019-05-02 16:51:57 +00:00
|
|
|
#include <list>
|
|
|
|
|
2012-09-05 16:29:19 +00:00
|
|
|
QT_BEGIN_NAMESPACE
|
|
|
|
|
|
|
|
class QMakeGlobals;
|
|
|
|
|
|
|
|
class QMAKE_EXPORT QMakeHandler : public QMakeParserHandler
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
enum {
|
|
|
|
SourceEvaluator = 0x10,
|
|
|
|
|
2013-09-02 14:43:49 +00:00
|
|
|
CumulativeEvalMessage = 0x1000,
|
|
|
|
|
2012-09-05 16:29:19 +00:00
|
|
|
EvalWarnLanguage = SourceEvaluator | WarningMessage | WarnLanguage,
|
|
|
|
EvalWarnDeprecated = SourceEvaluator | WarningMessage | WarnDeprecated,
|
|
|
|
|
|
|
|
EvalError = ErrorMessage | SourceEvaluator
|
|
|
|
};
|
|
|
|
|
|
|
|
// error(), warning() and message() from .pro file
|
2013-09-02 14:43:49 +00:00
|
|
|
virtual void fileMessage(int type, const QString &msg) = 0;
|
2012-09-05 16:29:19 +00:00
|
|
|
|
|
|
|
enum EvalFileType { EvalProjectFile, EvalIncludeFile, EvalConfigFile, EvalFeatureFile, EvalAuxFile };
|
|
|
|
virtual void aboutToEval(ProFile *parent, ProFile *proFile, EvalFileType type) = 0;
|
|
|
|
virtual void doneWithEval(ProFile *parent) = 0;
|
|
|
|
};
|
|
|
|
|
2013-06-03 17:08:10 +00:00
|
|
|
typedef QPair<QString, QString> QMakeFeatureKey; // key, parent
|
|
|
|
typedef QHash<QMakeFeatureKey, QString> QMakeFeatureHash;
|
|
|
|
|
|
|
|
class QMAKE_EXPORT QMakeFeatureRoots : public QSharedData
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
QMakeFeatureRoots(const QStringList &_paths) : paths(_paths) {}
|
|
|
|
const QStringList paths;
|
|
|
|
mutable QMakeFeatureHash cache;
|
|
|
|
#ifdef PROEVALUATOR_THREAD_SAFE
|
|
|
|
mutable QMutex mutex;
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
2019-05-02 16:51:57 +00:00
|
|
|
// We use a list-based stack instead of a vector-based one, so that
|
2012-09-05 16:29:19 +00:00
|
|
|
// the addresses of value maps stay constant. The qmake generators rely on that.
|
2019-05-02 16:51:57 +00:00
|
|
|
class QMAKE_EXPORT ProValueMapStack : public std::list<ProValueMap>
|
2012-09-05 16:29:19 +00:00
|
|
|
{
|
|
|
|
public:
|
2019-05-02 16:44:32 +00:00
|
|
|
inline void push(const ProValueMap &t) { push_back(t); }
|
|
|
|
inline ProValueMap pop() { auto r = std::move(back()); pop_back(); return r; }
|
|
|
|
ProValueMap &top() { return back(); }
|
|
|
|
const ProValueMap &top() const { return back(); }
|
2012-09-05 16:29:19 +00:00
|
|
|
};
|
|
|
|
|
2017-08-11 17:22:58 +00:00
|
|
|
namespace QMakeInternal { struct QMakeBuiltin; }
|
|
|
|
|
2012-09-05 16:29:19 +00:00
|
|
|
class QMAKE_EXPORT QMakeEvaluator
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
enum LoadFlag {
|
|
|
|
LoadProOnly = 0,
|
|
|
|
LoadPreFiles = 1,
|
|
|
|
LoadPostFiles = 2,
|
|
|
|
LoadAll = LoadPreFiles|LoadPostFiles,
|
2013-06-14 07:50:46 +00:00
|
|
|
LoadSilent = 0x10,
|
|
|
|
LoadHidden = 0x20
|
2012-09-05 16:29:19 +00:00
|
|
|
};
|
|
|
|
Q_DECLARE_FLAGS(LoadFlags, LoadFlag)
|
|
|
|
|
|
|
|
static void initStatics();
|
|
|
|
static void initFunctionStatics();
|
2013-05-29 18:18:51 +00:00
|
|
|
QMakeEvaluator(QMakeGlobals *option, QMakeParser *parser, QMakeVfs *vfs,
|
2012-09-05 16:29:19 +00:00
|
|
|
QMakeHandler *handler);
|
|
|
|
~QMakeEvaluator();
|
|
|
|
|
|
|
|
void setExtraVars(const ProValueMap &extraVars) { m_extraVars = extraVars; }
|
|
|
|
void setExtraConfigs(const ProStringList &extraConfigs) { m_extraConfigs = extraConfigs; }
|
|
|
|
void setOutputDir(const QString &outputDir) { m_outputDir = outputDir; }
|
|
|
|
|
|
|
|
ProStringList values(const ProKey &variableName) const;
|
|
|
|
ProStringList &valuesRef(const ProKey &variableName);
|
|
|
|
ProString first(const ProKey &variableName) const;
|
|
|
|
ProString propertyValue(const ProKey &val) const;
|
|
|
|
|
|
|
|
ProString dirSep() const { return m_dirSep; }
|
|
|
|
bool isHostBuild() const { return m_hostBuild; }
|
|
|
|
|
|
|
|
enum VisitReturn {
|
|
|
|
ReturnFalse,
|
|
|
|
ReturnTrue,
|
|
|
|
ReturnError,
|
|
|
|
ReturnBreak,
|
|
|
|
ReturnNext,
|
|
|
|
ReturnReturn
|
|
|
|
};
|
|
|
|
|
|
|
|
static ALWAYS_INLINE VisitReturn returnBool(bool b)
|
|
|
|
{ return b ? ReturnTrue : ReturnFalse; }
|
|
|
|
|
|
|
|
static ALWAYS_INLINE uint getBlockLen(const ushort *&tokPtr);
|
2016-06-29 14:56:57 +00:00
|
|
|
VisitReturn evaluateExpression(const ushort *&tokPtr, ProStringList *ret, bool joined);
|
2012-09-05 16:29:19 +00:00
|
|
|
static ALWAYS_INLINE void skipStr(const ushort *&tokPtr);
|
|
|
|
static ALWAYS_INLINE void skipHashStr(const ushort *&tokPtr);
|
|
|
|
void skipExpression(const ushort *&tokPtr);
|
|
|
|
|
|
|
|
void loadDefaults();
|
|
|
|
bool prepareProject(const QString &inDir);
|
|
|
|
bool loadSpecInternal();
|
|
|
|
bool loadSpec();
|
2014-06-16 12:31:30 +00:00
|
|
|
void initFrom(const QMakeEvaluator *other);
|
2012-09-05 16:29:19 +00:00
|
|
|
void setupProject();
|
|
|
|
void evaluateCommand(const QString &cmds, const QString &where);
|
2013-10-08 21:44:24 +00:00
|
|
|
void applyExtraConfigs();
|
2012-09-05 16:29:19 +00:00
|
|
|
VisitReturn visitProFile(ProFile *pro, QMakeHandler::EvalFileType type,
|
|
|
|
LoadFlags flags);
|
|
|
|
VisitReturn visitProBlock(ProFile *pro, const ushort *tokPtr);
|
|
|
|
VisitReturn visitProBlock(const ushort *tokPtr);
|
|
|
|
VisitReturn visitProLoop(const ProKey &variable, const ushort *exprPtr,
|
|
|
|
const ushort *tokPtr);
|
|
|
|
void visitProFunctionDef(ushort tok, const ProKey &name, const ushort *tokPtr);
|
2016-06-29 14:56:57 +00:00
|
|
|
VisitReturn visitProVariable(ushort tok, const ProStringList &curr, const ushort *&tokPtr);
|
2012-09-05 16:29:19 +00:00
|
|
|
|
|
|
|
ALWAYS_INLINE const ProKey &map(const ProString &var) { return map(var.toKey()); }
|
|
|
|
const ProKey &map(const ProKey &var);
|
|
|
|
ProValueMap *findValues(const ProKey &variableName, ProValueMap::Iterator *it);
|
|
|
|
|
|
|
|
void setTemplate();
|
|
|
|
|
2020-05-30 21:29:21 +00:00
|
|
|
ProStringList split_value_list(QStringView vals, int source = 0);
|
2016-06-29 14:56:57 +00:00
|
|
|
VisitReturn expandVariableReferences(const ushort *&tokPtr, int sizeHint, ProStringList *ret, bool joined);
|
2012-09-05 16:29:19 +00:00
|
|
|
|
|
|
|
QString currentFileName() const;
|
|
|
|
QString currentDirectory() const;
|
|
|
|
ProFile *currentProFile() const;
|
2017-08-14 16:30:29 +00:00
|
|
|
int currentFileId() const;
|
2012-09-05 16:29:19 +00:00
|
|
|
QString resolvePath(const QString &fileName) const
|
|
|
|
{ return QMakeInternal::IoUtils::resolvePath(currentDirectory(), fileName); }
|
2017-08-14 09:58:21 +00:00
|
|
|
QString filePathArg0(const ProStringList &args);
|
|
|
|
QString filePathEnvArg0(const ProStringList &args);
|
2012-09-05 16:29:19 +00:00
|
|
|
|
2012-09-19 19:56:16 +00:00
|
|
|
VisitReturn evaluateFile(const QString &fileName, QMakeHandler::EvalFileType type,
|
2012-09-05 16:29:19 +00:00
|
|
|
LoadFlags flags);
|
2012-09-19 19:56:16 +00:00
|
|
|
VisitReturn evaluateFileChecked(const QString &fileName, QMakeHandler::EvalFileType type,
|
|
|
|
LoadFlags flags);
|
|
|
|
VisitReturn evaluateFeatureFile(const QString &fileName, bool silent = false);
|
|
|
|
VisitReturn evaluateFileInto(const QString &fileName,
|
|
|
|
ProValueMap *values, // output-only
|
|
|
|
LoadFlags flags);
|
|
|
|
VisitReturn evaluateConfigFeatures();
|
2012-09-05 16:29:19 +00:00
|
|
|
void message(int type, const QString &msg) const;
|
|
|
|
void evalError(const QString &msg) const
|
|
|
|
{ message(QMakeHandler::EvalError, msg); }
|
|
|
|
void languageWarning(const QString &msg) const
|
|
|
|
{ message(QMakeHandler::EvalWarnLanguage, msg); }
|
|
|
|
void deprecationWarning(const QString &msg) const
|
|
|
|
{ message(QMakeHandler::EvalWarnDeprecated, msg); }
|
|
|
|
|
2016-06-29 14:56:57 +00:00
|
|
|
VisitReturn prepareFunctionArgs(const ushort *&tokPtr, QList<ProStringList> *ret);
|
|
|
|
VisitReturn evaluateFunction(const ProFunctionDef &func,
|
|
|
|
const QList<ProStringList> &argumentsList, ProStringList *ret);
|
2012-09-05 16:29:19 +00:00
|
|
|
VisitReturn evaluateBoolFunction(const ProFunctionDef &func,
|
|
|
|
const QList<ProStringList> &argumentsList,
|
|
|
|
const ProString &function);
|
|
|
|
|
2016-06-29 14:56:57 +00:00
|
|
|
VisitReturn evaluateExpandFunction(const ProKey &function, const ushort *&tokPtr, ProStringList *ret);
|
2012-09-05 16:29:19 +00:00
|
|
|
VisitReturn evaluateConditionalFunction(const ProKey &function, const ushort *&tokPtr);
|
|
|
|
|
2017-08-11 17:22:58 +00:00
|
|
|
VisitReturn evaluateBuiltinExpand(const QMakeInternal::QMakeBuiltin &adef,
|
|
|
|
const ProKey &function, const ProStringList &args, ProStringList &ret);
|
|
|
|
VisitReturn evaluateBuiltinConditional(const QMakeInternal::QMakeBuiltin &adef,
|
|
|
|
const ProKey &function, const ProStringList &args);
|
2012-09-05 16:29:19 +00:00
|
|
|
|
2020-05-30 21:29:21 +00:00
|
|
|
VisitReturn evaluateConditional(QStringView cond, const QString &where, int line = -1);
|
2012-09-05 16:29:19 +00:00
|
|
|
#ifdef PROEVALUATOR_FULL
|
2016-06-30 14:02:29 +00:00
|
|
|
VisitReturn checkRequirements(const ProStringList &deps);
|
2012-09-05 16:29:19 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
void updateMkspecPaths();
|
|
|
|
void updateFeaturePaths();
|
|
|
|
|
2020-05-30 21:29:21 +00:00
|
|
|
bool isActiveConfig(QStringView config, bool regex = false);
|
2012-09-05 16:29:19 +00:00
|
|
|
|
|
|
|
void populateDeps(
|
2013-02-01 19:03:02 +00:00
|
|
|
const ProStringList &deps, const ProString &prefix, const ProStringList &suffixes,
|
2014-07-25 17:37:57 +00:00
|
|
|
const ProString &priosfx,
|
|
|
|
QHash<ProKey, QSet<ProKey> > &dependencies, ProValueMap &dependees,
|
|
|
|
QMultiMap<int, ProString> &rootSet) const;
|
2012-09-05 16:29:19 +00:00
|
|
|
|
2016-05-18 14:35:01 +00:00
|
|
|
bool getMemberArgs(const ProKey &name, int srclen, const ProStringList &args,
|
|
|
|
int *start, int *end);
|
2016-05-19 13:40:55 +00:00
|
|
|
VisitReturn parseJsonInto(const QByteArray &json, const QString &into, ProValueMap *value);
|
2016-05-18 14:35:01 +00:00
|
|
|
|
2012-09-05 16:29:19 +00:00
|
|
|
VisitReturn writeFile(const QString &ctx, const QString &fn, QIODevice::OpenMode mode,
|
2016-10-24 17:30:24 +00:00
|
|
|
QMakeVfs::VfsFlags flags, const QString &contents);
|
2017-03-02 10:29:08 +00:00
|
|
|
#if QT_CONFIG(process)
|
2012-09-05 16:29:19 +00:00
|
|
|
void runProcess(QProcess *proc, const QString &command) const;
|
|
|
|
#endif
|
2016-07-15 16:09:24 +00:00
|
|
|
QByteArray getCommandOutput(const QString &args, int *exitCode) const;
|
2012-09-05 16:29:19 +00:00
|
|
|
|
2018-07-16 12:44:53 +00:00
|
|
|
private:
|
|
|
|
// Implementation detail of evaluateBuiltinConditional():
|
|
|
|
VisitReturn testFunc_cache(const ProStringList &args);
|
|
|
|
|
|
|
|
public:
|
2012-09-05 16:29:19 +00:00
|
|
|
QMakeEvaluator *m_caller;
|
|
|
|
#ifdef PROEVALUATOR_CUMULATIVE
|
|
|
|
bool m_cumulative;
|
|
|
|
int m_skipLevel;
|
|
|
|
#else
|
|
|
|
enum { m_cumulative = 0 };
|
|
|
|
enum { m_skipLevel = 0 };
|
|
|
|
#endif
|
|
|
|
|
2014-11-17 19:55:33 +00:00
|
|
|
static QString quoteValue(const ProString &val);
|
|
|
|
|
2012-09-05 16:29:19 +00:00
|
|
|
#ifdef PROEVALUATOR_DEBUG
|
|
|
|
void debugMsgInternal(int level, const char *fmt, ...) const;
|
|
|
|
void traceMsgInternal(const char *fmt, ...) const;
|
|
|
|
static QString formatValue(const ProString &val, bool forceQuote = false);
|
|
|
|
static QString formatValueList(const ProStringList &vals, bool commas = false);
|
|
|
|
static QString formatValueListList(const QList<ProStringList> &vals);
|
|
|
|
|
|
|
|
const int m_debugLevel;
|
|
|
|
#else
|
|
|
|
ALWAYS_INLINE void debugMsgInternal(int, const char *, ...) const {}
|
|
|
|
ALWAYS_INLINE void traceMsgInternal(const char *, ...) const {}
|
|
|
|
|
|
|
|
enum { m_debugLevel = 0 };
|
|
|
|
#endif
|
|
|
|
|
|
|
|
struct Location {
|
2018-08-02 22:22:24 +00:00
|
|
|
Location() : pro(nullptr), line(0) {}
|
2012-09-05 16:29:19 +00:00
|
|
|
Location(ProFile *_pro, ushort _line) : pro(_pro), line(_line) {}
|
2018-08-02 22:22:24 +00:00
|
|
|
void clear() { pro = nullptr; line = 0; }
|
2012-09-05 16:29:19 +00:00
|
|
|
ProFile *pro;
|
|
|
|
ushort line;
|
|
|
|
};
|
|
|
|
|
|
|
|
Location m_current; // Currently evaluated location
|
|
|
|
QStack<Location> m_locationStack; // All execution location changes
|
|
|
|
QStack<ProFile *> m_profileStack; // Includes only
|
|
|
|
|
|
|
|
ProValueMap m_extraVars;
|
|
|
|
ProStringList m_extraConfigs;
|
|
|
|
QString m_outputDir;
|
|
|
|
|
|
|
|
int m_listCount;
|
2017-08-11 12:55:37 +00:00
|
|
|
int m_toggle;
|
2012-09-05 16:29:19 +00:00
|
|
|
bool m_valuemapInited;
|
|
|
|
bool m_hostBuild;
|
|
|
|
QString m_qmakespec;
|
|
|
|
QString m_qmakespecName;
|
|
|
|
QString m_superfile;
|
|
|
|
QString m_conffile;
|
|
|
|
QString m_cachefile;
|
support a cache that is really just a cache
unlike .qmake.cache & co., the presence of this file has no magic
effects on where mkspecs, modules and other things are searched.
as the obvious name "cache" is of course already taken, we call it
"stash".
the file is searched up to the super cache (if present), otherwise up to
the normal cache/conf (if present), otherwise up to the root.
if it's not found, it is created next to the super cache (if present),
otherwise next to the cache/conf (if present), otherwise in the current
output directory.
note that the cache really should be created and populated by the
top-level project if there are subprojects: otherwise, if there is an
"anchor" (super/cache/conf), subprojects would race for updating the
cache and make a mess. without an "anchor", each subproject would just
create its own cache, kind of defeating its purpose. this is no
different from the existing "cache", but it's worth mentioning that
removing the "anchoring" function does not remove the "nesting order"
constraint.
Task-number: QTBUG-31340
Change-Id: I786d40cef40d14582a0dd4a9407863001bec4c98
Reviewed-by: Joerg Bornemann <joerg.bornemann@digia.com>
2013-11-07 19:40:00 +00:00
|
|
|
QString m_stashfile;
|
2012-09-05 16:29:19 +00:00
|
|
|
QString m_sourceRoot;
|
|
|
|
QString m_buildRoot;
|
|
|
|
QStringList m_qmakepath;
|
|
|
|
QStringList m_qmakefeatures;
|
|
|
|
QStringList m_mkspecPaths;
|
2013-06-03 17:08:10 +00:00
|
|
|
QExplicitlySharedDataPointer<QMakeFeatureRoots> m_featureRoots;
|
2012-09-05 16:29:19 +00:00
|
|
|
ProString m_dirSep;
|
|
|
|
ProFunctionDefs m_functionDefs;
|
|
|
|
ProStringList m_returnValue;
|
|
|
|
ProValueMapStack m_valuemapStack; // VariableName must be us-ascii, the content however can be non-us-ascii.
|
|
|
|
QString m_tmp1, m_tmp2, m_tmp3, m_tmp[2]; // Temporaries for efficient toQString
|
|
|
|
|
|
|
|
QMakeGlobals *m_option;
|
|
|
|
QMakeParser *m_parser;
|
|
|
|
QMakeHandler *m_handler;
|
2013-05-29 18:18:51 +00:00
|
|
|
QMakeVfs *m_vfs;
|
2012-09-05 16:29:19 +00:00
|
|
|
};
|
2015-07-07 11:01:36 +00:00
|
|
|
Q_DECLARE_TYPEINFO(QMakeEvaluator::Location, Q_PRIMITIVE_TYPE);
|
2012-09-05 16:29:19 +00:00
|
|
|
|
|
|
|
Q_DECLARE_OPERATORS_FOR_FLAGS(QMakeEvaluator::LoadFlags)
|
|
|
|
|
|
|
|
QT_END_NAMESPACE
|
|
|
|
|
|
|
|
#endif // QMAKEEVALUATOR_H
|