1 | /**************************************************************************** |
2 | ** |
3 | ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). |
4 | ** Contact: http://www.qt-project.org/legal |
5 | ** |
6 | ** This file is part of the Qt Linguist of the Qt Toolkit. |
7 | ** |
8 | ** $QT_BEGIN_LICENSE:LGPL$ |
9 | ** Commercial License Usage |
10 | ** Licensees holding valid commercial Qt licenses may use this file in |
11 | ** accordance with the commercial license agreement provided with the |
12 | ** Software or, alternatively, in accordance with the terms contained in |
13 | ** a written agreement between you and Digia. For licensing terms and |
14 | ** conditions see http://qt.digia.com/licensing. For further information |
15 | ** use the contact form at http://qt.digia.com/contact-us. |
16 | ** |
17 | ** GNU Lesser General Public License Usage |
18 | ** Alternatively, this file may be used under the terms of the GNU Lesser |
19 | ** General Public License version 2.1 as published by the Free Software |
20 | ** Foundation and appearing in the file LICENSE.LGPL included in the |
21 | ** packaging of this file. Please review the following information to |
22 | ** ensure the GNU Lesser General Public License version 2.1 requirements |
23 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
24 | ** |
25 | ** In addition, as a special exception, Digia gives you certain additional |
26 | ** rights. These rights are described in the Digia Qt LGPL Exception |
27 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
28 | ** |
29 | ** GNU General Public License Usage |
30 | ** Alternatively, this file may be used under the terms of the GNU |
31 | ** General Public License version 3.0 as published by the Free Software |
32 | ** Foundation and appearing in the file LICENSE.GPL included in the |
33 | ** packaging of this file. Please review the following information to |
34 | ** ensure the GNU General Public License version 3.0 requirements will be |
35 | ** met: http://www.gnu.org/copyleft/gpl.html. |
36 | ** |
37 | ** |
38 | ** $QT_END_LICENSE$ |
39 | ** |
40 | ****************************************************************************/ |
41 | |
42 | #ifndef PROFILEEVALUATOR_H |
43 | #define PROFILEEVALUATOR_H |
44 | |
45 | #include "proparser_global.h" |
46 | #include "proitems.h" |
47 | |
48 | #include <QtCore/QHash> |
49 | #include <QtCore/QStringList> |
50 | #ifndef QT_BOOTSTRAPPED |
51 | # include <QtCore/QProcess> |
52 | #endif |
53 | #ifdef PROEVALUATOR_THREAD_SAFE |
54 | # include <QtCore/QMutex> |
55 | # include <QtCore/QWaitCondition> |
56 | #endif |
57 | |
58 | QT_BEGIN_NAMESPACE |
59 | |
60 | struct ProFileOption; |
61 | class ProFileParser; |
62 | |
63 | class PROPARSER_EXPORT ProFileEvaluatorHandler |
64 | { |
65 | public: |
66 | // qmake/project configuration error |
67 | virtual void configError(const QString &msg) = 0; |
68 | // Some error during evaluation |
69 | virtual void evalError(const QString &filename, int lineNo, const QString &msg) = 0; |
70 | // error() and message() from .pro file |
71 | virtual void fileMessage(const QString &msg) = 0; |
72 | |
73 | enum EvalFileType { EvalProjectFile, EvalIncludeFile, EvalConfigFile, EvalFeatureFile, EvalAuxFile }; |
74 | virtual void aboutToEval(ProFile *parent, ProFile *proFile, EvalFileType type) = 0; |
75 | virtual void doneWithEval(ProFile *parent) = 0; |
76 | }; |
77 | |
78 | |
79 | class PROPARSER_EXPORT ProFileEvaluator |
80 | { |
81 | class Private; |
82 | |
83 | public: |
84 | class FunctionDef { |
85 | public: |
86 | FunctionDef(ProFile *pro, int offset) : m_pro(pro), m_offset(offset) { m_pro->ref(); } |
87 | FunctionDef(const FunctionDef &o) : m_pro(o.m_pro), m_offset(o.m_offset) { m_pro->ref(); } |
88 | ~FunctionDef() { m_pro->deref(); } |
89 | FunctionDef &operator=(const FunctionDef &o) |
90 | { |
91 | if (this != &o) { |
92 | m_pro->deref(); |
93 | m_pro = o.m_pro; |
94 | m_pro->ref(); |
95 | m_offset = o.m_offset; |
96 | } |
97 | return *this; |
98 | } |
99 | ProFile *pro() const { return m_pro; } |
100 | const ushort *tokPtr() const { return m_pro->tokPtr() + m_offset; } |
101 | private: |
102 | ProFile *m_pro; |
103 | int m_offset; |
104 | }; |
105 | |
106 | struct FunctionDefs { |
107 | QHash<ProString, FunctionDef> testFunctions; |
108 | QHash<ProString, FunctionDef> replaceFunctions; |
109 | }; |
110 | |
111 | enum TemplateType { |
112 | TT_Unknown = 0, |
113 | TT_Application, |
114 | TT_Library, |
115 | TT_Script, |
116 | TT_Aux, |
117 | TT_Subdirs |
118 | }; |
119 | |
120 | // Call this from a concurrency-free context |
121 | static void initialize(); |
122 | |
123 | ProFileEvaluator(ProFileOption *option, ProFileParser *parser, ProFileEvaluatorHandler *handler); |
124 | ~ProFileEvaluator(); |
125 | |
126 | ProFileEvaluator::TemplateType templateType() const; |
127 | #ifdef PROEVALUATOR_CUMULATIVE |
128 | void setCumulative(bool on); // Default is true! |
129 | #endif |
130 | void setOutputDir(const QString &dir); // Default is empty |
131 | |
132 | enum LoadFlag { |
133 | LoadProOnly = 0, |
134 | LoadPreFiles = 1, |
135 | LoadPostFiles = 2, |
136 | LoadAll = LoadPreFiles|LoadPostFiles |
137 | }; |
138 | Q_DECLARE_FLAGS(LoadFlags, LoadFlag) |
139 | bool accept(ProFile *pro, LoadFlags flags = LoadAll); |
140 | |
141 | bool contains(const QString &variableName) const; |
142 | QString value(const QString &variableName) const; |
143 | QStringList values(const QString &variableName) const; |
144 | QStringList values(const QString &variableName, const ProFile *pro) const; |
145 | QStringList absolutePathValues(const QString &variable, const QString &baseDirectory) const; |
146 | QStringList absoluteFileValues( |
147 | const QString &variable, const QString &baseDirectory, const QStringList &searchDirs, |
148 | const ProFile *pro) const; |
149 | QString propertyValue(const QString &val) const; |
150 | |
151 | private: |
152 | Private *d; |
153 | |
154 | friend struct ProFileOption; |
155 | }; |
156 | |
157 | Q_DECLARE_OPERATORS_FOR_FLAGS(ProFileEvaluator::LoadFlags) |
158 | |
159 | // This struct is from qmake, but we are not using everything. |
160 | struct PROPARSER_EXPORT ProFileOption |
161 | { |
162 | ProFileOption(); |
163 | ~ProFileOption(); |
164 | |
165 | //simply global convenience |
166 | //QString libtool_ext; |
167 | //QString pkgcfg_ext; |
168 | //QString prf_ext; |
169 | //QString prl_ext; |
170 | //QString ui_ext; |
171 | //QStringList h_ext; |
172 | //QStringList cpp_ext; |
173 | //QString h_moc_ext; |
174 | //QString cpp_moc_ext; |
175 | //QString obj_ext; |
176 | //QString lex_ext; |
177 | //QString yacc_ext; |
178 | //QString h_moc_mod; |
179 | //QString cpp_moc_mod; |
180 | //QString lex_mod; |
181 | //QString yacc_mod; |
182 | QString dir_sep; |
183 | QString dirlist_sep; |
184 | QString qmakespec; |
185 | QString cachefile; |
186 | QHash<QString, QString> properties; |
187 | #ifndef QT_BOOTSTRAPPED |
188 | QProcessEnvironment environment; |
189 | #endif |
190 | QString sysroot; |
191 | |
192 | //QString pro_ext; |
193 | //QString res_ext; |
194 | |
195 | // -nocache, -cache, -spec, QMAKESPEC |
196 | // -set persistent value |
197 | void setCommandLineArguments(const QStringList &args); |
198 | #ifdef PROEVALUATOR_INIT_PROPS |
199 | bool initProperties(const QString &qmake); |
200 | #endif |
201 | |
202 | private: |
203 | friend class ProFileEvaluator; |
204 | friend class ProFileEvaluator::Private; |
205 | |
206 | void applyHostMode(); |
207 | QString getEnv(const QString &) const; |
208 | |
209 | QHash<ProString, ProStringList> base_valuemap; // Cached results of qmake.conf, .qmake.cache & default_pre.prf |
210 | ProFileEvaluator::FunctionDefs base_functions; |
211 | QStringList feature_roots; |
212 | QString qmakespec_name; |
213 | QString precmds, postcmds; |
214 | enum HOST_MODE { HOST_UNKNOWN_MODE, HOST_UNIX_MODE, HOST_WIN_MODE, HOST_MACX_MODE }; |
215 | HOST_MODE host_mode; |
216 | enum TARG_MODE { TARG_UNKNOWN_MODE, TARG_UNIX_MODE, TARG_WIN_MODE, TARG_MACX_MODE, |
217 | TARG_SYMBIAN_MODE }; |
218 | TARG_MODE target_mode; |
219 | #ifdef PROEVALUATOR_THREAD_SAFE |
220 | QMutex mutex; |
221 | QWaitCondition cond; |
222 | bool base_inProgress; |
223 | #endif |
224 | }; |
225 | |
226 | Q_DECLARE_TYPEINFO(ProFileEvaluator::FunctionDef, Q_MOVABLE_TYPE); |
227 | |
228 | QT_END_NAMESPACE |
229 | |
230 | #endif // PROFILEEVALUATOR_H |
231 | |