1 /**************************************************************************
3 ** This file is part of Qt Creator
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
7 ** Contact: Nokia Corporation (info@qt.nokia.com)
10 ** GNU Lesser General Public License Usage
12 ** This file may be used under the terms of the GNU Lesser General Public
13 ** License version 2.1 as published by the Free Software Foundation and
14 ** appearing in the file LICENSE.LGPL included in the packaging of this file.
15 ** Please review the following information to ensure the GNU Lesser General
16 ** Public License version 2.1 requirements will be met:
17 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
19 ** In addition, as a special exception, Nokia gives you certain additional
20 ** rights. These rights are described in the Nokia Qt LGPL Exception
21 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
25 ** Alternatively, this file may be used in accordance with the terms and
26 ** conditions contained in a signed written agreement between you and Nokia.
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
31 **************************************************************************/
33 #ifndef PROFILEEVALUATOR_H
34 #define PROFILEEVALUATOR_H
38 #include <QtCore/QHash>
39 #include <QtCore/QStringList>
40 #ifdef PROEVALUATOR_THREAD_SAFE
41 # include <QtCore/QMutex>
42 # include <QtCore/QWaitCondition>
50 class ProFileEvaluatorHandler
53 // qmake/project configuration error
54 virtual void configError(const QString &msg) = 0;
55 // Some error during evaluation
56 virtual void evalError(const QString &filename, int lineNo, const QString &msg) = 0;
57 // error() and message() from .pro file
58 virtual void fileMessage(const QString &msg) = 0;
60 enum EvalFileType { EvalProjectFile, EvalIncludeFile, EvalConfigFile, EvalFeatureFile, EvalAuxFile };
61 virtual void aboutToEval(ProFile *parent, ProFile *proFile, EvalFileType type) = 0;
62 virtual void doneWithEval(ProFile *parent) = 0;
66 class ProFileEvaluator
73 FunctionDef(ProFile *pro, int offset) : m_pro(pro), m_offset(offset) { m_pro->ref(); }
74 FunctionDef(const FunctionDef &o) : m_pro(o.m_pro), m_offset(o.m_offset) { m_pro->ref(); }
75 ~FunctionDef() { m_pro->deref(); }
76 FunctionDef &operator=(const FunctionDef &o)
82 m_offset = o.m_offset;
86 ProFile *pro() const { return m_pro; }
87 const ushort *tokPtr() const { return m_pro->tokPtr() + m_offset; }
94 QHash<ProString, FunctionDef> testFunctions;
95 QHash<ProString, FunctionDef> replaceFunctions;
106 // Call this from a concurrency-free context
107 static void initialize();
109 ProFileEvaluator(ProFileOption *option, ProFileParser *parser, ProFileEvaluatorHandler *handler);
112 ProFileEvaluator::TemplateType templateType() const;
113 void setCumulative(bool on); // Default is true!
114 void setOutputDir(const QString &dir); // Default is empty
120 LoadAll = LoadPreFiles|LoadPostFiles
122 Q_DECLARE_FLAGS(LoadFlags, LoadFlag)
123 bool accept(ProFile *pro, LoadFlags flags = LoadAll);
125 bool contains(const QString &variableName) const;
126 QString value(const QString &variableName) const;
127 QStringList values(const QString &variableName) const;
128 QStringList values(const QString &variableName, const ProFile *pro) const;
129 QStringList absolutePathValues(const QString &variable, const QString &baseDirectory) const;
130 QStringList absoluteFileValues(
131 const QString &variable, const QString &baseDirectory, const QStringList &searchDirs,
132 const ProFile *pro) const;
133 QString propertyValue(const QString &val) const;
138 friend struct ProFileOption;
141 Q_DECLARE_OPERATORS_FOR_FLAGS(ProFileEvaluator::LoadFlags)
143 // This struct is from qmake, but we are not using everything.
149 //simply global convenience
150 //QString libtool_ext;
151 //QString pkgcfg_ext;
156 //QStringList cpp_ext;
158 //QString cpp_moc_ext;
163 //QString cpp_moc_mod;
170 QHash<QString, QString> properties;
176 // -nocache, -cache, -spec, QMAKESPEC
177 // -set persistent value
178 void setCommandLineArguments(const QStringList &args);
181 friend class ProFileEvaluator;
182 friend class ProFileEvaluator::Private;
184 void applyHostMode();
186 QHash<ProString, ProStringList> base_valuemap; // Cached results of qmake.conf, .qmake.cache & default_pre.prf
187 ProFileEvaluator::FunctionDefs base_functions;
188 QStringList feature_roots;
189 QString qmakespec_name;
190 QString precmds, postcmds;
191 enum HOST_MODE { HOST_UNKNOWN_MODE, HOST_UNIX_MODE, HOST_WIN_MODE, HOST_MACX_MODE };
193 enum TARG_MODE { TARG_UNKNOWN_MODE, TARG_UNIX_MODE, TARG_WIN_MODE, TARG_MACX_MODE,
195 TARG_MODE target_mode;
196 #ifdef PROEVALUATOR_THREAD_SAFE
199 bool base_inProgress;
203 Q_DECLARE_TYPEINFO(ProFileEvaluator::FunctionDef, Q_MOVABLE_TYPE);
207 #endif // PROFILEEVALUATOR_H