| [2] | 1 | /**************************************************************************** | 
|---|
|  | 2 | ** | 
|---|
|  | 3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). | 
|---|
| [561] | 4 | ** All rights reserved. | 
|---|
|  | 5 | ** Contact: Nokia Corporation (qt-info@nokia.com) | 
|---|
| [2] | 6 | ** | 
|---|
|  | 7 | ** This file is part of the qmake application of the Qt Toolkit. | 
|---|
|  | 8 | ** | 
|---|
|  | 9 | ** $QT_BEGIN_LICENSE:LGPL$ | 
|---|
|  | 10 | ** Commercial Usage | 
|---|
|  | 11 | ** Licensees holding valid Qt Commercial licenses may use this file in | 
|---|
|  | 12 | ** accordance with the Qt Commercial License Agreement provided with the | 
|---|
|  | 13 | ** Software or, alternatively, in accordance with the terms contained in | 
|---|
|  | 14 | ** a written agreement between you and Nokia. | 
|---|
|  | 15 | ** | 
|---|
|  | 16 | ** GNU Lesser General Public License Usage | 
|---|
|  | 17 | ** Alternatively, this file may be used under the terms of the GNU Lesser | 
|---|
|  | 18 | ** General Public License version 2.1 as published by the Free Software | 
|---|
|  | 19 | ** Foundation and appearing in the file LICENSE.LGPL included in the | 
|---|
|  | 20 | ** packaging of this file.  Please review the following information to | 
|---|
|  | 21 | ** ensure the GNU Lesser General Public License version 2.1 requirements | 
|---|
|  | 22 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | 
|---|
|  | 23 | ** | 
|---|
| [561] | 24 | ** In addition, as a special exception, Nokia gives you certain additional | 
|---|
|  | 25 | ** rights.  These rights are described in the Nokia Qt LGPL Exception | 
|---|
|  | 26 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | 
|---|
| [2] | 27 | ** | 
|---|
|  | 28 | ** GNU General Public License Usage | 
|---|
|  | 29 | ** Alternatively, this file may be used under the terms of the GNU | 
|---|
|  | 30 | ** General Public License version 3.0 as published by the Free Software | 
|---|
|  | 31 | ** Foundation and appearing in the file LICENSE.GPL included in the | 
|---|
|  | 32 | ** packaging of this file.  Please review the following information to | 
|---|
|  | 33 | ** ensure the GNU General Public License version 3.0 requirements will be | 
|---|
|  | 34 | ** met: http://www.gnu.org/copyleft/gpl.html. | 
|---|
|  | 35 | ** | 
|---|
| [561] | 36 | ** If you have questions regarding the use of this file, please contact | 
|---|
|  | 37 | ** Nokia at qt-info@nokia.com. | 
|---|
| [2] | 38 | ** $QT_END_LICENSE$ | 
|---|
|  | 39 | ** | 
|---|
|  | 40 | ****************************************************************************/ | 
|---|
|  | 41 |  | 
|---|
|  | 42 | #include "project.h" | 
|---|
|  | 43 | #include "property.h" | 
|---|
|  | 44 | #include "option.h" | 
|---|
|  | 45 | #include "cachekeys.h" | 
|---|
|  | 46 |  | 
|---|
| [561] | 47 | #include "epocroot.h" | 
|---|
|  | 48 |  | 
|---|
| [2] | 49 | #include <qdatetime.h> | 
|---|
|  | 50 | #include <qfile.h> | 
|---|
|  | 51 | #include <qfileinfo.h> | 
|---|
|  | 52 | #include <qdir.h> | 
|---|
|  | 53 | #include <qregexp.h> | 
|---|
|  | 54 | #include <qtextstream.h> | 
|---|
|  | 55 | #include <qstack.h> | 
|---|
|  | 56 | #include <qhash.h> | 
|---|
|  | 57 | #include <qdebug.h> | 
|---|
|  | 58 | #ifdef Q_OS_UNIX | 
|---|
|  | 59 | #include <unistd.h> | 
|---|
|  | 60 | #include <sys/utsname.h> | 
|---|
|  | 61 | #elif defined(Q_OS_WIN32) | 
|---|
| [561] | 62 | #include <windows.h> | 
|---|
| [29] | 63 | #elif defined(Q_OS_OS2) | 
|---|
|  | 64 | #include <qt_os2.h> | 
|---|
| [2] | 65 | #endif | 
|---|
|  | 66 | #include <stdio.h> | 
|---|
|  | 67 | #include <stdlib.h> | 
|---|
|  | 68 |  | 
|---|
|  | 69 | #ifdef Q_OS_WIN32 | 
|---|
|  | 70 | #define QT_POPEN _popen | 
|---|
|  | 71 | #define QT_PCLOSE _pclose | 
|---|
|  | 72 | #else | 
|---|
|  | 73 | #define QT_POPEN popen | 
|---|
|  | 74 | #define QT_PCLOSE pclose | 
|---|
|  | 75 | #endif | 
|---|
|  | 76 |  | 
|---|
|  | 77 | QT_BEGIN_NAMESPACE | 
|---|
|  | 78 |  | 
|---|
|  | 79 | //expand fucntions | 
|---|
|  | 80 | enum ExpandFunc { E_MEMBER=1, E_FIRST, E_LAST, E_CAT, E_FROMFILE, E_EVAL, E_LIST, | 
|---|
|  | 81 | E_SPRINTF, E_JOIN, E_SPLIT, E_BASENAME, E_DIRNAME, E_SECTION, | 
|---|
|  | 82 | E_FIND, E_SYSTEM, E_UNIQUE, E_QUOTE, E_ESCAPE_EXPAND, | 
|---|
| [561] | 83 | E_UPPER, E_LOWER, E_FILES, E_PROMPT, E_RE_ESCAPE, E_REPLACE, | 
|---|
|  | 84 | E_SIZE }; | 
|---|
| [2] | 85 | QMap<QString, ExpandFunc> qmake_expandFunctions() | 
|---|
|  | 86 | { | 
|---|
|  | 87 | static QMap<QString, ExpandFunc> *qmake_expand_functions = 0; | 
|---|
|  | 88 | if(!qmake_expand_functions) { | 
|---|
|  | 89 | qmake_expand_functions = new QMap<QString, ExpandFunc>; | 
|---|
|  | 90 | qmakeAddCacheClear(qmakeDeleteCacheClear_QMapStringInt, (void**)&qmake_expand_functions); | 
|---|
|  | 91 | qmake_expand_functions->insert("member", E_MEMBER); | 
|---|
|  | 92 | qmake_expand_functions->insert("first", E_FIRST); | 
|---|
|  | 93 | qmake_expand_functions->insert("last", E_LAST); | 
|---|
|  | 94 | qmake_expand_functions->insert("cat", E_CAT); | 
|---|
|  | 95 | qmake_expand_functions->insert("fromfile", E_FROMFILE); | 
|---|
|  | 96 | qmake_expand_functions->insert("eval", E_EVAL); | 
|---|
|  | 97 | qmake_expand_functions->insert("list", E_LIST); | 
|---|
|  | 98 | qmake_expand_functions->insert("sprintf", E_SPRINTF); | 
|---|
|  | 99 | qmake_expand_functions->insert("join", E_JOIN); | 
|---|
|  | 100 | qmake_expand_functions->insert("split", E_SPLIT); | 
|---|
|  | 101 | qmake_expand_functions->insert("basename", E_BASENAME); | 
|---|
|  | 102 | qmake_expand_functions->insert("dirname", E_DIRNAME); | 
|---|
|  | 103 | qmake_expand_functions->insert("section", E_SECTION); | 
|---|
|  | 104 | qmake_expand_functions->insert("find", E_FIND); | 
|---|
|  | 105 | qmake_expand_functions->insert("system", E_SYSTEM); | 
|---|
|  | 106 | qmake_expand_functions->insert("unique", E_UNIQUE); | 
|---|
|  | 107 | qmake_expand_functions->insert("quote", E_QUOTE); | 
|---|
|  | 108 | qmake_expand_functions->insert("escape_expand", E_ESCAPE_EXPAND); | 
|---|
|  | 109 | qmake_expand_functions->insert("upper", E_UPPER); | 
|---|
|  | 110 | qmake_expand_functions->insert("lower", E_LOWER); | 
|---|
|  | 111 | qmake_expand_functions->insert("re_escape", E_RE_ESCAPE); | 
|---|
|  | 112 | qmake_expand_functions->insert("files", E_FILES); | 
|---|
|  | 113 | qmake_expand_functions->insert("prompt", E_PROMPT); | 
|---|
|  | 114 | qmake_expand_functions->insert("replace", E_REPLACE); | 
|---|
| [561] | 115 | qmake_expand_functions->insert("size", E_SIZE); | 
|---|
| [2] | 116 | } | 
|---|
|  | 117 | return *qmake_expand_functions; | 
|---|
|  | 118 | } | 
|---|
|  | 119 | //replace functions | 
|---|
|  | 120 | enum TestFunc { T_REQUIRES=1, T_GREATERTHAN, T_LESSTHAN, T_EQUALS, | 
|---|
|  | 121 | T_EXISTS, T_EXPORT, T_CLEAR, T_UNSET, T_EVAL, T_CONFIG, T_SYSTEM, | 
|---|
|  | 122 | T_RETURN, T_BREAK, T_NEXT, T_DEFINED, T_CONTAINS, T_INFILE, | 
|---|
|  | 123 | T_COUNT, T_ISEMPTY, T_INCLUDE, T_LOAD, T_DEBUG, T_ERROR, | 
|---|
|  | 124 | T_MESSAGE, T_WARNING, T_IF }; | 
|---|
|  | 125 | QMap<QString, TestFunc> qmake_testFunctions() | 
|---|
|  | 126 | { | 
|---|
|  | 127 | static QMap<QString, TestFunc> *qmake_test_functions = 0; | 
|---|
|  | 128 | if(!qmake_test_functions) { | 
|---|
|  | 129 | qmake_test_functions = new QMap<QString, TestFunc>; | 
|---|
|  | 130 | qmake_test_functions->insert("requires", T_REQUIRES); | 
|---|
|  | 131 | qmake_test_functions->insert("greaterThan", T_GREATERTHAN); | 
|---|
|  | 132 | qmake_test_functions->insert("lessThan", T_LESSTHAN); | 
|---|
|  | 133 | qmake_test_functions->insert("equals", T_EQUALS); | 
|---|
|  | 134 | qmake_test_functions->insert("isEqual", T_EQUALS); | 
|---|
|  | 135 | qmake_test_functions->insert("exists", T_EXISTS); | 
|---|
|  | 136 | qmake_test_functions->insert("export", T_EXPORT); | 
|---|
|  | 137 | qmake_test_functions->insert("clear", T_CLEAR); | 
|---|
|  | 138 | qmake_test_functions->insert("unset", T_UNSET); | 
|---|
|  | 139 | qmake_test_functions->insert("eval", T_EVAL); | 
|---|
|  | 140 | qmake_test_functions->insert("CONFIG", T_CONFIG); | 
|---|
|  | 141 | qmake_test_functions->insert("if", T_IF); | 
|---|
|  | 142 | qmake_test_functions->insert("isActiveConfig", T_CONFIG); | 
|---|
|  | 143 | qmake_test_functions->insert("system", T_SYSTEM); | 
|---|
|  | 144 | qmake_test_functions->insert("return", T_RETURN); | 
|---|
|  | 145 | qmake_test_functions->insert("break", T_BREAK); | 
|---|
|  | 146 | qmake_test_functions->insert("next", T_NEXT); | 
|---|
|  | 147 | qmake_test_functions->insert("defined", T_DEFINED); | 
|---|
|  | 148 | qmake_test_functions->insert("contains", T_CONTAINS); | 
|---|
|  | 149 | qmake_test_functions->insert("infile", T_INFILE); | 
|---|
|  | 150 | qmake_test_functions->insert("count", T_COUNT); | 
|---|
|  | 151 | qmake_test_functions->insert("isEmpty", T_ISEMPTY); | 
|---|
|  | 152 | qmake_test_functions->insert("include", T_INCLUDE); | 
|---|
|  | 153 | qmake_test_functions->insert("load", T_LOAD); | 
|---|
|  | 154 | qmake_test_functions->insert("debug", T_DEBUG); | 
|---|
|  | 155 | qmake_test_functions->insert("error", T_ERROR); | 
|---|
|  | 156 | qmake_test_functions->insert("message", T_MESSAGE); | 
|---|
|  | 157 | qmake_test_functions->insert("warning", T_WARNING); | 
|---|
|  | 158 | } | 
|---|
|  | 159 | return *qmake_test_functions; | 
|---|
|  | 160 | } | 
|---|
|  | 161 |  | 
|---|
|  | 162 | struct parser_info { | 
|---|
|  | 163 | QString file; | 
|---|
|  | 164 | int line_no; | 
|---|
|  | 165 | bool from_file; | 
|---|
|  | 166 | } parser; | 
|---|
|  | 167 |  | 
|---|
|  | 168 | static QString remove_quotes(const QString &arg) | 
|---|
|  | 169 | { | 
|---|
|  | 170 | const ushort SINGLEQUOTE = '\''; | 
|---|
|  | 171 | const ushort DOUBLEQUOTE = '"'; | 
|---|
|  | 172 |  | 
|---|
|  | 173 | const QChar *arg_data = arg.data(); | 
|---|
|  | 174 | const ushort first = arg_data->unicode(); | 
|---|
|  | 175 | const int arg_len = arg.length(); | 
|---|
|  | 176 | if(first == SINGLEQUOTE || first == DOUBLEQUOTE) { | 
|---|
|  | 177 | const ushort last = (arg_data+arg_len-1)->unicode(); | 
|---|
|  | 178 | if(last == first) | 
|---|
|  | 179 | return arg.mid(1, arg_len-2); | 
|---|
|  | 180 | } | 
|---|
|  | 181 | return arg; | 
|---|
|  | 182 | } | 
|---|
|  | 183 |  | 
|---|
|  | 184 | static QString varMap(const QString &x) | 
|---|
|  | 185 | { | 
|---|
|  | 186 | QString ret(x); | 
|---|
|  | 187 | if(ret.startsWith("TMAKE")) //tmake no more! | 
|---|
|  | 188 | ret = "QMAKE" + ret.mid(5); | 
|---|
|  | 189 | else if(ret == "INTERFACES") | 
|---|
|  | 190 | ret = "FORMS"; | 
|---|
|  | 191 | else if(ret == "QMAKE_POST_BUILD") | 
|---|
|  | 192 | ret = "QMAKE_POST_LINK"; | 
|---|
|  | 193 | else if(ret == "TARGETDEPS") | 
|---|
|  | 194 | ret = "POST_TARGETDEPS"; | 
|---|
|  | 195 | else if(ret == "LIBPATH") | 
|---|
|  | 196 | ret = "QMAKE_LIBDIR"; | 
|---|
|  | 197 | else if(ret == "QMAKE_EXT_MOC") | 
|---|
|  | 198 | ret = "QMAKE_EXT_CPP_MOC"; | 
|---|
|  | 199 | else if(ret == "QMAKE_MOD_MOC") | 
|---|
|  | 200 | ret = "QMAKE_H_MOD_MOC"; | 
|---|
|  | 201 | else if(ret == "QMAKE_LFLAGS_SHAPP") | 
|---|
|  | 202 | ret = "QMAKE_LFLAGS_APP"; | 
|---|
|  | 203 | else if(ret == "PRECOMPH") | 
|---|
|  | 204 | ret = "PRECOMPILED_HEADER"; | 
|---|
|  | 205 | else if(ret == "PRECOMPCPP") | 
|---|
|  | 206 | ret = "PRECOMPILED_SOURCE"; | 
|---|
|  | 207 | else if(ret == "INCPATH") | 
|---|
|  | 208 | ret = "INCLUDEPATH"; | 
|---|
|  | 209 | else if(ret == "QMAKE_EXTRA_WIN_COMPILERS" || ret == "QMAKE_EXTRA_UNIX_COMPILERS") | 
|---|
|  | 210 | ret = "QMAKE_EXTRA_COMPILERS"; | 
|---|
|  | 211 | else if(ret == "QMAKE_EXTRA_WIN_TARGETS" || ret == "QMAKE_EXTRA_UNIX_TARGETS") | 
|---|
|  | 212 | ret = "QMAKE_EXTRA_TARGETS"; | 
|---|
|  | 213 | else if(ret == "QMAKE_EXTRA_UNIX_INCLUDES") | 
|---|
|  | 214 | ret = "QMAKE_EXTRA_INCLUDES"; | 
|---|
|  | 215 | else if(ret == "QMAKE_EXTRA_UNIX_VARIABLES") | 
|---|
|  | 216 | ret = "QMAKE_EXTRA_VARIABLES"; | 
|---|
|  | 217 | else if(ret == "QMAKE_RPATH") | 
|---|
|  | 218 | ret = "QMAKE_LFLAGS_RPATH"; | 
|---|
|  | 219 | else if(ret == "QMAKE_FRAMEWORKDIR") | 
|---|
|  | 220 | ret = "QMAKE_FRAMEWORKPATH"; | 
|---|
|  | 221 | else if(ret == "QMAKE_FRAMEWORKDIR_FLAGS") | 
|---|
|  | 222 | ret = "QMAKE_FRAMEWORKPATH_FLAGS"; | 
|---|
|  | 223 | return ret; | 
|---|
|  | 224 | } | 
|---|
|  | 225 |  | 
|---|
|  | 226 | static QStringList split_arg_list(QString params) | 
|---|
|  | 227 | { | 
|---|
|  | 228 | int quote = 0; | 
|---|
|  | 229 | QStringList args; | 
|---|
|  | 230 |  | 
|---|
|  | 231 | const ushort LPAREN = '('; | 
|---|
|  | 232 | const ushort RPAREN = ')'; | 
|---|
|  | 233 | const ushort SINGLEQUOTE = '\''; | 
|---|
|  | 234 | const ushort DOUBLEQUOTE = '"'; | 
|---|
|  | 235 | const ushort COMMA = ','; | 
|---|
|  | 236 | const ushort SPACE = ' '; | 
|---|
|  | 237 | //const ushort TAB = '\t'; | 
|---|
|  | 238 |  | 
|---|
|  | 239 | ushort unicode; | 
|---|
|  | 240 | const QChar *params_data = params.data(); | 
|---|
|  | 241 | const int params_len = params.length(); | 
|---|
|  | 242 | int last = 0; | 
|---|
|  | 243 | while(last < params_len && (params_data[last].unicode() == SPACE | 
|---|
|  | 244 | /*|| params_data[last].unicode() == TAB*/)) | 
|---|
|  | 245 | ++last; | 
|---|
|  | 246 | for(int x = last, parens = 0; x <= params_len; x++) { | 
|---|
|  | 247 | unicode = params_data[x].unicode(); | 
|---|
|  | 248 | if(x == params_len) { | 
|---|
|  | 249 | while(x && params_data[x-1].unicode() == SPACE) | 
|---|
|  | 250 | --x; | 
|---|
|  | 251 | QString mid(params_data+last, x-last); | 
|---|
|  | 252 | if(quote) { | 
|---|
|  | 253 | if(mid[0] == quote && mid[(int)mid.length()-1] == quote) | 
|---|
|  | 254 | mid = mid.mid(1, mid.length()-2); | 
|---|
|  | 255 | quote = 0; | 
|---|
|  | 256 | } | 
|---|
|  | 257 | args << mid; | 
|---|
|  | 258 | break; | 
|---|
|  | 259 | } | 
|---|
|  | 260 | if(unicode == LPAREN) { | 
|---|
|  | 261 | --parens; | 
|---|
|  | 262 | } else if(unicode == RPAREN) { | 
|---|
|  | 263 | ++parens; | 
|---|
|  | 264 | } else if(quote && unicode == quote) { | 
|---|
|  | 265 | quote = 0; | 
|---|
|  | 266 | } else if(!quote && (unicode == SINGLEQUOTE || unicode == DOUBLEQUOTE)) { | 
|---|
|  | 267 | quote = unicode; | 
|---|
|  | 268 | } | 
|---|
|  | 269 | if(!parens && !quote && unicode == COMMA) { | 
|---|
|  | 270 | QString mid = params.mid(last, x - last).trimmed(); | 
|---|
|  | 271 | args << mid; | 
|---|
|  | 272 | last = x+1; | 
|---|
|  | 273 | while(last < params_len && (params_data[last].unicode() == SPACE | 
|---|
|  | 274 | /*|| params_data[last].unicode() == TAB*/)) | 
|---|
|  | 275 | ++last; | 
|---|
|  | 276 | } | 
|---|
|  | 277 | } | 
|---|
|  | 278 | return args; | 
|---|
|  | 279 | } | 
|---|
|  | 280 |  | 
|---|
|  | 281 | static QStringList split_value_list(const QString &vals, bool do_semicolon=false) | 
|---|
|  | 282 | { | 
|---|
|  | 283 | QString build; | 
|---|
|  | 284 | QStringList ret; | 
|---|
|  | 285 | QStack<char> quote; | 
|---|
|  | 286 |  | 
|---|
|  | 287 | const ushort LPAREN = '('; | 
|---|
|  | 288 | const ushort RPAREN = ')'; | 
|---|
|  | 289 | const ushort SINGLEQUOTE = '\''; | 
|---|
|  | 290 | const ushort DOUBLEQUOTE = '"'; | 
|---|
|  | 291 | const ushort BACKSLASH = '\\'; | 
|---|
|  | 292 | const ushort SEMICOLON = ';'; | 
|---|
|  | 293 |  | 
|---|
|  | 294 | ushort unicode; | 
|---|
|  | 295 | const QChar *vals_data = vals.data(); | 
|---|
|  | 296 | const int vals_len = vals.length(); | 
|---|
|  | 297 | for(int x = 0, parens = 0; x < vals_len; x++) { | 
|---|
|  | 298 | unicode = vals_data[x].unicode(); | 
|---|
|  | 299 | if(x != (int)vals_len-1 && unicode == BACKSLASH && | 
|---|
|  | 300 | (vals_data[x+1].unicode() == SINGLEQUOTE || vals_data[x+1].unicode() == DOUBLEQUOTE)) { | 
|---|
|  | 301 | build += vals_data[x++]; //get that 'escape' | 
|---|
|  | 302 | } else if(!quote.isEmpty() && unicode == quote.top()) { | 
|---|
|  | 303 | quote.pop(); | 
|---|
|  | 304 | } else if(unicode == SINGLEQUOTE || unicode == DOUBLEQUOTE) { | 
|---|
|  | 305 | quote.push(unicode); | 
|---|
|  | 306 | } else if(unicode == RPAREN) { | 
|---|
|  | 307 | --parens; | 
|---|
|  | 308 | } else if(unicode == LPAREN) { | 
|---|
|  | 309 | ++parens; | 
|---|
|  | 310 | } | 
|---|
|  | 311 |  | 
|---|
|  | 312 | if(!parens && quote.isEmpty() && ((do_semicolon && unicode == SEMICOLON) || | 
|---|
|  | 313 | vals_data[x] == Option::field_sep)) { | 
|---|
|  | 314 | ret << build; | 
|---|
|  | 315 | build.clear(); | 
|---|
|  | 316 | } else { | 
|---|
|  | 317 | build += vals_data[x]; | 
|---|
|  | 318 | } | 
|---|
|  | 319 | } | 
|---|
|  | 320 | if(!build.isEmpty()) | 
|---|
|  | 321 | ret << build; | 
|---|
|  | 322 | return ret; | 
|---|
|  | 323 | } | 
|---|
|  | 324 |  | 
|---|
|  | 325 | //just a parsable entity | 
|---|
|  | 326 | struct ParsableBlock | 
|---|
|  | 327 | { | 
|---|
|  | 328 | ParsableBlock() : ref_cnt(1) { } | 
|---|
|  | 329 | virtual ~ParsableBlock() { } | 
|---|
|  | 330 |  | 
|---|
|  | 331 | struct Parse { | 
|---|
|  | 332 | QString text; | 
|---|
|  | 333 | parser_info pi; | 
|---|
|  | 334 | Parse(const QString &t) : text(t){ pi = parser; } | 
|---|
|  | 335 | }; | 
|---|
|  | 336 | QList<Parse> parselist; | 
|---|
|  | 337 |  | 
|---|
|  | 338 | inline int ref() { return ++ref_cnt; } | 
|---|
|  | 339 | inline int deref() { return --ref_cnt; } | 
|---|
|  | 340 |  | 
|---|
|  | 341 | protected: | 
|---|
|  | 342 | int ref_cnt; | 
|---|
|  | 343 | virtual bool continueBlock() = 0; | 
|---|
|  | 344 | bool eval(QMakeProject *p, QMap<QString, QStringList> &place); | 
|---|
|  | 345 | }; | 
|---|
|  | 346 |  | 
|---|
|  | 347 | bool ParsableBlock::eval(QMakeProject *p, QMap<QString, QStringList> &place) | 
|---|
|  | 348 | { | 
|---|
|  | 349 | //save state | 
|---|
|  | 350 | parser_info pi = parser; | 
|---|
|  | 351 | const int block_count = p->scope_blocks.count(); | 
|---|
|  | 352 |  | 
|---|
|  | 353 | //execute | 
|---|
|  | 354 | bool ret = true; | 
|---|
|  | 355 | for(int i = 0; i < parselist.count(); i++) { | 
|---|
|  | 356 | parser = parselist.at(i).pi; | 
|---|
|  | 357 | if(!(ret = p->parse(parselist.at(i).text, place)) || !continueBlock()) | 
|---|
|  | 358 | break; | 
|---|
|  | 359 | } | 
|---|
|  | 360 |  | 
|---|
|  | 361 | //restore state | 
|---|
|  | 362 | parser = pi; | 
|---|
|  | 363 | while(p->scope_blocks.count() > block_count) | 
|---|
|  | 364 | p->scope_blocks.pop(); | 
|---|
|  | 365 | return ret; | 
|---|
|  | 366 | } | 
|---|
|  | 367 |  | 
|---|
|  | 368 | //defined functions | 
|---|
|  | 369 | struct FunctionBlock : public ParsableBlock | 
|---|
|  | 370 | { | 
|---|
|  | 371 | FunctionBlock() : calling_place(0), scope_level(1), cause_return(false) { } | 
|---|
|  | 372 |  | 
|---|
|  | 373 | QMap<QString, QStringList> vars; | 
|---|
|  | 374 | QMap<QString, QStringList> *calling_place; | 
|---|
|  | 375 | QStringList return_value; | 
|---|
|  | 376 | int scope_level; | 
|---|
|  | 377 | bool cause_return; | 
|---|
|  | 378 |  | 
|---|
|  | 379 | bool exec(const QList<QStringList> &args, | 
|---|
|  | 380 | QMakeProject *p, QMap<QString, QStringList> &place, QStringList &functionReturn); | 
|---|
|  | 381 | virtual bool continueBlock() { return !cause_return; } | 
|---|
|  | 382 | }; | 
|---|
|  | 383 |  | 
|---|
|  | 384 | bool FunctionBlock::exec(const QList<QStringList> &args, | 
|---|
|  | 385 | QMakeProject *proj, QMap<QString, QStringList> &place, | 
|---|
|  | 386 | QStringList &functionReturn) | 
|---|
|  | 387 | { | 
|---|
|  | 388 | //save state | 
|---|
|  | 389 | #if 1 | 
|---|
|  | 390 | calling_place = &place; | 
|---|
|  | 391 | #else | 
|---|
|  | 392 | calling_place = &proj->variables(); | 
|---|
|  | 393 | #endif | 
|---|
|  | 394 | return_value.clear(); | 
|---|
|  | 395 | cause_return = false; | 
|---|
|  | 396 |  | 
|---|
|  | 397 | //execute | 
|---|
|  | 398 | #if 0 | 
|---|
|  | 399 | vars = proj->variables(); // should be place so that local variables can be inherited | 
|---|
|  | 400 | #else | 
|---|
|  | 401 | vars = place; | 
|---|
|  | 402 | #endif | 
|---|
|  | 403 | vars["ARGS"].clear(); | 
|---|
|  | 404 | for(int i = 0; i < args.count(); i++) { | 
|---|
|  | 405 | vars["ARGS"] += args[i]; | 
|---|
|  | 406 | vars[QString::number(i+1)] = args[i]; | 
|---|
|  | 407 | } | 
|---|
|  | 408 | bool ret = ParsableBlock::eval(proj, vars); | 
|---|
|  | 409 | functionReturn = return_value; | 
|---|
|  | 410 |  | 
|---|
|  | 411 | //restore state | 
|---|
|  | 412 | calling_place = 0; | 
|---|
|  | 413 | return_value.clear(); | 
|---|
|  | 414 | vars.clear(); | 
|---|
|  | 415 | return ret; | 
|---|
|  | 416 | } | 
|---|
|  | 417 |  | 
|---|
|  | 418 | //loops | 
|---|
|  | 419 | struct IteratorBlock : public ParsableBlock | 
|---|
|  | 420 | { | 
|---|
|  | 421 | IteratorBlock() : scope_level(1), loop_forever(false), cause_break(false), cause_next(false) { } | 
|---|
|  | 422 |  | 
|---|
|  | 423 | int scope_level; | 
|---|
|  | 424 |  | 
|---|
|  | 425 | struct Test { | 
|---|
|  | 426 | QString func; | 
|---|
|  | 427 | QStringList args; | 
|---|
|  | 428 | bool invert; | 
|---|
|  | 429 | parser_info pi; | 
|---|
|  | 430 | Test(const QString &f, QStringList &a, bool i) : func(f), args(a), invert(i) { pi = parser; } | 
|---|
|  | 431 | }; | 
|---|
|  | 432 | QList<Test> test; | 
|---|
|  | 433 |  | 
|---|
|  | 434 | QString variable; | 
|---|
|  | 435 |  | 
|---|
|  | 436 | bool loop_forever, cause_break, cause_next; | 
|---|
|  | 437 | QStringList list; | 
|---|
|  | 438 |  | 
|---|
|  | 439 | bool exec(QMakeProject *p, QMap<QString, QStringList> &place); | 
|---|
|  | 440 | virtual bool continueBlock() { return !cause_next && !cause_break; } | 
|---|
|  | 441 | }; | 
|---|
|  | 442 | bool IteratorBlock::exec(QMakeProject *p, QMap<QString, QStringList> &place) | 
|---|
|  | 443 | { | 
|---|
|  | 444 | bool ret = true; | 
|---|
|  | 445 | QStringList::Iterator it; | 
|---|
|  | 446 | if(!loop_forever) | 
|---|
|  | 447 | it = list.begin(); | 
|---|
|  | 448 | int iterate_count = 0; | 
|---|
|  | 449 | //save state | 
|---|
|  | 450 | IteratorBlock *saved_iterator = p->iterator; | 
|---|
|  | 451 | p->iterator = this; | 
|---|
|  | 452 |  | 
|---|
|  | 453 | //do the loop | 
|---|
|  | 454 | while(loop_forever || it != list.end()) { | 
|---|
|  | 455 | cause_next = cause_break = false; | 
|---|
|  | 456 | if(!loop_forever && (*it).isEmpty()) { //ignore empty items | 
|---|
|  | 457 | ++it; | 
|---|
|  | 458 | continue; | 
|---|
|  | 459 | } | 
|---|
|  | 460 |  | 
|---|
|  | 461 | //set up the loop variable | 
|---|
|  | 462 | QStringList va; | 
|---|
|  | 463 | if(!variable.isEmpty()) { | 
|---|
|  | 464 | va = place[variable]; | 
|---|
|  | 465 | if(loop_forever) | 
|---|
|  | 466 | place[variable] = QStringList(QString::number(iterate_count)); | 
|---|
|  | 467 | else | 
|---|
|  | 468 | place[variable] = QStringList(*it); | 
|---|
|  | 469 | } | 
|---|
|  | 470 | //do the iterations | 
|---|
|  | 471 | bool succeed = true; | 
|---|
|  | 472 | for(QList<Test>::Iterator test_it = test.begin(); test_it != test.end(); ++test_it) { | 
|---|
|  | 473 | parser = (*test_it).pi; | 
|---|
|  | 474 | succeed = p->doProjectTest((*test_it).func, (*test_it).args, place); | 
|---|
|  | 475 | if((*test_it).invert) | 
|---|
|  | 476 | succeed = !succeed; | 
|---|
|  | 477 | if(!succeed) | 
|---|
|  | 478 | break; | 
|---|
|  | 479 | } | 
|---|
|  | 480 | if(succeed) | 
|---|
|  | 481 | ret = ParsableBlock::eval(p, place); | 
|---|
|  | 482 | //restore the variable in the map | 
|---|
|  | 483 | if(!variable.isEmpty()) | 
|---|
|  | 484 | place[variable] = va; | 
|---|
|  | 485 | //loop counters | 
|---|
|  | 486 | if(!loop_forever) | 
|---|
|  | 487 | ++it; | 
|---|
|  | 488 | iterate_count++; | 
|---|
|  | 489 | if(!ret || cause_break) | 
|---|
|  | 490 | break; | 
|---|
|  | 491 | } | 
|---|
|  | 492 |  | 
|---|
|  | 493 | //restore state | 
|---|
|  | 494 | p->iterator = saved_iterator; | 
|---|
|  | 495 | return ret; | 
|---|
|  | 496 | } | 
|---|
|  | 497 |  | 
|---|
|  | 498 | QMakeProject::ScopeBlock::~ScopeBlock() | 
|---|
|  | 499 | { | 
|---|
|  | 500 | #if 0 | 
|---|
|  | 501 | if(iterate) | 
|---|
|  | 502 | delete iterate; | 
|---|
|  | 503 | #endif | 
|---|
|  | 504 | } | 
|---|
|  | 505 |  | 
|---|
|  | 506 | static void qmake_error_msg(const QString &msg) | 
|---|
|  | 507 | { | 
|---|
|  | 508 | fprintf(stderr, "%s:%d: %s\n", parser.file.toLatin1().constData(), parser.line_no, | 
|---|
|  | 509 | msg.toLatin1().constData()); | 
|---|
|  | 510 | } | 
|---|
|  | 511 |  | 
|---|
| [561] | 512 | enum isForSymbian_enum { | 
|---|
|  | 513 | isForSymbian_NOT_SET = -1, | 
|---|
|  | 514 | isForSymbian_FALSE = 0, | 
|---|
|  | 515 | isForSymbian_ABLD = 1, | 
|---|
|  | 516 | isForSymbian_SBSV2 = 2, | 
|---|
|  | 517 | }; | 
|---|
|  | 518 |  | 
|---|
|  | 519 | static isForSymbian_enum isForSymbian_value = isForSymbian_NOT_SET; | 
|---|
|  | 520 |  | 
|---|
|  | 521 | // Checking for symbian build is primarily determined from the qmake spec, | 
|---|
|  | 522 | // but if that is not specified, detect if symbian is the default spec | 
|---|
|  | 523 | // by checking the MAKEFILE_GENERATOR variable value. | 
|---|
|  | 524 | static void init_symbian(const QMap<QString, QStringList>& vars) | 
|---|
|  | 525 | { | 
|---|
|  | 526 | if (isForSymbian_value != isForSymbian_NOT_SET) | 
|---|
|  | 527 | return; | 
|---|
|  | 528 |  | 
|---|
|  | 529 | QString spec = QFileInfo(Option::mkfile::qmakespec).fileName(); | 
|---|
|  | 530 | if (spec.startsWith("symbian-abld", Qt::CaseInsensitive)) { | 
|---|
|  | 531 | isForSymbian_value = isForSymbian_ABLD; | 
|---|
|  | 532 | } else if (spec.startsWith("symbian-sbsv2", Qt::CaseInsensitive)) { | 
|---|
|  | 533 | isForSymbian_value = isForSymbian_SBSV2; | 
|---|
|  | 534 | } else { | 
|---|
|  | 535 | QStringList generatorList = vars["MAKEFILE_GENERATOR"]; | 
|---|
|  | 536 |  | 
|---|
|  | 537 | if (!generatorList.isEmpty()) { | 
|---|
|  | 538 | QString generator = generatorList.first(); | 
|---|
|  | 539 | if (generator.startsWith("SYMBIAN_ABLD")) | 
|---|
|  | 540 | isForSymbian_value = isForSymbian_ABLD; | 
|---|
|  | 541 | else if (generator.startsWith("SYMBIAN_SBSV2")) | 
|---|
|  | 542 | isForSymbian_value = isForSymbian_SBSV2; | 
|---|
|  | 543 | else | 
|---|
|  | 544 | isForSymbian_value = isForSymbian_FALSE; | 
|---|
|  | 545 | } else { | 
|---|
|  | 546 | isForSymbian_value = isForSymbian_FALSE; | 
|---|
|  | 547 | } | 
|---|
|  | 548 | } | 
|---|
|  | 549 |  | 
|---|
|  | 550 | // Force recursive on Symbian, as non-recursive is not really a viable option there | 
|---|
|  | 551 | if (isForSymbian_value != isForSymbian_FALSE) | 
|---|
|  | 552 | Option::recursive = true; | 
|---|
|  | 553 | } | 
|---|
|  | 554 |  | 
|---|
|  | 555 | bool isForSymbian() | 
|---|
|  | 556 | { | 
|---|
|  | 557 | // If isForSymbian_value has not been initialized explicitly yet, | 
|---|
|  | 558 | // call initializer with dummy map to check qmake spec. | 
|---|
|  | 559 | if (isForSymbian_value == isForSymbian_NOT_SET) | 
|---|
|  | 560 | init_symbian(QMap<QString, QStringList>()); | 
|---|
|  | 561 |  | 
|---|
|  | 562 | return (isForSymbian_value != isForSymbian_FALSE); | 
|---|
|  | 563 | } | 
|---|
|  | 564 |  | 
|---|
|  | 565 | bool isForSymbianSbsv2() | 
|---|
|  | 566 | { | 
|---|
|  | 567 | // If isForSymbian_value has not been initialized explicitly yet, | 
|---|
|  | 568 | // call initializer with dummy map to check qmake spec. | 
|---|
|  | 569 | if (isForSymbian_value == isForSymbian_NOT_SET) | 
|---|
|  | 570 | init_symbian(QMap<QString, QStringList>()); | 
|---|
|  | 571 |  | 
|---|
|  | 572 | return (isForSymbian_value == isForSymbian_SBSV2); | 
|---|
|  | 573 | } | 
|---|
|  | 574 |  | 
|---|
| [2] | 575 | /* | 
|---|
|  | 576 | 1) environment variable QMAKEFEATURES (as separated by colons) | 
|---|
|  | 577 | 2) property variable QMAKEFEATURES (as separated by colons) | 
|---|
|  | 578 | 3) <project_root> (where .qmake.cache lives) + FEATURES_DIR | 
|---|
|  | 579 | 4) environment variable QMAKEPATH (as separated by colons) + /mkspecs/FEATURES_DIR | 
|---|
|  | 580 | 5) your QMAKESPEC/features dir | 
|---|
|  | 581 | 6) your data_install/mkspecs/FEATURES_DIR | 
|---|
|  | 582 | 7) your QMAKESPEC/../FEATURES_DIR dir | 
|---|
|  | 583 |  | 
|---|
|  | 584 | FEATURES_DIR is defined as: | 
|---|
|  | 585 |  | 
|---|
|  | 586 | 1) features/(unix|win32|macx)/ | 
|---|
|  | 587 | 2) features/ | 
|---|
|  | 588 | */ | 
|---|
|  | 589 | QStringList qmake_feature_paths(QMakeProperty *prop=0) | 
|---|
|  | 590 | { | 
|---|
|  | 591 | QStringList concat; | 
|---|
|  | 592 | { | 
|---|
|  | 593 | const QString base_concat = QDir::separator() + QString("features"); | 
|---|
|  | 594 | switch(Option::target_mode) { | 
|---|
|  | 595 | case Option::TARG_MACX_MODE:                     //also a unix | 
|---|
|  | 596 | concat << base_concat + QDir::separator() + "mac"; | 
|---|
|  | 597 | concat << base_concat + QDir::separator() + "macx"; | 
|---|
|  | 598 | concat << base_concat + QDir::separator() + "unix"; | 
|---|
|  | 599 | break; | 
|---|
|  | 600 | case Option::TARG_UNIX_MODE: | 
|---|
| [561] | 601 | { | 
|---|
|  | 602 | if (isForSymbian()) | 
|---|
|  | 603 | concat << base_concat + QDir::separator() + "symbian"; | 
|---|
|  | 604 | else | 
|---|
|  | 605 | concat << base_concat + QDir::separator() + "unix"; | 
|---|
|  | 606 | break; | 
|---|
|  | 607 | } | 
|---|
| [2] | 608 | case Option::TARG_WIN_MODE: | 
|---|
| [561] | 609 | { | 
|---|
|  | 610 | if (isForSymbian()) | 
|---|
|  | 611 | concat << base_concat + QDir::separator() + "symbian"; | 
|---|
|  | 612 | else | 
|---|
|  | 613 | concat << base_concat + QDir::separator() + "win32"; | 
|---|
|  | 614 | break; | 
|---|
|  | 615 | } | 
|---|
| [27] | 616 | case Option::TARG_OS2_MODE: | 
|---|
|  | 617 | concat << base_concat + QDir::separator() + "os2"; | 
|---|
|  | 618 | break; | 
|---|
| [2] | 619 | case Option::TARG_MAC9_MODE: | 
|---|
|  | 620 | concat << base_concat + QDir::separator() + "mac"; | 
|---|
|  | 621 | concat << base_concat + QDir::separator() + "mac9"; | 
|---|
|  | 622 | break; | 
|---|
|  | 623 | } | 
|---|
|  | 624 | concat << base_concat; | 
|---|
|  | 625 | } | 
|---|
|  | 626 | const QString mkspecs_concat = QDir::separator() + QString("mkspecs"); | 
|---|
|  | 627 | QStringList feature_roots; | 
|---|
|  | 628 | QByteArray mkspec_path = qgetenv("QMAKEFEATURES"); | 
|---|
|  | 629 | if(!mkspec_path.isNull()) | 
|---|
|  | 630 | feature_roots += splitPathList(QString::fromLocal8Bit(mkspec_path)); | 
|---|
|  | 631 | if(prop) | 
|---|
|  | 632 | feature_roots += splitPathList(prop->value("QMAKEFEATURES")); | 
|---|
|  | 633 | if(!Option::mkfile::cachefile.isEmpty()) { | 
|---|
|  | 634 | QString path; | 
|---|
|  | 635 | int last_slash = Option::mkfile::cachefile.lastIndexOf(Option::dir_sep); | 
|---|
|  | 636 | if(last_slash != -1) | 
|---|
|  | 637 | path = Option::fixPathToLocalOS(Option::mkfile::cachefile.left(last_slash)); | 
|---|
|  | 638 | for(QStringList::Iterator concat_it = concat.begin(); | 
|---|
|  | 639 | concat_it != concat.end(); ++concat_it) | 
|---|
|  | 640 | feature_roots << (path + (*concat_it)); | 
|---|
|  | 641 | } | 
|---|
|  | 642 | QByteArray qmakepath = qgetenv("QMAKEPATH"); | 
|---|
|  | 643 | if (!qmakepath.isNull()) { | 
|---|
|  | 644 | const QStringList lst = splitPathList(QString::fromLocal8Bit(qmakepath)); | 
|---|
|  | 645 | for(QStringList::ConstIterator it = lst.begin(); it != lst.end(); ++it) { | 
|---|
|  | 646 | for(QStringList::Iterator concat_it = concat.begin(); | 
|---|
|  | 647 | concat_it != concat.end(); ++concat_it) | 
|---|
|  | 648 | feature_roots << ((*it) + mkspecs_concat + (*concat_it)); | 
|---|
|  | 649 | } | 
|---|
|  | 650 | } | 
|---|
|  | 651 | if(!Option::mkfile::qmakespec.isEmpty()) | 
|---|
|  | 652 | feature_roots << Option::mkfile::qmakespec + QDir::separator() + "features"; | 
|---|
|  | 653 | if(!Option::mkfile::qmakespec.isEmpty()) { | 
|---|
|  | 654 | QFileInfo specfi(Option::mkfile::qmakespec); | 
|---|
|  | 655 | QDir specdir(specfi.absoluteFilePath()); | 
|---|
|  | 656 | while(!specdir.isRoot()) { | 
|---|
|  | 657 | if(!specdir.cdUp() || specdir.isRoot()) | 
|---|
|  | 658 | break; | 
|---|
|  | 659 | if(QFile::exists(specdir.path() + QDir::separator() + "features")) { | 
|---|
|  | 660 | for(QStringList::Iterator concat_it = concat.begin(); | 
|---|
|  | 661 | concat_it != concat.end(); ++concat_it) | 
|---|
|  | 662 | feature_roots << (specdir.path() + (*concat_it)); | 
|---|
|  | 663 | break; | 
|---|
|  | 664 | } | 
|---|
|  | 665 | } | 
|---|
|  | 666 | } | 
|---|
|  | 667 | for(QStringList::Iterator concat_it = concat.begin(); | 
|---|
|  | 668 | concat_it != concat.end(); ++concat_it) | 
|---|
|  | 669 | feature_roots << (QLibraryInfo::location(QLibraryInfo::PrefixPath) + | 
|---|
|  | 670 | mkspecs_concat + (*concat_it)); | 
|---|
|  | 671 | for(QStringList::Iterator concat_it = concat.begin(); | 
|---|
|  | 672 | concat_it != concat.end(); ++concat_it) | 
|---|
|  | 673 | feature_roots << (QLibraryInfo::location(QLibraryInfo::DataPath) + | 
|---|
|  | 674 | mkspecs_concat + (*concat_it)); | 
|---|
|  | 675 | return feature_roots; | 
|---|
|  | 676 | } | 
|---|
|  | 677 |  | 
|---|
|  | 678 | QStringList qmake_mkspec_paths() | 
|---|
|  | 679 | { | 
|---|
|  | 680 | QStringList ret; | 
|---|
|  | 681 | const QString concat = QDir::separator() + QString("mkspecs"); | 
|---|
|  | 682 | QByteArray qmakepath = qgetenv("QMAKEPATH"); | 
|---|
|  | 683 | if (!qmakepath.isEmpty()) { | 
|---|
|  | 684 | const QStringList lst = splitPathList(QString::fromLocal8Bit(qmakepath)); | 
|---|
|  | 685 | for(QStringList::ConstIterator it = lst.begin(); it != lst.end(); ++it) | 
|---|
|  | 686 | ret << ((*it) + concat); | 
|---|
|  | 687 | } | 
|---|
|  | 688 | ret << QLibraryInfo::location(QLibraryInfo::DataPath) + concat; | 
|---|
|  | 689 |  | 
|---|
|  | 690 | return ret; | 
|---|
|  | 691 | } | 
|---|
|  | 692 |  | 
|---|
|  | 693 | class QMakeProjectEnv | 
|---|
|  | 694 | { | 
|---|
|  | 695 | QStringList envs; | 
|---|
|  | 696 | public: | 
|---|
|  | 697 | QMakeProjectEnv() { } | 
|---|
|  | 698 | QMakeProjectEnv(QMakeProject *p) { execute(p->variables()); } | 
|---|
|  | 699 | QMakeProjectEnv(const QMap<QString, QStringList> &values) { execute(values); } | 
|---|
|  | 700 |  | 
|---|
|  | 701 | void execute(QMakeProject *p) { execute(p->variables()); } | 
|---|
|  | 702 | void execute(const QMap<QString, QStringList> &values) { | 
|---|
|  | 703 | #ifdef Q_OS_UNIX | 
|---|
|  | 704 | for(QMap<QString, QStringList>::ConstIterator it = values.begin(); it != values.end(); ++it) { | 
|---|
|  | 705 | const QString var = it.key(), val = it.value().join(" "); | 
|---|
|  | 706 | if(!var.startsWith(".")) { | 
|---|
|  | 707 | const QString env_var = Option::sysenv_mod + var; | 
|---|
|  | 708 | if(!putenv(strdup(QString(env_var + "=" + val).toAscii().data()))) | 
|---|
|  | 709 | envs.append(env_var); | 
|---|
|  | 710 | } | 
|---|
|  | 711 | } | 
|---|
|  | 712 | #else | 
|---|
|  | 713 | Q_UNUSED(values); | 
|---|
|  | 714 | #endif | 
|---|
|  | 715 | } | 
|---|
|  | 716 | ~QMakeProjectEnv() { | 
|---|
|  | 717 | #ifdef Q_OS_UNIX | 
|---|
|  | 718 | for(QStringList::ConstIterator it = envs.begin();it != envs.end(); ++it) { | 
|---|
|  | 719 | putenv(strdup(QString(*it + "=").toAscii().data())); | 
|---|
|  | 720 | } | 
|---|
|  | 721 | #endif | 
|---|
|  | 722 | } | 
|---|
|  | 723 | }; | 
|---|
|  | 724 |  | 
|---|
|  | 725 | QMakeProject::~QMakeProject() | 
|---|
|  | 726 | { | 
|---|
|  | 727 | if(own_prop) | 
|---|
|  | 728 | delete prop; | 
|---|
|  | 729 | for(QMap<QString, FunctionBlock*>::iterator it = replaceFunctions.begin(); it != replaceFunctions.end(); ++it) { | 
|---|
|  | 730 | if(!it.value()->deref()) | 
|---|
|  | 731 | delete it.value(); | 
|---|
|  | 732 | } | 
|---|
|  | 733 | replaceFunctions.clear(); | 
|---|
|  | 734 | for(QMap<QString, FunctionBlock*>::iterator it = testFunctions.begin(); it != testFunctions.end(); ++it) { | 
|---|
|  | 735 | if(!it.value()->deref()) | 
|---|
|  | 736 | delete it.value(); | 
|---|
|  | 737 | } | 
|---|
|  | 738 | testFunctions.clear(); | 
|---|
|  | 739 | } | 
|---|
|  | 740 |  | 
|---|
|  | 741 |  | 
|---|
|  | 742 | void | 
|---|
|  | 743 | QMakeProject::init(QMakeProperty *p, const QMap<QString, QStringList> *vars) | 
|---|
|  | 744 | { | 
|---|
|  | 745 | if(vars) | 
|---|
|  | 746 | base_vars = *vars; | 
|---|
|  | 747 | if(!p) { | 
|---|
|  | 748 | prop = new QMakeProperty; | 
|---|
|  | 749 | own_prop = true; | 
|---|
|  | 750 | } else { | 
|---|
|  | 751 | prop = p; | 
|---|
|  | 752 | own_prop = false; | 
|---|
|  | 753 | } | 
|---|
|  | 754 | reset(); | 
|---|
|  | 755 | } | 
|---|
|  | 756 |  | 
|---|
|  | 757 | QMakeProject::QMakeProject(QMakeProject *p, const QMap<QString, QStringList> *vars) | 
|---|
|  | 758 | { | 
|---|
|  | 759 | init(p->properties(), vars ? vars : &p->variables()); | 
|---|
|  | 760 | for(QMap<QString, FunctionBlock*>::iterator it = p->replaceFunctions.begin(); it != p->replaceFunctions.end(); ++it) { | 
|---|
|  | 761 | it.value()->ref(); | 
|---|
|  | 762 | replaceFunctions.insert(it.key(), it.value()); | 
|---|
|  | 763 | } | 
|---|
|  | 764 | for(QMap<QString, FunctionBlock*>::iterator it = p->testFunctions.begin(); it != p->testFunctions.end(); ++it) { | 
|---|
|  | 765 | it.value()->ref(); | 
|---|
|  | 766 | testFunctions.insert(it.key(), it.value()); | 
|---|
|  | 767 | } | 
|---|
|  | 768 | } | 
|---|
|  | 769 |  | 
|---|
|  | 770 | void | 
|---|
|  | 771 | QMakeProject::reset() | 
|---|
|  | 772 | { | 
|---|
|  | 773 | // scope_blocks starts with one non-ignoring entity | 
|---|
|  | 774 | scope_blocks.clear(); | 
|---|
|  | 775 | scope_blocks.push(ScopeBlock()); | 
|---|
|  | 776 | iterator = 0; | 
|---|
|  | 777 | function = 0; | 
|---|
|  | 778 | } | 
|---|
|  | 779 |  | 
|---|
|  | 780 | bool | 
|---|
|  | 781 | QMakeProject::parse(const QString &t, QMap<QString, QStringList> &place, int numLines) | 
|---|
|  | 782 | { | 
|---|
|  | 783 | QString s = t.simplified(); | 
|---|
|  | 784 | int hash_mark = s.indexOf("#"); | 
|---|
|  | 785 | if(hash_mark != -1) //good bye comments | 
|---|
|  | 786 | s = s.left(hash_mark); | 
|---|
|  | 787 | if(s.isEmpty()) // blank_line | 
|---|
|  | 788 | return true; | 
|---|
|  | 789 |  | 
|---|
|  | 790 | if(scope_blocks.top().ignore) { | 
|---|
|  | 791 | bool continue_parsing = false; | 
|---|
|  | 792 | // adjust scope for each block which appears on a single line | 
|---|
|  | 793 | for(int i = 0; i < s.length(); i++) { | 
|---|
|  | 794 | if(s[i] == '{') { | 
|---|
|  | 795 | scope_blocks.push(ScopeBlock(true)); | 
|---|
|  | 796 | } else if(s[i] == '}') { | 
|---|
|  | 797 | if(scope_blocks.count() == 1) { | 
|---|
|  | 798 | fprintf(stderr, "Braces mismatch %s:%d\n", parser.file.toLatin1().constData(), parser.line_no); | 
|---|
|  | 799 | return false; | 
|---|
|  | 800 | } | 
|---|
|  | 801 | ScopeBlock sb = scope_blocks.pop(); | 
|---|
|  | 802 | if(sb.iterate) { | 
|---|
|  | 803 | sb.iterate->exec(this, place); | 
|---|
|  | 804 | delete sb.iterate; | 
|---|
|  | 805 | sb.iterate = 0; | 
|---|
|  | 806 | } | 
|---|
|  | 807 | if(!scope_blocks.top().ignore) { | 
|---|
|  | 808 | debug_msg(1, "Project Parser: %s:%d : Leaving block %d", parser.file.toLatin1().constData(), | 
|---|
|  | 809 | parser.line_no, scope_blocks.count()+1); | 
|---|
|  | 810 | s = s.mid(i+1).trimmed(); | 
|---|
|  | 811 | continue_parsing = !s.isEmpty(); | 
|---|
|  | 812 | break; | 
|---|
|  | 813 | } | 
|---|
|  | 814 | } | 
|---|
|  | 815 | } | 
|---|
|  | 816 | if(!continue_parsing) { | 
|---|
|  | 817 | debug_msg(1, "Project Parser: %s:%d : Ignored due to block being false.", | 
|---|
|  | 818 | parser.file.toLatin1().constData(), parser.line_no); | 
|---|
|  | 819 | return true; | 
|---|
|  | 820 | } | 
|---|
|  | 821 | } | 
|---|
|  | 822 |  | 
|---|
|  | 823 | if(function) { | 
|---|
|  | 824 | QString append; | 
|---|
|  | 825 | int d_off = 0; | 
|---|
|  | 826 | const QChar *d = s.unicode(); | 
|---|
|  | 827 | bool function_finished = false; | 
|---|
|  | 828 | while(d_off < s.length()) { | 
|---|
|  | 829 | if(*(d+d_off) == QLatin1Char('}')) { | 
|---|
|  | 830 | function->scope_level--; | 
|---|
|  | 831 | if(!function->scope_level) { | 
|---|
|  | 832 | function_finished = true; | 
|---|
|  | 833 | break; | 
|---|
|  | 834 | } | 
|---|
|  | 835 | } else if(*(d+d_off) == QLatin1Char('{')) { | 
|---|
|  | 836 | function->scope_level++; | 
|---|
|  | 837 | } | 
|---|
|  | 838 | append += *(d+d_off); | 
|---|
|  | 839 | ++d_off; | 
|---|
|  | 840 | } | 
|---|
|  | 841 | if(!append.isEmpty()) | 
|---|
|  | 842 | function->parselist.append(IteratorBlock::Parse(append)); | 
|---|
|  | 843 | if(function_finished) { | 
|---|
|  | 844 | function = 0; | 
|---|
|  | 845 | s = QString(d+d_off, s.length()-d_off); | 
|---|
|  | 846 | } else { | 
|---|
|  | 847 | return true; | 
|---|
|  | 848 | } | 
|---|
|  | 849 | } else if(IteratorBlock *it = scope_blocks.top().iterate) { | 
|---|
|  | 850 | QString append; | 
|---|
|  | 851 | int d_off = 0; | 
|---|
|  | 852 | const QChar *d = s.unicode(); | 
|---|
|  | 853 | bool iterate_finished = false; | 
|---|
|  | 854 | while(d_off < s.length()) { | 
|---|
|  | 855 | if(*(d+d_off) == QLatin1Char('}')) { | 
|---|
|  | 856 | it->scope_level--; | 
|---|
|  | 857 | if(!it->scope_level) { | 
|---|
|  | 858 | iterate_finished = true; | 
|---|
|  | 859 | break; | 
|---|
|  | 860 | } | 
|---|
|  | 861 | } else if(*(d+d_off) == QLatin1Char('{')) { | 
|---|
|  | 862 | it->scope_level++; | 
|---|
|  | 863 | } | 
|---|
|  | 864 | append += *(d+d_off); | 
|---|
|  | 865 | ++d_off; | 
|---|
|  | 866 | } | 
|---|
|  | 867 | if(!append.isEmpty()) | 
|---|
|  | 868 | scope_blocks.top().iterate->parselist.append(IteratorBlock::Parse(append)); | 
|---|
|  | 869 | if(iterate_finished) { | 
|---|
|  | 870 | scope_blocks.top().iterate = 0; | 
|---|
|  | 871 | bool ret = it->exec(this, place); | 
|---|
|  | 872 | delete it; | 
|---|
|  | 873 | if(!ret) | 
|---|
|  | 874 | return false; | 
|---|
|  | 875 | s = s.mid(d_off); | 
|---|
|  | 876 | } else { | 
|---|
|  | 877 | return true; | 
|---|
|  | 878 | } | 
|---|
|  | 879 | } | 
|---|
|  | 880 |  | 
|---|
|  | 881 | QString scope, var, op; | 
|---|
|  | 882 | QStringList val; | 
|---|
|  | 883 | #define SKIP_WS(d, o, l) while(o < l && (*(d+o) == QLatin1Char(' ') || *(d+o) == QLatin1Char('\t'))) ++o | 
|---|
|  | 884 | const QChar *d = s.unicode(); | 
|---|
|  | 885 | int d_off = 0; | 
|---|
|  | 886 | SKIP_WS(d, d_off, s.length()); | 
|---|
|  | 887 | IteratorBlock *iterator = 0; | 
|---|
|  | 888 | bool scope_failed = false, else_line = false, or_op=false; | 
|---|
|  | 889 | QChar quote = 0; | 
|---|
|  | 890 | int parens = 0, scope_count=0, start_block = 0; | 
|---|
|  | 891 | while(d_off < s.length()) { | 
|---|
|  | 892 | if(!parens) { | 
|---|
|  | 893 | if(*(d+d_off) == QLatin1Char('=')) | 
|---|
|  | 894 | break; | 
|---|
|  | 895 | if(*(d+d_off) == QLatin1Char('+') || *(d+d_off) == QLatin1Char('-') || | 
|---|
|  | 896 | *(d+d_off) == QLatin1Char('*') || *(d+d_off) == QLatin1Char('~')) { | 
|---|
|  | 897 | if(*(d+d_off+1) == QLatin1Char('=')) { | 
|---|
|  | 898 | break; | 
|---|
|  | 899 | } else if(*(d+d_off+1) == QLatin1Char(' ')) { | 
|---|
|  | 900 | const QChar *k = d+d_off+1; | 
|---|
|  | 901 | int k_off = 0; | 
|---|
|  | 902 | SKIP_WS(k, k_off, s.length()-d_off); | 
|---|
|  | 903 | if(*(k+k_off) == QLatin1Char('=')) { | 
|---|
|  | 904 | QString msg; | 
|---|
|  | 905 | qmake_error_msg(QString(d+d_off, 1) + "must be followed immediately by ="); | 
|---|
|  | 906 | return false; | 
|---|
|  | 907 | } | 
|---|
|  | 908 | } | 
|---|
|  | 909 | } | 
|---|
|  | 910 | } | 
|---|
|  | 911 |  | 
|---|
|  | 912 | if(!quote.isNull()) { | 
|---|
|  | 913 | if(*(d+d_off) == quote) | 
|---|
|  | 914 | quote = QChar(); | 
|---|
|  | 915 | } else if(*(d+d_off) == '(') { | 
|---|
|  | 916 | ++parens; | 
|---|
|  | 917 | } else if(*(d+d_off) == ')') { | 
|---|
|  | 918 | --parens; | 
|---|
|  | 919 | } else if(*(d+d_off) == '"' /*|| *(d+d_off) == '\''*/) { | 
|---|
|  | 920 | quote = *(d+d_off); | 
|---|
|  | 921 | } | 
|---|
|  | 922 |  | 
|---|
|  | 923 | if(!parens && quote.isNull() && | 
|---|
|  | 924 | (*(d+d_off) == QLatin1Char(':') || *(d+d_off) == QLatin1Char('{') || | 
|---|
|  | 925 | *(d+d_off) == QLatin1Char(')') || *(d+d_off) == QLatin1Char('|'))) { | 
|---|
|  | 926 | scope_count++; | 
|---|
|  | 927 | scope = var.trimmed(); | 
|---|
|  | 928 | if(*(d+d_off) == QLatin1Char(')')) | 
|---|
|  | 929 | scope += *(d+d_off); // need this | 
|---|
|  | 930 | var = ""; | 
|---|
|  | 931 |  | 
|---|
|  | 932 | bool test = scope_failed; | 
|---|
|  | 933 | if(scope.isEmpty()) { | 
|---|
|  | 934 | test = true; | 
|---|
|  | 935 | } else if(scope.toLower() == "else") { //else is a builtin scope here as it modifies state | 
|---|
|  | 936 | if(scope_count != 1 || scope_blocks.top().else_status == ScopeBlock::TestNone) { | 
|---|
|  | 937 | qmake_error_msg(("Unexpected " + scope + " ('" + s + "')").toLatin1()); | 
|---|
|  | 938 | return false; | 
|---|
|  | 939 | } | 
|---|
|  | 940 | else_line = true; | 
|---|
|  | 941 | test = (scope_blocks.top().else_status == ScopeBlock::TestSeek); | 
|---|
|  | 942 | debug_msg(1, "Project Parser: %s:%d : Else%s %s.", parser.file.toLatin1().constData(), parser.line_no, | 
|---|
|  | 943 | scope == "else" ? "" : QString(" (" + scope + ")").toLatin1().constData(), | 
|---|
|  | 944 | test ? "considered" : "excluded"); | 
|---|
|  | 945 | } else { | 
|---|
|  | 946 | QString comp_scope = scope; | 
|---|
|  | 947 | bool invert_test = (comp_scope.at(0) == QLatin1Char('!')); | 
|---|
|  | 948 | if(invert_test) | 
|---|
|  | 949 | comp_scope = comp_scope.mid(1); | 
|---|
|  | 950 | int lparen = comp_scope.indexOf('('); | 
|---|
|  | 951 | if(or_op == scope_failed) { | 
|---|
|  | 952 | if(lparen != -1) { // if there is an lparen in the scope, it IS a function | 
|---|
|  | 953 | int rparen = comp_scope.lastIndexOf(')'); | 
|---|
|  | 954 | if(rparen == -1) { | 
|---|
|  | 955 | qmake_error_msg("Function missing right paren: " + comp_scope); | 
|---|
|  | 956 | return false; | 
|---|
|  | 957 | } | 
|---|
|  | 958 | QString func = comp_scope.left(lparen); | 
|---|
|  | 959 | QStringList args = split_arg_list(comp_scope.mid(lparen+1, rparen - lparen - 1)); | 
|---|
|  | 960 | if(function) { | 
|---|
|  | 961 | fprintf(stderr, "%s:%d: No tests can come after a function definition!\n", | 
|---|
|  | 962 | parser.file.toLatin1().constData(), parser.line_no); | 
|---|
|  | 963 | return false; | 
|---|
|  | 964 | } else if(func == "for") { //for is a builtin function here, as it modifies state | 
|---|
|  | 965 | if(args.count() > 2 || args.count() < 1) { | 
|---|
|  | 966 | fprintf(stderr, "%s:%d: for(iterate, list) requires two arguments.\n", | 
|---|
|  | 967 | parser.file.toLatin1().constData(), parser.line_no); | 
|---|
|  | 968 | return false; | 
|---|
|  | 969 | } else if(iterator) { | 
|---|
|  | 970 | fprintf(stderr, "%s:%d unexpected nested for()\n", | 
|---|
|  | 971 | parser.file.toLatin1().constData(), parser.line_no); | 
|---|
|  | 972 | return false; | 
|---|
|  | 973 | } | 
|---|
|  | 974 |  | 
|---|
|  | 975 | iterator = new IteratorBlock; | 
|---|
|  | 976 | QString it_list; | 
|---|
|  | 977 | if(args.count() == 1) { | 
|---|
|  | 978 | doVariableReplace(args[0], place); | 
|---|
|  | 979 | it_list = args[0]; | 
|---|
|  | 980 | if(args[0] != "ever") { | 
|---|
|  | 981 | delete iterator; | 
|---|
|  | 982 | iterator = 0; | 
|---|
|  | 983 | fprintf(stderr, "%s:%d: for(iterate, list) requires two arguments.\n", | 
|---|
|  | 984 | parser.file.toLatin1().constData(), parser.line_no); | 
|---|
|  | 985 | return false; | 
|---|
|  | 986 | } | 
|---|
|  | 987 | it_list = "forever"; | 
|---|
|  | 988 | } else if(args.count() == 2) { | 
|---|
|  | 989 | iterator->variable = args[0]; | 
|---|
|  | 990 | doVariableReplace(args[1], place); | 
|---|
|  | 991 | it_list = args[1]; | 
|---|
|  | 992 | } | 
|---|
|  | 993 | QStringList list = place[it_list]; | 
|---|
|  | 994 | if(list.isEmpty()) { | 
|---|
|  | 995 | if(it_list == "forever") { | 
|---|
|  | 996 | iterator->loop_forever = true; | 
|---|
|  | 997 | } else { | 
|---|
|  | 998 | int dotdot = it_list.indexOf(".."); | 
|---|
|  | 999 | if(dotdot != -1) { | 
|---|
|  | 1000 | bool ok; | 
|---|
|  | 1001 | int start = it_list.left(dotdot).toInt(&ok); | 
|---|
|  | 1002 | if(ok) { | 
|---|
|  | 1003 | int end = it_list.mid(dotdot+2).toInt(&ok); | 
|---|
|  | 1004 | if(ok) { | 
|---|
|  | 1005 | if(start < end) { | 
|---|
|  | 1006 | for(int i = start; i <= end; i++) | 
|---|
|  | 1007 | list << QString::number(i); | 
|---|
|  | 1008 | } else { | 
|---|
|  | 1009 | for(int i = start; i >= end; i--) | 
|---|
|  | 1010 | list << QString::number(i); | 
|---|
|  | 1011 | } | 
|---|
|  | 1012 | } | 
|---|
|  | 1013 | } | 
|---|
|  | 1014 | } | 
|---|
|  | 1015 | } | 
|---|
|  | 1016 | } | 
|---|
|  | 1017 | iterator->list = list; | 
|---|
|  | 1018 | test = !invert_test; | 
|---|
|  | 1019 | } else if(iterator) { | 
|---|
|  | 1020 | iterator->test.append(IteratorBlock::Test(func, args, invert_test)); | 
|---|
|  | 1021 | test = !invert_test; | 
|---|
|  | 1022 | } else if(func == "defineTest" || func == "defineReplace") { | 
|---|
|  | 1023 | if(!function_blocks.isEmpty()) { | 
|---|
|  | 1024 | fprintf(stderr, | 
|---|
|  | 1025 | "%s:%d: cannot define a function within another definition.\n", | 
|---|
|  | 1026 | parser.file.toLatin1().constData(), parser.line_no); | 
|---|
|  | 1027 | return false; | 
|---|
|  | 1028 | } | 
|---|
|  | 1029 | if(args.count() != 1) { | 
|---|
|  | 1030 | fprintf(stderr, "%s:%d: %s(function_name) requires one argument.\n", | 
|---|
|  | 1031 | parser.file.toLatin1().constData(), parser.line_no, func.toLatin1().constData()); | 
|---|
|  | 1032 | return false; | 
|---|
|  | 1033 | } | 
|---|
|  | 1034 | QMap<QString, FunctionBlock*> *map = 0; | 
|---|
|  | 1035 | if(func == "defineTest") | 
|---|
|  | 1036 | map = &testFunctions; | 
|---|
|  | 1037 | else | 
|---|
|  | 1038 | map = &replaceFunctions; | 
|---|
|  | 1039 | #if 0 | 
|---|
|  | 1040 | if(!map || map->contains(args[0])) { | 
|---|
|  | 1041 | fprintf(stderr, "%s:%d: Function[%s] multiply defined.\n", | 
|---|
|  | 1042 | parser.file.toLatin1().constData(), parser.line_no, args[0].toLatin1().constData()); | 
|---|
|  | 1043 | return false; | 
|---|
|  | 1044 | } | 
|---|
|  | 1045 | #endif | 
|---|
|  | 1046 | function = new FunctionBlock; | 
|---|
|  | 1047 | map->insert(args[0], function); | 
|---|
|  | 1048 | test = true; | 
|---|
|  | 1049 | } else { | 
|---|
|  | 1050 | test = doProjectTest(func, args, place); | 
|---|
|  | 1051 | if(*(d+d_off) == QLatin1Char(')') && d_off == s.length()-1) { | 
|---|
|  | 1052 | if(invert_test) | 
|---|
|  | 1053 | test = !test; | 
|---|
|  | 1054 | scope_blocks.top().else_status = | 
|---|
|  | 1055 | (test ? ScopeBlock::TestFound : ScopeBlock::TestSeek); | 
|---|
|  | 1056 | return true;  // assume we are done | 
|---|
|  | 1057 | } | 
|---|
|  | 1058 | } | 
|---|
|  | 1059 | } else { | 
|---|
|  | 1060 | QString cscope = comp_scope.trimmed(); | 
|---|
|  | 1061 | doVariableReplace(cscope, place); | 
|---|
|  | 1062 | test = isActiveConfig(cscope.trimmed(), true, &place); | 
|---|
|  | 1063 | } | 
|---|
|  | 1064 | if(invert_test) | 
|---|
|  | 1065 | test = !test; | 
|---|
|  | 1066 | } | 
|---|
|  | 1067 | } | 
|---|
|  | 1068 | if(!test && !scope_failed) | 
|---|
|  | 1069 | debug_msg(1, "Project Parser: %s:%d : Test (%s) failed.", parser.file.toLatin1().constData(), | 
|---|
|  | 1070 | parser.line_no, scope.toLatin1().constData()); | 
|---|
|  | 1071 | if(test == or_op) | 
|---|
|  | 1072 | scope_failed = !test; | 
|---|
|  | 1073 | or_op = (*(d+d_off) == QLatin1Char('|')); | 
|---|
|  | 1074 |  | 
|---|
|  | 1075 | if(*(d+d_off) == QLatin1Char('{')) { // scoping block | 
|---|
|  | 1076 | start_block++; | 
|---|
|  | 1077 | if(iterator) { | 
|---|
|  | 1078 | for(int off = 0, braces = 0; true; ++off) { | 
|---|
|  | 1079 | if(*(d+d_off+off) == QLatin1Char('{')) | 
|---|
|  | 1080 | ++braces; | 
|---|
|  | 1081 | else if(*(d+d_off+off) == QLatin1Char('}') && braces) | 
|---|
|  | 1082 | --braces; | 
|---|
|  | 1083 | if(!braces || d_off+off == s.length()) { | 
|---|
|  | 1084 | iterator->parselist.append(s.mid(d_off, off-1)); | 
|---|
|  | 1085 | if(braces > 1) | 
|---|
|  | 1086 | iterator->scope_level += braces-1; | 
|---|
|  | 1087 | d_off += off-1; | 
|---|
|  | 1088 | break; | 
|---|
|  | 1089 | } | 
|---|
|  | 1090 | } | 
|---|
|  | 1091 | } | 
|---|
|  | 1092 | } | 
|---|
|  | 1093 | } else if(!parens && *(d+d_off) == QLatin1Char('}')) { | 
|---|
|  | 1094 | if(start_block) { | 
|---|
|  | 1095 | --start_block; | 
|---|
|  | 1096 | } else if(!scope_blocks.count()) { | 
|---|
|  | 1097 | warn_msg(WarnParser, "Possible braces mismatch %s:%d", parser.file.toLatin1().constData(), parser.line_no); | 
|---|
|  | 1098 | } else { | 
|---|
|  | 1099 | if(scope_blocks.count() == 1) { | 
|---|
|  | 1100 | fprintf(stderr, "Braces mismatch %s:%d\n", parser.file.toLatin1().constData(), parser.line_no); | 
|---|
|  | 1101 | return false; | 
|---|
|  | 1102 | } | 
|---|
|  | 1103 | debug_msg(1, "Project Parser: %s:%d : Leaving block %d", parser.file.toLatin1().constData(), | 
|---|
|  | 1104 | parser.line_no, scope_blocks.count()); | 
|---|
|  | 1105 | ScopeBlock sb = scope_blocks.pop(); | 
|---|
|  | 1106 | if(sb.iterate) | 
|---|
|  | 1107 | sb.iterate->exec(this, place); | 
|---|
|  | 1108 | } | 
|---|
|  | 1109 | } else { | 
|---|
|  | 1110 | var += *(d+d_off); | 
|---|
|  | 1111 | } | 
|---|
|  | 1112 | ++d_off; | 
|---|
|  | 1113 | } | 
|---|
|  | 1114 | var = var.trimmed(); | 
|---|
|  | 1115 |  | 
|---|
|  | 1116 | if(!else_line || (else_line && !scope_failed)) | 
|---|
|  | 1117 | scope_blocks.top().else_status = (!scope_failed ? ScopeBlock::TestFound : ScopeBlock::TestSeek); | 
|---|
|  | 1118 | if(start_block) { | 
|---|
|  | 1119 | ScopeBlock next_block(scope_failed); | 
|---|
|  | 1120 | next_block.iterate = iterator; | 
|---|
|  | 1121 | if(iterator) | 
|---|
|  | 1122 | next_block.else_status = ScopeBlock::TestNone; | 
|---|
|  | 1123 | else if(scope_failed) | 
|---|
|  | 1124 | next_block.else_status = ScopeBlock::TestSeek; | 
|---|
|  | 1125 | else | 
|---|
|  | 1126 | next_block.else_status = ScopeBlock::TestFound; | 
|---|
|  | 1127 | scope_blocks.push(next_block); | 
|---|
|  | 1128 | debug_msg(1, "Project Parser: %s:%d : Entering block %d (%d). [%s]", parser.file.toLatin1().constData(), | 
|---|
|  | 1129 | parser.line_no, scope_blocks.count(), scope_failed, s.toLatin1().constData()); | 
|---|
|  | 1130 | } else if(iterator) { | 
|---|
|  | 1131 | iterator->parselist.append(var+s.mid(d_off)); | 
|---|
|  | 1132 | bool ret = iterator->exec(this, place); | 
|---|
|  | 1133 | delete iterator; | 
|---|
|  | 1134 | return ret; | 
|---|
|  | 1135 | } | 
|---|
|  | 1136 |  | 
|---|
|  | 1137 | if((!scope_count && !var.isEmpty()) || (scope_count == 1 && else_line)) | 
|---|
|  | 1138 | scope_blocks.top().else_status = ScopeBlock::TestNone; | 
|---|
|  | 1139 | if(d_off == s.length()) { | 
|---|
|  | 1140 | if(!var.trimmed().isEmpty()) | 
|---|
|  | 1141 | qmake_error_msg(("Parse Error ('" + s + "')").toLatin1()); | 
|---|
|  | 1142 | return var.isEmpty(); // allow just a scope | 
|---|
|  | 1143 | } | 
|---|
|  | 1144 |  | 
|---|
|  | 1145 | SKIP_WS(d, d_off, s.length()); | 
|---|
|  | 1146 | for(; d_off < s.length() && op.indexOf('=') == -1; op += *(d+(d_off++))) | 
|---|
|  | 1147 | ; | 
|---|
|  | 1148 | op.replace(QRegExp("\\s"), ""); | 
|---|
|  | 1149 |  | 
|---|
|  | 1150 | SKIP_WS(d, d_off, s.length()); | 
|---|
|  | 1151 | QString vals = s.mid(d_off); // vals now contains the space separated list of values | 
|---|
|  | 1152 | int rbraces = vals.count('}'), lbraces = vals.count('{'); | 
|---|
|  | 1153 | if(scope_blocks.count() > 1 && rbraces - lbraces == 1) { | 
|---|
|  | 1154 | debug_msg(1, "Project Parser: %s:%d : Leaving block %d", parser.file.toLatin1().constData(), | 
|---|
|  | 1155 | parser.line_no, scope_blocks.count()); | 
|---|
|  | 1156 | ScopeBlock sb = scope_blocks.pop(); | 
|---|
|  | 1157 | if(sb.iterate) | 
|---|
|  | 1158 | sb.iterate->exec(this, place); | 
|---|
|  | 1159 | vals.truncate(vals.length()-1); | 
|---|
|  | 1160 | } else if(rbraces != lbraces) { | 
|---|
|  | 1161 | warn_msg(WarnParser, "Possible braces mismatch {%s} %s:%d", | 
|---|
|  | 1162 | vals.toLatin1().constData(), parser.file.toLatin1().constData(), parser.line_no); | 
|---|
|  | 1163 | } | 
|---|
|  | 1164 | if(scope_failed) | 
|---|
|  | 1165 | return true; // oh well | 
|---|
|  | 1166 | #undef SKIP_WS | 
|---|
|  | 1167 |  | 
|---|
|  | 1168 | doVariableReplace(var, place); | 
|---|
|  | 1169 | var = varMap(var); //backwards compatability | 
|---|
|  | 1170 | if(!var.isEmpty() && Option::mkfile::do_preprocess) { | 
|---|
|  | 1171 | static QString last_file("*none*"); | 
|---|
|  | 1172 | if(parser.file != last_file) { | 
|---|
|  | 1173 | fprintf(stdout, "#file %s:%d\n", parser.file.toLatin1().constData(), parser.line_no); | 
|---|
|  | 1174 | last_file = parser.file; | 
|---|
|  | 1175 | } | 
|---|
|  | 1176 | fprintf(stdout, "%s %s %s\n", var.toLatin1().constData(), op.toLatin1().constData(), vals.toLatin1().constData()); | 
|---|
|  | 1177 | } | 
|---|
|  | 1178 |  | 
|---|
|  | 1179 | if(vals.contains('=') && numLines > 1) | 
|---|
|  | 1180 | warn_msg(WarnParser, "Detected possible line continuation: {%s} %s:%d", | 
|---|
|  | 1181 | var.toLatin1().constData(), parser.file.toLatin1().constData(), parser.line_no); | 
|---|
|  | 1182 |  | 
|---|
|  | 1183 | QStringList &varlist = place[var]; // varlist is the list in the symbol table | 
|---|
|  | 1184 |  | 
|---|
|  | 1185 | if(Option::debug_level >= 1) { | 
|---|
|  | 1186 | QString tmp_vals = vals; | 
|---|
|  | 1187 | doVariableReplace(tmp_vals, place); | 
|---|
|  | 1188 | debug_msg(1, "Project Parser: %s:%d :%s: :%s: (%s)", parser.file.toLatin1().constData(), parser.line_no, | 
|---|
|  | 1189 | var.toLatin1().constData(), op.toLatin1().constData(), tmp_vals.toLatin1().constData()); | 
|---|
|  | 1190 | } | 
|---|
|  | 1191 |  | 
|---|
|  | 1192 | // now do the operation | 
|---|
|  | 1193 | if(op == "~=") { | 
|---|
|  | 1194 | doVariableReplace(vals, place); | 
|---|
|  | 1195 | if(vals.length() < 4 || vals.at(0) != 's') { | 
|---|
|  | 1196 | qmake_error_msg(("~= operator only can handle s/// function ('" + | 
|---|
|  | 1197 | s + "')").toLatin1()); | 
|---|
|  | 1198 | return false; | 
|---|
|  | 1199 | } | 
|---|
|  | 1200 | QChar sep = vals.at(1); | 
|---|
|  | 1201 | QStringList func = vals.split(sep); | 
|---|
|  | 1202 | if(func.count() < 3 || func.count() > 4) { | 
|---|
|  | 1203 | qmake_error_msg(("~= operator only can handle s/// function ('" + | 
|---|
|  | 1204 | s + "')").toLatin1()); | 
|---|
|  | 1205 | return false; | 
|---|
|  | 1206 | } | 
|---|
|  | 1207 | bool global = false, case_sense = true, quote = false; | 
|---|
|  | 1208 | if(func.count() == 4) { | 
|---|
|  | 1209 | global = func[3].indexOf('g') != -1; | 
|---|
|  | 1210 | case_sense = func[3].indexOf('i') == -1; | 
|---|
|  | 1211 | quote = func[3].indexOf('q') != -1; | 
|---|
|  | 1212 | } | 
|---|
|  | 1213 | QString from = func[1], to = func[2]; | 
|---|
|  | 1214 | if(quote) | 
|---|
|  | 1215 | from = QRegExp::escape(from); | 
|---|
|  | 1216 | QRegExp regexp(from, case_sense ? Qt::CaseSensitive : Qt::CaseInsensitive); | 
|---|
|  | 1217 | for(QStringList::Iterator varit = varlist.begin(); varit != varlist.end();) { | 
|---|
|  | 1218 | if((*varit).contains(regexp)) { | 
|---|
|  | 1219 | (*varit) = (*varit).replace(regexp, to); | 
|---|
|  | 1220 | if ((*varit).isEmpty()) | 
|---|
|  | 1221 | varit = varlist.erase(varit); | 
|---|
|  | 1222 | else | 
|---|
|  | 1223 | ++varit; | 
|---|
|  | 1224 | if(!global) | 
|---|
|  | 1225 | break; | 
|---|
|  | 1226 | } else | 
|---|
|  | 1227 | ++varit; | 
|---|
|  | 1228 | } | 
|---|
|  | 1229 | } else { | 
|---|
|  | 1230 | QStringList vallist; | 
|---|
|  | 1231 | { | 
|---|
|  | 1232 | //doVariableReplace(vals, place); | 
|---|
|  | 1233 | QStringList tmp = split_value_list(vals, (var == "DEPENDPATH" || var == "INCLUDEPATH")); | 
|---|
|  | 1234 | for(int i = 0; i < tmp.size(); ++i) | 
|---|
|  | 1235 | vallist += doVariableReplaceExpand(tmp[i], place); | 
|---|
|  | 1236 | } | 
|---|
|  | 1237 |  | 
|---|
|  | 1238 | if(op == "=") { | 
|---|
|  | 1239 | if(!varlist.isEmpty()) { | 
|---|
|  | 1240 | bool send_warning = false; | 
|---|
|  | 1241 | if(var != "TEMPLATE" && var != "TARGET") { | 
|---|
|  | 1242 | QSet<QString> incoming_vals = vallist.toSet(); | 
|---|
|  | 1243 | for(int i = 0; i < varlist.size(); ++i) { | 
|---|
|  | 1244 | const QString var = varlist.at(i).trimmed(); | 
|---|
|  | 1245 | if(!var.isEmpty() && !incoming_vals.contains(var)) { | 
|---|
|  | 1246 | send_warning = true; | 
|---|
|  | 1247 | break; | 
|---|
|  | 1248 | } | 
|---|
|  | 1249 | } | 
|---|
|  | 1250 | } | 
|---|
|  | 1251 | if(send_warning) | 
|---|
|  | 1252 | warn_msg(WarnParser, "Operator=(%s) clears variables previously set: %s:%d", | 
|---|
|  | 1253 | var.toLatin1().constData(), parser.file.toLatin1().constData(), parser.line_no); | 
|---|
|  | 1254 | } | 
|---|
|  | 1255 | varlist.clear(); | 
|---|
|  | 1256 | } | 
|---|
|  | 1257 | for(QStringList::ConstIterator valit = vallist.begin(); | 
|---|
|  | 1258 | valit != vallist.end(); ++valit) { | 
|---|
|  | 1259 | if((*valit).isEmpty()) | 
|---|
|  | 1260 | continue; | 
|---|
|  | 1261 | if((op == "*=" && !varlist.contains((*valit))) || | 
|---|
|  | 1262 | op == "=" || op == "+=") | 
|---|
|  | 1263 | varlist.append((*valit)); | 
|---|
|  | 1264 | else if(op == "-=") | 
|---|
|  | 1265 | varlist.removeAll((*valit)); | 
|---|
|  | 1266 | } | 
|---|
|  | 1267 | if(var == "REQUIRES") // special case to get communicated to backends! | 
|---|
|  | 1268 | doProjectCheckReqs(vallist, place); | 
|---|
|  | 1269 | } | 
|---|
|  | 1270 | return true; | 
|---|
|  | 1271 | } | 
|---|
|  | 1272 |  | 
|---|
|  | 1273 | bool | 
|---|
|  | 1274 | QMakeProject::read(QTextStream &file, QMap<QString, QStringList> &place) | 
|---|
|  | 1275 | { | 
|---|
|  | 1276 | int numLines = 0; | 
|---|
|  | 1277 | bool ret = true; | 
|---|
|  | 1278 | QString s; | 
|---|
|  | 1279 | while(!file.atEnd()) { | 
|---|
|  | 1280 | parser.line_no++; | 
|---|
|  | 1281 | QString line = file.readLine().trimmed(); | 
|---|
|  | 1282 | int prelen = line.length(); | 
|---|
|  | 1283 |  | 
|---|
|  | 1284 | int hash_mark = line.indexOf("#"); | 
|---|
|  | 1285 | if(hash_mark != -1) //good bye comments | 
|---|
|  | 1286 | line = line.left(hash_mark).trimmed(); | 
|---|
|  | 1287 | if(!line.isEmpty() && line.right(1) == "\\") { | 
|---|
|  | 1288 | if(!line.startsWith("#")) { | 
|---|
|  | 1289 | line.truncate(line.length() - 1); | 
|---|
|  | 1290 | s += line + Option::field_sep; | 
|---|
|  | 1291 | ++numLines; | 
|---|
|  | 1292 | } | 
|---|
|  | 1293 | } else if(!line.isEmpty() || (line.isEmpty() && !prelen)) { | 
|---|
|  | 1294 | if(s.isEmpty() && line.isEmpty()) | 
|---|
|  | 1295 | continue; | 
|---|
|  | 1296 | if(!line.isEmpty()) { | 
|---|
|  | 1297 | s += line; | 
|---|
|  | 1298 | ++numLines; | 
|---|
|  | 1299 | } | 
|---|
|  | 1300 | if(!s.isEmpty()) { | 
|---|
|  | 1301 | if(!(ret = parse(s, place, numLines))) { | 
|---|
|  | 1302 | s = ""; | 
|---|
|  | 1303 | numLines = 0; | 
|---|
|  | 1304 | break; | 
|---|
|  | 1305 | } | 
|---|
|  | 1306 | s = ""; | 
|---|
|  | 1307 | numLines = 0; | 
|---|
|  | 1308 | } | 
|---|
|  | 1309 | } | 
|---|
|  | 1310 | } | 
|---|
|  | 1311 | if (!s.isEmpty()) | 
|---|
|  | 1312 | ret = parse(s, place, numLines); | 
|---|
|  | 1313 | return ret; | 
|---|
|  | 1314 | } | 
|---|
|  | 1315 |  | 
|---|
|  | 1316 | bool | 
|---|
|  | 1317 | QMakeProject::read(const QString &file, QMap<QString, QStringList> &place) | 
|---|
|  | 1318 | { | 
|---|
|  | 1319 | parser_info pi = parser; | 
|---|
|  | 1320 | reset(); | 
|---|
|  | 1321 |  | 
|---|
|  | 1322 | const QString oldpwd = qmake_getpwd(); | 
|---|
|  | 1323 | QString filename = Option::fixPathToLocalOS(file); | 
|---|
|  | 1324 | doVariableReplace(filename, place); | 
|---|
|  | 1325 | bool ret = false, using_stdin = false; | 
|---|
|  | 1326 | QFile qfile; | 
|---|
|  | 1327 | if(!strcmp(filename.toLatin1(), "-")) { | 
|---|
|  | 1328 | qfile.setFileName(""); | 
|---|
|  | 1329 | ret = qfile.open(stdin, QIODevice::ReadOnly); | 
|---|
|  | 1330 | using_stdin = true; | 
|---|
|  | 1331 | } else if(QFileInfo(file).isDir()) { | 
|---|
|  | 1332 | return false; | 
|---|
|  | 1333 | } else { | 
|---|
|  | 1334 | qfile.setFileName(filename); | 
|---|
|  | 1335 | ret = qfile.open(QIODevice::ReadOnly); | 
|---|
|  | 1336 | qmake_setpwd(QFileInfo(filename).absolutePath()); | 
|---|
|  | 1337 | } | 
|---|
|  | 1338 | if(ret) { | 
|---|
|  | 1339 | parser_info pi = parser; | 
|---|
|  | 1340 | parser.from_file = true; | 
|---|
|  | 1341 | parser.file = filename; | 
|---|
|  | 1342 | parser.line_no = 0; | 
|---|
|  | 1343 | QTextStream t(&qfile); | 
|---|
|  | 1344 | ret = read(t, place); | 
|---|
|  | 1345 | if(!using_stdin) | 
|---|
|  | 1346 | qfile.close(); | 
|---|
|  | 1347 | } | 
|---|
|  | 1348 | if(scope_blocks.count() != 1) { | 
|---|
|  | 1349 | qmake_error_msg("Unterminated conditional block at end of file"); | 
|---|
|  | 1350 | ret = false; | 
|---|
|  | 1351 | } | 
|---|
|  | 1352 | parser = pi; | 
|---|
|  | 1353 | qmake_setpwd(oldpwd); | 
|---|
|  | 1354 | return ret; | 
|---|
|  | 1355 | } | 
|---|
|  | 1356 |  | 
|---|
|  | 1357 | bool | 
|---|
|  | 1358 | QMakeProject::read(const QString &project, uchar cmd) | 
|---|
|  | 1359 | { | 
|---|
|  | 1360 | pfile = QFileInfo(project).absoluteFilePath(); | 
|---|
|  | 1361 | return read(cmd); | 
|---|
|  | 1362 | } | 
|---|
|  | 1363 |  | 
|---|
|  | 1364 | bool | 
|---|
|  | 1365 | QMakeProject::read(uchar cmd) | 
|---|
|  | 1366 | { | 
|---|
|  | 1367 | if(cfile.isEmpty()) { | 
|---|
|  | 1368 | //find out where qmake (myself) lives | 
|---|
|  | 1369 | if (!base_vars.contains("QMAKE_QMAKE")) { | 
|---|
|  | 1370 | if (!Option::qmake_abslocation.isNull()) | 
|---|
|  | 1371 | base_vars["QMAKE_QMAKE"] = QStringList(Option::qmake_abslocation); | 
|---|
|  | 1372 | else | 
|---|
|  | 1373 | base_vars["QMAKE_QMAKE"] = QStringList("qmake"); | 
|---|
|  | 1374 | } | 
|---|
|  | 1375 |  | 
|---|
|  | 1376 | // hack to get the Option stuff in there | 
|---|
|  | 1377 | base_vars["QMAKE_EXT_OBJ"] = QStringList(Option::obj_ext); | 
|---|
|  | 1378 | base_vars["QMAKE_EXT_CPP"] = Option::cpp_ext; | 
|---|
|  | 1379 | base_vars["QMAKE_EXT_C"] = Option::c_ext; | 
|---|
|  | 1380 | base_vars["QMAKE_EXT_H"] = Option::h_ext; | 
|---|
|  | 1381 | base_vars["QMAKE_SH"] = Option::shellPath; | 
|---|
|  | 1382 | if(!Option::user_template_prefix.isEmpty()) | 
|---|
|  | 1383 | base_vars["TEMPLATE_PREFIX"] = QStringList(Option::user_template_prefix); | 
|---|
|  | 1384 |  | 
|---|
|  | 1385 | if(cmd & ReadCache && Option::mkfile::do_cache) {        // parse the cache | 
|---|
|  | 1386 | int cache_depth = -1; | 
|---|
|  | 1387 | QString qmake_cache = Option::mkfile::cachefile; | 
|---|
|  | 1388 | if(qmake_cache.isEmpty())  { //find it as it has not been specified | 
|---|
|  | 1389 | QString dir = QDir::toNativeSeparators(Option::output_dir); | 
|---|
|  | 1390 | while(!QFile::exists((qmake_cache = dir + QDir::separator() + ".qmake.cache"))) { | 
|---|
|  | 1391 | dir = dir.left(dir.lastIndexOf(QDir::separator())); | 
|---|
|  | 1392 | if(dir.isEmpty() || dir.indexOf(QDir::separator()) == -1) { | 
|---|
|  | 1393 | qmake_cache = ""; | 
|---|
|  | 1394 | break; | 
|---|
|  | 1395 | } | 
|---|
|  | 1396 | if(cache_depth == -1) | 
|---|
|  | 1397 | cache_depth = 1; | 
|---|
|  | 1398 | else | 
|---|
|  | 1399 | cache_depth++; | 
|---|
|  | 1400 | } | 
|---|
|  | 1401 | } else { | 
|---|
|  | 1402 | QString abs_cache = QFileInfo(Option::mkfile::cachefile).absoluteDir().path(); | 
|---|
|  | 1403 | if(Option::output_dir.startsWith(abs_cache)) | 
|---|
|  | 1404 | cache_depth = Option::output_dir.mid(abs_cache.length()).count('/'); | 
|---|
|  | 1405 | } | 
|---|
|  | 1406 | if(!qmake_cache.isEmpty()) { | 
|---|
|  | 1407 | if(read(qmake_cache, cache)) { | 
|---|
|  | 1408 | Option::mkfile::cachefile_depth = cache_depth; | 
|---|
|  | 1409 | Option::mkfile::cachefile = qmake_cache; | 
|---|
|  | 1410 | if(Option::mkfile::qmakespec.isEmpty() && !cache["QMAKESPEC"].isEmpty()) | 
|---|
|  | 1411 | Option::mkfile::qmakespec = cache["QMAKESPEC"].first(); | 
|---|
|  | 1412 | } | 
|---|
|  | 1413 | } | 
|---|
|  | 1414 | } | 
|---|
|  | 1415 | if(cmd & ReadConf) {             // parse mkspec | 
|---|
|  | 1416 | QString qmakespec = fixEnvVariables(Option::mkfile::qmakespec); | 
|---|
|  | 1417 | QStringList mkspec_roots = qmake_mkspec_paths(); | 
|---|
|  | 1418 | debug_msg(2, "Looking for mkspec %s in (%s)", qmakespec.toLatin1().constData(), | 
|---|
|  | 1419 | mkspec_roots.join("::").toLatin1().constData()); | 
|---|
|  | 1420 | if(qmakespec.isEmpty()) { | 
|---|
|  | 1421 | for(QStringList::ConstIterator it = mkspec_roots.begin(); it != mkspec_roots.end(); ++it) { | 
|---|
|  | 1422 | QString mkspec = (*it) + QDir::separator() + "default"; | 
|---|
|  | 1423 | QFileInfo default_info(mkspec); | 
|---|
|  | 1424 | if(default_info.exists() && default_info.isDir()) { | 
|---|
|  | 1425 | qmakespec = mkspec; | 
|---|
|  | 1426 | break; | 
|---|
|  | 1427 | } | 
|---|
|  | 1428 | } | 
|---|
|  | 1429 | if(qmakespec.isEmpty()) { | 
|---|
|  | 1430 | fprintf(stderr, "QMAKESPEC has not been set, so configuration cannot be deduced.\n"); | 
|---|
|  | 1431 | return false; | 
|---|
|  | 1432 | } | 
|---|
|  | 1433 | Option::mkfile::qmakespec = qmakespec; | 
|---|
|  | 1434 | } | 
|---|
|  | 1435 |  | 
|---|
|  | 1436 | if(QDir::isRelativePath(qmakespec)) { | 
|---|
|  | 1437 | if (QFile::exists(qmakespec+"/qmake.conf")) { | 
|---|
|  | 1438 | Option::mkfile::qmakespec = QFileInfo(Option::mkfile::qmakespec).absoluteFilePath(); | 
|---|
| [363] | 1439 | } else if (QFile::exists(Option::output_dir+"/"+qmakespec+"/qmake.conf")) { | 
|---|
|  | 1440 | qmakespec = Option::mkfile::qmakespec = QFileInfo(Option::output_dir+"/"+qmakespec).absoluteFilePath(); | 
|---|
| [2] | 1441 | } else { | 
|---|
| [363] | 1442 | bool found_mkspec = false; | 
|---|
|  | 1443 | for(QStringList::ConstIterator it = mkspec_roots.begin(); it != mkspec_roots.end(); ++it) { | 
|---|
|  | 1444 | QString mkspec = (*it) + QDir::separator() + qmakespec; | 
|---|
|  | 1445 | if(QFile::exists(mkspec)) { | 
|---|
|  | 1446 | found_mkspec = true; | 
|---|
|  | 1447 | Option::mkfile::qmakespec = qmakespec = mkspec; | 
|---|
|  | 1448 | break; | 
|---|
| [2] | 1449 | } | 
|---|
|  | 1450 | } | 
|---|
| [363] | 1451 | if(!found_mkspec) { | 
|---|
|  | 1452 | fprintf(stderr, "Could not find mkspecs for your QMAKESPEC(%s) after trying:\n\t%s\n", | 
|---|
|  | 1453 | qmakespec.toLatin1().constData(), mkspec_roots.join("\n\t").toLatin1().constData()); | 
|---|
|  | 1454 | return false; | 
|---|
|  | 1455 | } | 
|---|
| [2] | 1456 | } | 
|---|
|  | 1457 | } | 
|---|
|  | 1458 |  | 
|---|
|  | 1459 | // parse qmake configuration | 
|---|
|  | 1460 | while(qmakespec.endsWith(QString(QChar(QDir::separator())))) | 
|---|
|  | 1461 | qmakespec.truncate(qmakespec.length()-1); | 
|---|
|  | 1462 | QString spec = qmakespec + QDir::separator() + "qmake.conf"; | 
|---|
|  | 1463 | if(!QFile::exists(spec) && | 
|---|
|  | 1464 | QFile::exists(qmakespec + QDir::separator() + "tmake.conf")) | 
|---|
|  | 1465 | spec = qmakespec + QDir::separator() + "tmake.conf"; | 
|---|
|  | 1466 | debug_msg(1, "QMAKESPEC conf: reading %s", spec.toLatin1().constData()); | 
|---|
|  | 1467 | if(!read(spec, base_vars)) { | 
|---|
|  | 1468 | fprintf(stderr, "Failure to read QMAKESPEC conf file %s.\n", spec.toLatin1().constData()); | 
|---|
|  | 1469 | return false; | 
|---|
|  | 1470 | } | 
|---|
| [561] | 1471 |  | 
|---|
|  | 1472 | init_symbian(base_vars); | 
|---|
|  | 1473 |  | 
|---|
| [2] | 1474 | if(Option::mkfile::do_cache && !Option::mkfile::cachefile.isEmpty()) { | 
|---|
|  | 1475 | debug_msg(1, "QMAKECACHE file: reading %s", Option::mkfile::cachefile.toLatin1().constData()); | 
|---|
|  | 1476 | read(Option::mkfile::cachefile, base_vars); | 
|---|
|  | 1477 | } | 
|---|
|  | 1478 | } | 
|---|
|  | 1479 |  | 
|---|
|  | 1480 | if(cmd & ReadFeatures) { | 
|---|
|  | 1481 | debug_msg(1, "Processing default_pre: %s", vars["CONFIG"].join("::").toLatin1().constData()); | 
|---|
|  | 1482 | if(doProjectInclude("default_pre", IncludeFlagFeature, base_vars) == IncludeNoExist) | 
|---|
|  | 1483 | doProjectInclude("default", IncludeFlagFeature, base_vars); | 
|---|
|  | 1484 | } | 
|---|
|  | 1485 | } | 
|---|
|  | 1486 |  | 
|---|
|  | 1487 | vars = base_vars; // start with the base | 
|---|
|  | 1488 |  | 
|---|
|  | 1489 | //get a default | 
|---|
|  | 1490 | if(pfile != "-" && vars["TARGET"].isEmpty()) | 
|---|
|  | 1491 | vars["TARGET"].append(QFileInfo(pfile).baseName()); | 
|---|
|  | 1492 |  | 
|---|
|  | 1493 | //before commandline | 
|---|
|  | 1494 | if(cmd & ReadCmdLine) { | 
|---|
|  | 1495 | cfile = pfile; | 
|---|
|  | 1496 | parser.file = "(internal)"; | 
|---|
|  | 1497 | parser.from_file = false; | 
|---|
|  | 1498 | parser.line_no = 1; //really arg count now.. duh | 
|---|
|  | 1499 | reset(); | 
|---|
|  | 1500 | for(QStringList::ConstIterator it = Option::before_user_vars.begin(); | 
|---|
|  | 1501 | it != Option::before_user_vars.end(); ++it) { | 
|---|
|  | 1502 | if(!parse((*it), vars)) { | 
|---|
|  | 1503 | fprintf(stderr, "Argument failed to parse: %s\n", (*it).toLatin1().constData()); | 
|---|
|  | 1504 | return false; | 
|---|
|  | 1505 | } | 
|---|
|  | 1506 | parser.line_no++; | 
|---|
|  | 1507 | } | 
|---|
|  | 1508 | } | 
|---|
|  | 1509 |  | 
|---|
|  | 1510 | //commandline configs | 
|---|
|  | 1511 | if(cmd & ReadConfigs && !Option::user_configs.isEmpty()) { | 
|---|
|  | 1512 | parser.file = "(configs)"; | 
|---|
|  | 1513 | parser.from_file = false; | 
|---|
|  | 1514 | parser.line_no = 1; //really arg count now.. duh | 
|---|
|  | 1515 | parse("CONFIG += " + Option::user_configs.join(" "), vars); | 
|---|
|  | 1516 | } | 
|---|
|  | 1517 |  | 
|---|
|  | 1518 | if(cmd & ReadProFile) { // parse project file | 
|---|
|  | 1519 | debug_msg(1, "Project file: reading %s", pfile.toLatin1().constData()); | 
|---|
| [561] | 1520 | if(pfile != "-" && !QFile::exists(pfile) && !pfile.endsWith(Option::pro_ext)) | 
|---|
|  | 1521 | pfile += Option::pro_ext; | 
|---|
| [2] | 1522 | if(!read(pfile, vars)) | 
|---|
|  | 1523 | return false; | 
|---|
|  | 1524 | } | 
|---|
|  | 1525 |  | 
|---|
|  | 1526 | if(cmd & ReadPostFiles) { // parse post files | 
|---|
|  | 1527 | const QStringList l = vars["QMAKE_POST_INCLUDE_FILES"]; | 
|---|
|  | 1528 | for(QStringList::ConstIterator it = l.begin(); it != l.end(); ++it) { | 
|---|
|  | 1529 | if(read((*it), vars)) { | 
|---|
|  | 1530 | if(vars["QMAKE_INTERNAL_INCLUDED_FILES"].indexOf((*it)) == -1) | 
|---|
|  | 1531 | vars["QMAKE_INTERNAL_INCLUDED_FILES"].append((*it)); | 
|---|
|  | 1532 | } | 
|---|
|  | 1533 | } | 
|---|
|  | 1534 | } | 
|---|
|  | 1535 |  | 
|---|
|  | 1536 | if(cmd & ReadCmdLine) { | 
|---|
|  | 1537 | parser.file = "(internal)"; | 
|---|
|  | 1538 | parser.from_file = false; | 
|---|
|  | 1539 | parser.line_no = 1; //really arg count now.. duh | 
|---|
|  | 1540 | reset(); | 
|---|
|  | 1541 | for(QStringList::ConstIterator it = Option::after_user_vars.begin(); | 
|---|
|  | 1542 | it != Option::after_user_vars.end(); ++it) { | 
|---|
|  | 1543 | if(!parse((*it), vars)) { | 
|---|
|  | 1544 | fprintf(stderr, "Argument failed to parse: %s\n", (*it).toLatin1().constData()); | 
|---|
|  | 1545 | return false; | 
|---|
|  | 1546 | } | 
|---|
|  | 1547 | parser.line_no++; | 
|---|
|  | 1548 | } | 
|---|
|  | 1549 | } | 
|---|
|  | 1550 |  | 
|---|
|  | 1551 | //after configs (set in BUILDS) | 
|---|
|  | 1552 | if(cmd & ReadConfigs && !Option::after_user_configs.isEmpty()) { | 
|---|
|  | 1553 | parser.file = "(configs)"; | 
|---|
|  | 1554 | parser.from_file = false; | 
|---|
|  | 1555 | parser.line_no = 1; //really arg count now.. duh | 
|---|
|  | 1556 | parse("CONFIG += " + Option::after_user_configs.join(" "), vars); | 
|---|
|  | 1557 | } | 
|---|
|  | 1558 |  | 
|---|
|  | 1559 | if(pfile != "-" && vars["TARGET"].isEmpty()) | 
|---|
|  | 1560 | vars["TARGET"].append(QFileInfo(pfile).baseName()); | 
|---|
|  | 1561 |  | 
|---|
|  | 1562 | if(cmd & ReadConfigs && !Option::user_configs.isEmpty()) { | 
|---|
|  | 1563 | parser.file = "(configs)"; | 
|---|
|  | 1564 | parser.from_file = false; | 
|---|
|  | 1565 | parser.line_no = 1; //really arg count now.. duh | 
|---|
|  | 1566 | parse("CONFIG += " + Option::user_configs.join(" "), base_vars); | 
|---|
|  | 1567 | } | 
|---|
|  | 1568 |  | 
|---|
|  | 1569 | if(cmd & ReadFeatures) { | 
|---|
|  | 1570 | debug_msg(1, "Processing default_post: %s", vars["CONFIG"].join("::").toLatin1().constData()); | 
|---|
|  | 1571 | doProjectInclude("default_post", IncludeFlagFeature, vars); | 
|---|
|  | 1572 |  | 
|---|
|  | 1573 | QHash<QString, bool> processed; | 
|---|
|  | 1574 | const QStringList &configs = vars["CONFIG"]; | 
|---|
|  | 1575 | debug_msg(1, "Processing CONFIG features: %s", configs.join("::").toLatin1().constData()); | 
|---|
|  | 1576 | while(1) { | 
|---|
|  | 1577 | bool finished = true; | 
|---|
|  | 1578 | for(int i = configs.size()-1; i >= 0; --i) { | 
|---|
|  | 1579 | const QString config = configs[i].toLower(); | 
|---|
|  | 1580 | if(!processed.contains(config)) { | 
|---|
|  | 1581 | processed.insert(config, true); | 
|---|
|  | 1582 | if(doProjectInclude(config, IncludeFlagFeature, vars) == IncludeSuccess) { | 
|---|
|  | 1583 | finished = false; | 
|---|
|  | 1584 | break; | 
|---|
|  | 1585 | } | 
|---|
|  | 1586 | } | 
|---|
|  | 1587 | } | 
|---|
|  | 1588 | if(finished) | 
|---|
|  | 1589 | break; | 
|---|
|  | 1590 | } | 
|---|
|  | 1591 | } | 
|---|
|  | 1592 | Option::postProcessProject(this);   // let Option post-process | 
|---|
|  | 1593 | return true; | 
|---|
|  | 1594 | } | 
|---|
|  | 1595 |  | 
|---|
|  | 1596 | bool | 
|---|
|  | 1597 | QMakeProject::isActiveConfig(const QString &x, bool regex, QMap<QString, QStringList> *place) | 
|---|
|  | 1598 | { | 
|---|
|  | 1599 | if(x.isEmpty()) | 
|---|
|  | 1600 | return true; | 
|---|
|  | 1601 |  | 
|---|
|  | 1602 | //magic types for easy flipping | 
|---|
|  | 1603 | if(x == "true") | 
|---|
|  | 1604 | return true; | 
|---|
|  | 1605 | else if(x == "false") | 
|---|
|  | 1606 | return false; | 
|---|
|  | 1607 |  | 
|---|
| [561] | 1608 | static QString spec; | 
|---|
|  | 1609 | if(spec.isEmpty()) | 
|---|
|  | 1610 | spec = QFileInfo(Option::mkfile::qmakespec).fileName(); | 
|---|
|  | 1611 |  | 
|---|
|  | 1612 | // Symbian is an exception to how scopes are resolved. Since we do not | 
|---|
|  | 1613 | // have a separate target mode for Symbian, but we expect the scope to resolve | 
|---|
|  | 1614 | // on other platforms we base it entirely on the mkspec. This means that | 
|---|
|  | 1615 | // using a mkspec starting with 'symbian*' will resolve both the 'symbian' | 
|---|
|  | 1616 | // and the 'unix' (because of Open C) scopes to true. | 
|---|
|  | 1617 | if(isForSymbian() && (x == "symbian" || x == "unix")) | 
|---|
|  | 1618 | return true; | 
|---|
|  | 1619 |  | 
|---|
| [2] | 1620 | //mkspecs | 
|---|
| [561] | 1621 | if((Option::target_mode == Option::TARG_MACX_MODE || | 
|---|
| [2] | 1622 | Option::target_mode == Option::TARG_UNIX_MODE) && x == "unix") | 
|---|
| [561] | 1623 | return !isForSymbian(); | 
|---|
| [2] | 1624 | else if(Option::target_mode == Option::TARG_MACX_MODE && x == "macx") | 
|---|
| [561] | 1625 | return !isForSymbian(); | 
|---|
| [2] | 1626 | else if(Option::target_mode == Option::TARG_MAC9_MODE && x == "mac9") | 
|---|
| [561] | 1627 | return !isForSymbian(); | 
|---|
| [2] | 1628 | else if((Option::target_mode == Option::TARG_MAC9_MODE || Option::target_mode == Option::TARG_MACX_MODE) && | 
|---|
|  | 1629 | x == "mac") | 
|---|
| [561] | 1630 | return !isForSymbian(); | 
|---|
| [2] | 1631 | else if(Option::target_mode == Option::TARG_WIN_MODE && x == "win32") | 
|---|
| [561] | 1632 | return !isForSymbian(); | 
|---|
| [27] | 1633 | else if(Option::target_mode == Option::TARG_OS2_MODE && x == "os2") | 
|---|
|  | 1634 | return true; | 
|---|
| [2] | 1635 | QRegExp re(x, Qt::CaseSensitive, QRegExp::Wildcard); | 
|---|
|  | 1636 | if((regex && re.exactMatch(spec)) || (!regex && spec == x)) | 
|---|
|  | 1637 | return true; | 
|---|
|  | 1638 | #ifdef Q_OS_UNIX | 
|---|
|  | 1639 | else if(spec == "default") { | 
|---|
|  | 1640 | static char *buffer = NULL; | 
|---|
|  | 1641 | if(!buffer) { | 
|---|
|  | 1642 | buffer = (char *)malloc(1024); | 
|---|
|  | 1643 | qmakeAddCacheClear(qmakeFreeCacheClear, (void**)&buffer); | 
|---|
|  | 1644 | } | 
|---|
|  | 1645 | int l = readlink(Option::mkfile::qmakespec.toLatin1(), buffer, 1024); | 
|---|
|  | 1646 | if(l != -1) { | 
|---|
|  | 1647 | buffer[l] = '\0'; | 
|---|
|  | 1648 | QString r = buffer; | 
|---|
|  | 1649 | if(r.lastIndexOf('/') != -1) | 
|---|
|  | 1650 | r = r.mid(r.lastIndexOf('/') + 1); | 
|---|
|  | 1651 | if((regex && re.exactMatch(r)) || (!regex && r == x)) | 
|---|
|  | 1652 | return true; | 
|---|
|  | 1653 | } | 
|---|
|  | 1654 | } | 
|---|
| [27] | 1655 | #elif defined(Q_OS_WIN) || defined(Q_OS_OS2) | 
|---|
| [2] | 1656 | else if(spec == "default") { | 
|---|
|  | 1657 | // We can't resolve symlinks as they do on Unix, so configure.exe puts the source of the | 
|---|
|  | 1658 | // qmake.conf at the end of the default/qmake.conf in the QMAKESPEC_ORG variable. | 
|---|
|  | 1659 | const QStringList &spec_org = (place ? (*place)["QMAKESPEC_ORIGINAL"] | 
|---|
|  | 1660 | : vars["QMAKESPEC_ORIGINAL"]); | 
|---|
|  | 1661 | if (!spec_org.isEmpty()) { | 
|---|
| [28] | 1662 | spec = QFileInfo(spec_org.at(0)).fileName(); | 
|---|
| [2] | 1663 | if((regex && re.exactMatch(spec)) || (!regex && spec == x)) | 
|---|
|  | 1664 | return true; | 
|---|
|  | 1665 | } | 
|---|
|  | 1666 | } | 
|---|
|  | 1667 | #endif | 
|---|
|  | 1668 |  | 
|---|
|  | 1669 | //simple matching | 
|---|
|  | 1670 | const QStringList &configs = (place ? (*place)["CONFIG"] : vars["CONFIG"]); | 
|---|
|  | 1671 | for(QStringList::ConstIterator it = configs.begin(); it != configs.end(); ++it) { | 
|---|
|  | 1672 | if(((regex && re.exactMatch((*it))) || (!regex && (*it) == x)) && re.exactMatch((*it))) | 
|---|
|  | 1673 | return true; | 
|---|
|  | 1674 | } | 
|---|
|  | 1675 | return false; | 
|---|
|  | 1676 | } | 
|---|
|  | 1677 |  | 
|---|
|  | 1678 | bool | 
|---|
|  | 1679 | QMakeProject::doProjectTest(QString str, QMap<QString, QStringList> &place) | 
|---|
|  | 1680 | { | 
|---|
|  | 1681 | QString chk = remove_quotes(str); | 
|---|
|  | 1682 | if(chk.isEmpty()) | 
|---|
|  | 1683 | return true; | 
|---|
|  | 1684 | bool invert_test = (chk.left(1) == "!"); | 
|---|
|  | 1685 | if(invert_test) | 
|---|
|  | 1686 | chk = chk.mid(1); | 
|---|
|  | 1687 |  | 
|---|
|  | 1688 | bool test=false; | 
|---|
|  | 1689 | int lparen = chk.indexOf('('); | 
|---|
|  | 1690 | if(lparen != -1) { // if there is an lparen in the chk, it IS a function | 
|---|
|  | 1691 | int rparen = chk.indexOf(')', lparen); | 
|---|
|  | 1692 | if(rparen == -1) { | 
|---|
|  | 1693 | qmake_error_msg("Function missing right paren: " + chk); | 
|---|
|  | 1694 | } else { | 
|---|
|  | 1695 | QString func = chk.left(lparen); | 
|---|
|  | 1696 | test = doProjectTest(func, chk.mid(lparen+1, rparen - lparen - 1), place); | 
|---|
|  | 1697 | } | 
|---|
|  | 1698 | } else { | 
|---|
|  | 1699 | test = isActiveConfig(chk, true, &place); | 
|---|
|  | 1700 | } | 
|---|
|  | 1701 | if(invert_test) | 
|---|
|  | 1702 | return !test; | 
|---|
|  | 1703 | return test; | 
|---|
|  | 1704 | } | 
|---|
|  | 1705 |  | 
|---|
|  | 1706 | bool | 
|---|
|  | 1707 | QMakeProject::doProjectTest(QString func, const QString ¶ms, | 
|---|
|  | 1708 | QMap<QString, QStringList> &place) | 
|---|
|  | 1709 | { | 
|---|
|  | 1710 | return doProjectTest(func, split_arg_list(params), place); | 
|---|
|  | 1711 | } | 
|---|
|  | 1712 |  | 
|---|
|  | 1713 | QMakeProject::IncludeStatus | 
|---|
|  | 1714 | QMakeProject::doProjectInclude(QString file, uchar flags, QMap<QString, QStringList> &place) | 
|---|
|  | 1715 | { | 
|---|
|  | 1716 | enum { UnknownFormat, ProFormat, JSFormat } format = UnknownFormat; | 
|---|
|  | 1717 | if(flags & IncludeFlagFeature) { | 
|---|
|  | 1718 | if(!file.endsWith(Option::prf_ext)) | 
|---|
|  | 1719 | file += Option::prf_ext; | 
|---|
|  | 1720 | if(file.indexOf(Option::dir_sep) == -1 || !QFile::exists(file)) { | 
|---|
|  | 1721 | static QStringList *feature_roots = 0; | 
|---|
|  | 1722 | if(!feature_roots) { | 
|---|
| [561] | 1723 | init_symbian(base_vars); | 
|---|
| [2] | 1724 | feature_roots = new QStringList(qmake_feature_paths(prop)); | 
|---|
|  | 1725 | qmakeAddCacheClear(qmakeDeleteCacheClear_QStringList, (void**)&feature_roots); | 
|---|
|  | 1726 | } | 
|---|
|  | 1727 | debug_msg(2, "Looking for feature '%s' in (%s)", file.toLatin1().constData(), | 
|---|
|  | 1728 | feature_roots->join("::").toLatin1().constData()); | 
|---|
|  | 1729 | int start_root = 0; | 
|---|
|  | 1730 | if(parser.from_file) { | 
|---|
|  | 1731 | QFileInfo currFile(parser.file), prfFile(file); | 
|---|
|  | 1732 | if(currFile.fileName() == prfFile.fileName()) { | 
|---|
|  | 1733 | currFile = QFileInfo(currFile.canonicalFilePath()); | 
|---|
|  | 1734 | for(int root = 0; root < feature_roots->size(); ++root) { | 
|---|
|  | 1735 | prfFile = QFileInfo(feature_roots->at(root) + | 
|---|
|  | 1736 | QDir::separator() + file).canonicalFilePath(); | 
|---|
|  | 1737 | if(prfFile == currFile) { | 
|---|
|  | 1738 | start_root = root+1; | 
|---|
|  | 1739 | break; | 
|---|
|  | 1740 | } | 
|---|
|  | 1741 | } | 
|---|
|  | 1742 | } | 
|---|
|  | 1743 | } | 
|---|
|  | 1744 | for(int root = start_root; root < feature_roots->size(); ++root) { | 
|---|
|  | 1745 | QString prf(feature_roots->at(root) + QDir::separator() + file); | 
|---|
|  | 1746 | if(QFile::exists(prf + Option::js_ext)) { | 
|---|
|  | 1747 | format = JSFormat; | 
|---|
|  | 1748 | file = prf + Option::js_ext; | 
|---|
|  | 1749 | break; | 
|---|
|  | 1750 | } else if(QFile::exists(prf)) { | 
|---|
|  | 1751 | format = ProFormat; | 
|---|
|  | 1752 | file = prf; | 
|---|
|  | 1753 | break; | 
|---|
|  | 1754 | } | 
|---|
|  | 1755 | } | 
|---|
|  | 1756 | if(format == UnknownFormat) | 
|---|
|  | 1757 | return IncludeNoExist; | 
|---|
|  | 1758 | if(place["QMAKE_INTERNAL_INCLUDED_FEATURES"].indexOf(file) != -1) | 
|---|
|  | 1759 | return IncludeFeatureAlreadyLoaded; | 
|---|
|  | 1760 | place["QMAKE_INTERNAL_INCLUDED_FEATURES"].append(file); | 
|---|
|  | 1761 | } | 
|---|
|  | 1762 | } | 
|---|
|  | 1763 | if(QDir::isRelativePath(file)) { | 
|---|
|  | 1764 | QStringList include_roots; | 
|---|
|  | 1765 | if(Option::output_dir != qmake_getpwd()) | 
|---|
|  | 1766 | include_roots << qmake_getpwd(); | 
|---|
|  | 1767 | include_roots << Option::output_dir; | 
|---|
| [363] | 1768 | for(int root = 0; root < include_roots.size(); ++root) { | 
|---|
|  | 1769 | QString testName = QDir::toNativeSeparators(include_roots[root]); | 
|---|
|  | 1770 | if (!testName.endsWith(QString(QDir::separator()))) | 
|---|
|  | 1771 | testName += QDir::separator(); | 
|---|
|  | 1772 | testName += file; | 
|---|
| [2] | 1773 | if(QFile::exists(testName)) { | 
|---|
|  | 1774 | file = testName; | 
|---|
|  | 1775 | break; | 
|---|
|  | 1776 | } | 
|---|
|  | 1777 | } | 
|---|
|  | 1778 | } | 
|---|
|  | 1779 | if(format == UnknownFormat) { | 
|---|
|  | 1780 | if(QFile::exists(file)) { | 
|---|
|  | 1781 | if(file.endsWith(Option::js_ext)) | 
|---|
|  | 1782 | format = JSFormat; | 
|---|
|  | 1783 | else | 
|---|
|  | 1784 | format = ProFormat; | 
|---|
|  | 1785 | } else { | 
|---|
|  | 1786 | return IncludeNoExist; | 
|---|
|  | 1787 | } | 
|---|
|  | 1788 | } | 
|---|
|  | 1789 | if(Option::mkfile::do_preprocess) //nice to see this first.. | 
|---|
|  | 1790 | fprintf(stderr, "#switching file %s(%s) - %s:%d\n", (flags & IncludeFlagFeature) ? "load" : "include", | 
|---|
|  | 1791 | file.toLatin1().constData(), | 
|---|
|  | 1792 | parser.file.toLatin1().constData(), parser.line_no); | 
|---|
|  | 1793 | debug_msg(1, "Project Parser: %s'ing file %s.", (flags & IncludeFlagFeature) ? "load" : "include", | 
|---|
|  | 1794 | file.toLatin1().constData()); | 
|---|
|  | 1795 |  | 
|---|
|  | 1796 | QString orig_file = file; | 
|---|
|  | 1797 | int di = file.lastIndexOf(QDir::separator()); | 
|---|
|  | 1798 | QString oldpwd = qmake_getpwd(); | 
|---|
|  | 1799 | if(di != -1) { | 
|---|
|  | 1800 | if(!qmake_setpwd(file.left(file.lastIndexOf(QDir::separator())))) { | 
|---|
|  | 1801 | fprintf(stderr, "Cannot find directory: %s\n", file.left(di).toLatin1().constData()); | 
|---|
|  | 1802 | return IncludeFailure; | 
|---|
|  | 1803 | } | 
|---|
|  | 1804 | file = file.right(file.length() - di - 1); | 
|---|
|  | 1805 | } | 
|---|
|  | 1806 | bool parsed = false; | 
|---|
|  | 1807 | parser_info pi = parser; | 
|---|
|  | 1808 | if(format == JSFormat) { | 
|---|
|  | 1809 | warn_msg(WarnParser, "%s:%d: QtScript support disabled for %s.", | 
|---|
|  | 1810 | pi.file.toLatin1().constData(), pi.line_no, orig_file.toLatin1().constData()); | 
|---|
|  | 1811 | } else { | 
|---|
|  | 1812 | QStack<ScopeBlock> sc = scope_blocks; | 
|---|
|  | 1813 | IteratorBlock *it = iterator; | 
|---|
|  | 1814 | FunctionBlock *fu = function; | 
|---|
|  | 1815 | if(flags & (IncludeFlagNewProject|IncludeFlagNewParser)) { | 
|---|
|  | 1816 | // The "project's variables" are used in other places (eg. export()) so it's not | 
|---|
|  | 1817 | // possible to use "place" everywhere. Instead just set variables and grab them later | 
|---|
|  | 1818 | QMakeProject proj(this, &place); | 
|---|
|  | 1819 | if(flags & IncludeFlagNewParser) { | 
|---|
|  | 1820 | #if 1 | 
|---|
|  | 1821 | if(proj.doProjectInclude("default_pre", IncludeFlagFeature, proj.variables()) == IncludeNoExist) | 
|---|
|  | 1822 | proj.doProjectInclude("default", IncludeFlagFeature, proj.variables()); | 
|---|
|  | 1823 | #endif | 
|---|
|  | 1824 | parsed = proj.read(file, proj.variables()); | 
|---|
|  | 1825 | } else { | 
|---|
|  | 1826 | parsed = proj.read(file); | 
|---|
|  | 1827 | } | 
|---|
|  | 1828 | place = proj.variables(); | 
|---|
|  | 1829 | } else { | 
|---|
|  | 1830 | parsed = read(file, place); | 
|---|
|  | 1831 | } | 
|---|
|  | 1832 | iterator = it; | 
|---|
|  | 1833 | function = fu; | 
|---|
|  | 1834 | scope_blocks = sc; | 
|---|
|  | 1835 | } | 
|---|
|  | 1836 | if(parsed) { | 
|---|
|  | 1837 | if(place["QMAKE_INTERNAL_INCLUDED_FILES"].indexOf(orig_file) == -1) | 
|---|
|  | 1838 | place["QMAKE_INTERNAL_INCLUDED_FILES"].append(orig_file); | 
|---|
|  | 1839 | } else { | 
|---|
|  | 1840 | warn_msg(WarnParser, "%s:%d: Failure to include file %s.", | 
|---|
|  | 1841 | pi.file.toLatin1().constData(), pi.line_no, orig_file.toLatin1().constData()); | 
|---|
|  | 1842 | } | 
|---|
|  | 1843 | parser = pi; | 
|---|
|  | 1844 | qmake_setpwd(oldpwd); | 
|---|
|  | 1845 | if(!parsed) | 
|---|
|  | 1846 | return IncludeParseFailure; | 
|---|
|  | 1847 | return IncludeSuccess; | 
|---|
|  | 1848 | } | 
|---|
|  | 1849 |  | 
|---|
|  | 1850 | QStringList | 
|---|
|  | 1851 | QMakeProject::doProjectExpand(QString func, const QString ¶ms, | 
|---|
|  | 1852 | QMap<QString, QStringList> &place) | 
|---|
|  | 1853 | { | 
|---|
|  | 1854 | return doProjectExpand(func, split_arg_list(params), place); | 
|---|
|  | 1855 | } | 
|---|
|  | 1856 |  | 
|---|
|  | 1857 | QStringList | 
|---|
|  | 1858 | QMakeProject::doProjectExpand(QString func, QStringList args, | 
|---|
|  | 1859 | QMap<QString, QStringList> &place) | 
|---|
|  | 1860 | { | 
|---|
|  | 1861 | QList<QStringList> args_list; | 
|---|
|  | 1862 | for(int i = 0; i < args.size(); ++i) { | 
|---|
|  | 1863 | QStringList arg = split_value_list(args[i]), tmp; | 
|---|
|  | 1864 | for(int i = 0; i < arg.size(); ++i) | 
|---|
|  | 1865 | tmp += doVariableReplaceExpand(arg[i], place);; | 
|---|
|  | 1866 | args_list += tmp; | 
|---|
|  | 1867 | } | 
|---|
|  | 1868 | return doProjectExpand(func, args_list, place); | 
|---|
|  | 1869 | } | 
|---|
|  | 1870 |  | 
|---|
|  | 1871 | QStringList | 
|---|
|  | 1872 | QMakeProject::doProjectExpand(QString func, QList<QStringList> args_list, | 
|---|
|  | 1873 | QMap<QString, QStringList> &place) | 
|---|
|  | 1874 | { | 
|---|
|  | 1875 | func = func.trimmed(); | 
|---|
|  | 1876 | if(replaceFunctions.contains(func)) { | 
|---|
|  | 1877 | FunctionBlock *defined = replaceFunctions[func]; | 
|---|
|  | 1878 | function_blocks.push(defined); | 
|---|
|  | 1879 | QStringList ret; | 
|---|
|  | 1880 | defined->exec(args_list, this, place, ret); | 
|---|
| [405] | 1881 | FunctionBlock *popped = function_blocks.pop(); | 
|---|
|  | 1882 | Q_ASSERT(popped == defined); | 
|---|
|  | 1883 | Q_UNUSED(popped); | 
|---|
| [2] | 1884 | return ret; | 
|---|
|  | 1885 | } | 
|---|
|  | 1886 |  | 
|---|
|  | 1887 | QStringList args; //why don't the builtin functions just use args_list? --Sam | 
|---|
|  | 1888 | for(int i = 0; i < args_list.size(); ++i) | 
|---|
|  | 1889 | args += args_list[i].join(QString(Option::field_sep)); | 
|---|
|  | 1890 |  | 
|---|
|  | 1891 | ExpandFunc func_t = qmake_expandFunctions().value(func.toLower()); | 
|---|
|  | 1892 | debug_msg(1, "Running project expand: %s(%s) [%d]", | 
|---|
|  | 1893 | func.toLatin1().constData(), args.join("::").toLatin1().constData(), func_t); | 
|---|
|  | 1894 |  | 
|---|
|  | 1895 | QStringList ret; | 
|---|
|  | 1896 | switch(func_t) { | 
|---|
|  | 1897 | case E_MEMBER: { | 
|---|
|  | 1898 | if(args.count() < 1 || args.count() > 3) { | 
|---|
|  | 1899 | fprintf(stderr, "%s:%d: member(var, start, end) requires three arguments.\n", | 
|---|
|  | 1900 | parser.file.toLatin1().constData(), parser.line_no); | 
|---|
|  | 1901 | } else { | 
|---|
|  | 1902 | bool ok = true; | 
|---|
|  | 1903 | const QStringList &var = values(args.first(), place); | 
|---|
|  | 1904 | int start = 0, end = 0; | 
|---|
|  | 1905 | if(args.count() >= 2) { | 
|---|
|  | 1906 | QString start_str = args[1]; | 
|---|
|  | 1907 | start = start_str.toInt(&ok); | 
|---|
|  | 1908 | if(!ok) { | 
|---|
|  | 1909 | if(args.count() == 2) { | 
|---|
|  | 1910 | int dotdot = start_str.indexOf(".."); | 
|---|
|  | 1911 | if(dotdot != -1) { | 
|---|
|  | 1912 | start = start_str.left(dotdot).toInt(&ok); | 
|---|
|  | 1913 | if(ok) | 
|---|
|  | 1914 | end = start_str.mid(dotdot+2).toInt(&ok); | 
|---|
|  | 1915 | } | 
|---|
|  | 1916 | } | 
|---|
|  | 1917 | if(!ok) | 
|---|
|  | 1918 | fprintf(stderr, "%s:%d: member() argument 2 (start) '%s' invalid.\n", | 
|---|
|  | 1919 | parser.file.toLatin1().constData(), parser.line_no, | 
|---|
|  | 1920 | start_str.toLatin1().constData()); | 
|---|
|  | 1921 | } else { | 
|---|
|  | 1922 | end = start; | 
|---|
|  | 1923 | if(args.count() == 3) | 
|---|
|  | 1924 | end = args[2].toInt(&ok); | 
|---|
|  | 1925 | if(!ok) | 
|---|
|  | 1926 | fprintf(stderr, "%s:%d: member() argument 3 (end) '%s' invalid.\n", | 
|---|
|  | 1927 | parser.file.toLatin1().constData(), parser.line_no, | 
|---|
|  | 1928 | args[2].toLatin1().constData()); | 
|---|
|  | 1929 | } | 
|---|
|  | 1930 | } | 
|---|
|  | 1931 | if(ok) { | 
|---|
|  | 1932 | if(start < 0) | 
|---|
|  | 1933 | start += var.count(); | 
|---|
|  | 1934 | if(end < 0) | 
|---|
|  | 1935 | end += var.count(); | 
|---|
|  | 1936 | if(start < 0 || start >= var.count() || end < 0 || end >= var.count()) { | 
|---|
|  | 1937 | //nothing | 
|---|
|  | 1938 | } else if(start < end) { | 
|---|
|  | 1939 | for(int i = start; i <= end && (int)var.count() >= i; i++) | 
|---|
|  | 1940 | ret += var[i]; | 
|---|
|  | 1941 | } else { | 
|---|
|  | 1942 | for(int i = start; i >= end && (int)var.count() >= i && i >= 0; i--) | 
|---|
|  | 1943 | ret += var[i]; | 
|---|
|  | 1944 | } | 
|---|
|  | 1945 | } | 
|---|
|  | 1946 | } | 
|---|
|  | 1947 | break; } | 
|---|
|  | 1948 | case E_FIRST: | 
|---|
|  | 1949 | case E_LAST: { | 
|---|
|  | 1950 | if(args.count() != 1) { | 
|---|
|  | 1951 | fprintf(stderr, "%s:%d: %s(var) requires one argument.\n", | 
|---|
|  | 1952 | parser.file.toLatin1().constData(), parser.line_no, func.toLatin1().constData()); | 
|---|
|  | 1953 | } else { | 
|---|
|  | 1954 | const QStringList &var = values(args.first(), place); | 
|---|
|  | 1955 | if(!var.isEmpty()) { | 
|---|
|  | 1956 | if(func_t == E_FIRST) | 
|---|
|  | 1957 | ret = QStringList(var[0]); | 
|---|
|  | 1958 | else | 
|---|
|  | 1959 | ret = QStringList(var[var.size()-1]); | 
|---|
|  | 1960 | } | 
|---|
|  | 1961 | } | 
|---|
|  | 1962 | break; } | 
|---|
|  | 1963 | case E_CAT: { | 
|---|
|  | 1964 | if(args.count() < 1 || args.count() > 2) { | 
|---|
|  | 1965 | fprintf(stderr, "%s:%d: cat(file) requires one argument.\n", | 
|---|
|  | 1966 | parser.file.toLatin1().constData(), parser.line_no); | 
|---|
|  | 1967 | } else { | 
|---|
|  | 1968 | QString file = args[0]; | 
|---|
|  | 1969 | file = Option::fixPathToLocalOS(file); | 
|---|
|  | 1970 |  | 
|---|
|  | 1971 | bool singleLine = true; | 
|---|
|  | 1972 | if(args.count() > 1) | 
|---|
|  | 1973 | singleLine = (args[1].toLower() == "true"); | 
|---|
|  | 1974 |  | 
|---|
|  | 1975 | QFile qfile(file); | 
|---|
|  | 1976 | if(qfile.open(QIODevice::ReadOnly)) { | 
|---|
|  | 1977 | QTextStream stream(&qfile); | 
|---|
|  | 1978 | while(!stream.atEnd()) { | 
|---|
|  | 1979 | ret += split_value_list(stream.readLine().trimmed()); | 
|---|
|  | 1980 | if(!singleLine) | 
|---|
|  | 1981 | ret += "\n"; | 
|---|
|  | 1982 | } | 
|---|
|  | 1983 | qfile.close(); | 
|---|
|  | 1984 | } | 
|---|
|  | 1985 | } | 
|---|
|  | 1986 | break; } | 
|---|
|  | 1987 | case E_FROMFILE: { | 
|---|
|  | 1988 | if(args.count() != 2) { | 
|---|
|  | 1989 | fprintf(stderr, "%s:%d: fromfile(file, variable) requires two arguments.\n", | 
|---|
|  | 1990 | parser.file.toLatin1().constData(), parser.line_no); | 
|---|
|  | 1991 | } else { | 
|---|
|  | 1992 | QString file = args[0], seek_var = args[1]; | 
|---|
|  | 1993 | file = Option::fixPathToLocalOS(file); | 
|---|
|  | 1994 |  | 
|---|
|  | 1995 | QMap<QString, QStringList> tmp; | 
|---|
|  | 1996 | if(doProjectInclude(file, IncludeFlagNewParser, tmp) == IncludeSuccess) { | 
|---|
|  | 1997 | if(tmp.contains("QMAKE_INTERNAL_INCLUDED_FILES")) { | 
|---|
|  | 1998 | QStringList &out = place["QMAKE_INTERNAL_INCLUDED_FILES"]; | 
|---|
|  | 1999 | const QStringList &in = tmp["QMAKE_INTERNAL_INCLUDED_FILES"]; | 
|---|
|  | 2000 | for(int i = 0; i < in.size(); ++i) { | 
|---|
|  | 2001 | if(out.indexOf(in[i]) == -1) | 
|---|
|  | 2002 | out += in[i]; | 
|---|
|  | 2003 | } | 
|---|
|  | 2004 | } | 
|---|
|  | 2005 | ret = tmp[seek_var]; | 
|---|
|  | 2006 | } | 
|---|
|  | 2007 | } | 
|---|
|  | 2008 | break; } | 
|---|
|  | 2009 | case E_EVAL: { | 
|---|
|  | 2010 | if(args.count() < 1 || args.count() > 2) { | 
|---|
|  | 2011 | fprintf(stderr, "%s:%d: eval(variable) requires one argument.\n", | 
|---|
|  | 2012 | parser.file.toLatin1().constData(), parser.line_no); | 
|---|
|  | 2013 |  | 
|---|
|  | 2014 | } else { | 
|---|
|  | 2015 | const QMap<QString, QStringList> *source = &place; | 
|---|
|  | 2016 | if(args.count() == 2) { | 
|---|
|  | 2017 | if(args.at(1) == "Global") { | 
|---|
|  | 2018 | source = &vars; | 
|---|
|  | 2019 | } else if(args.at(1) == "Local") { | 
|---|
|  | 2020 | source = &place; | 
|---|
|  | 2021 | } else { | 
|---|
|  | 2022 | fprintf(stderr, "%s:%d: unexpected source to eval.\n", parser.file.toLatin1().constData(), | 
|---|
|  | 2023 | parser.line_no); | 
|---|
|  | 2024 | } | 
|---|
|  | 2025 | } | 
|---|
|  | 2026 | ret += source->value(args.at(0)); | 
|---|
|  | 2027 | } | 
|---|
|  | 2028 | break; } | 
|---|
|  | 2029 | case E_LIST: { | 
|---|
|  | 2030 | static int x = 0; | 
|---|
|  | 2031 | QString tmp; | 
|---|
|  | 2032 | tmp.sprintf(".QMAKE_INTERNAL_TMP_VAR_%d", x++); | 
|---|
|  | 2033 | ret = QStringList(tmp); | 
|---|
|  | 2034 | QStringList &lst = (*((QMap<QString, QStringList>*)&place))[tmp]; | 
|---|
|  | 2035 | lst.clear(); | 
|---|
|  | 2036 | for(QStringList::ConstIterator arg_it = args.begin(); | 
|---|
|  | 2037 | arg_it != args.end(); ++arg_it) | 
|---|
|  | 2038 | lst += split_value_list((*arg_it)); | 
|---|
|  | 2039 | break; } | 
|---|
|  | 2040 | case E_SPRINTF: { | 
|---|
|  | 2041 | if(args.count() < 1) { | 
|---|
|  | 2042 | fprintf(stderr, "%s:%d: sprintf(format, ...) requires one argument.\n", | 
|---|
|  | 2043 | parser.file.toLatin1().constData(), parser.line_no); | 
|---|
|  | 2044 | } else { | 
|---|
|  | 2045 | QString tmp = args.at(0); | 
|---|
|  | 2046 | for(int i = 1; i < args.count(); ++i) | 
|---|
|  | 2047 | tmp = tmp.arg(args.at(i)); | 
|---|
|  | 2048 | ret = split_value_list(tmp); | 
|---|
|  | 2049 | } | 
|---|
|  | 2050 | break; } | 
|---|
|  | 2051 | case E_JOIN: { | 
|---|
|  | 2052 | if(args.count() < 1 || args.count() > 4) { | 
|---|
|  | 2053 | fprintf(stderr, "%s:%d: join(var, glue, before, after) requires four" | 
|---|
|  | 2054 | "arguments.\n", parser.file.toLatin1().constData(), parser.line_no); | 
|---|
|  | 2055 | } else { | 
|---|
|  | 2056 | QString glue, before, after; | 
|---|
|  | 2057 | if(args.count() >= 2) | 
|---|
|  | 2058 | glue = args[1]; | 
|---|
|  | 2059 | if(args.count() >= 3) | 
|---|
|  | 2060 | before = args[2]; | 
|---|
|  | 2061 | if(args.count() == 4) | 
|---|
|  | 2062 | after = args[3]; | 
|---|
|  | 2063 | const QStringList &var = values(args.first(), place); | 
|---|
|  | 2064 | if(!var.isEmpty()) | 
|---|
|  | 2065 | ret = split_value_list(before + var.join(glue) + after); | 
|---|
|  | 2066 | } | 
|---|
|  | 2067 | break; } | 
|---|
|  | 2068 | case E_SPLIT: { | 
|---|
|  | 2069 | if(args.count() < 1 || args.count() > 2) { | 
|---|
|  | 2070 | fprintf(stderr, "%s:%d split(var, sep) requires one or two arguments\n", | 
|---|
|  | 2071 | parser.file.toLatin1().constData(), parser.line_no); | 
|---|
|  | 2072 | } else { | 
|---|
|  | 2073 | QString sep = QString(Option::field_sep); | 
|---|
|  | 2074 | if(args.count() >= 2) | 
|---|
|  | 2075 | sep = args[1]; | 
|---|
|  | 2076 | QStringList var = values(args.first(), place); | 
|---|
|  | 2077 | for(QStringList::ConstIterator vit = var.begin(); vit != var.end(); ++vit) { | 
|---|
|  | 2078 | QStringList lst = (*vit).split(sep); | 
|---|
|  | 2079 | for(QStringList::ConstIterator spltit = lst.begin(); spltit != lst.end(); ++spltit) | 
|---|
|  | 2080 | ret += (*spltit); | 
|---|
|  | 2081 | } | 
|---|
|  | 2082 | } | 
|---|
|  | 2083 | break; } | 
|---|
|  | 2084 | case E_BASENAME: | 
|---|
|  | 2085 | case E_DIRNAME: | 
|---|
|  | 2086 | case E_SECTION: { | 
|---|
|  | 2087 | bool regexp = false; | 
|---|
|  | 2088 | QString sep, var; | 
|---|
|  | 2089 | int beg=0, end=-1; | 
|---|
|  | 2090 | if(func_t == E_SECTION) { | 
|---|
|  | 2091 | if(args.count() != 3 && args.count() != 4) { | 
|---|
|  | 2092 | fprintf(stderr, "%s:%d section(var, sep, begin, end) requires three argument\n", | 
|---|
|  | 2093 | parser.file.toLatin1().constData(), parser.line_no); | 
|---|
|  | 2094 | } else { | 
|---|
|  | 2095 | var = args[0]; | 
|---|
|  | 2096 | sep = args[1]; | 
|---|
|  | 2097 | beg = args[2].toInt(); | 
|---|
|  | 2098 | if(args.count() == 4) | 
|---|
|  | 2099 | end = args[3].toInt(); | 
|---|
|  | 2100 | } | 
|---|
|  | 2101 | } else { | 
|---|
|  | 2102 | if(args.count() != 1) { | 
|---|
|  | 2103 | fprintf(stderr, "%s:%d %s(var) requires one argument.\n", | 
|---|
|  | 2104 | parser.file.toLatin1().constData(), parser.line_no, func.toLatin1().constData()); | 
|---|
|  | 2105 | } else { | 
|---|
|  | 2106 | var = args[0]; | 
|---|
|  | 2107 | regexp = true; | 
|---|
|  | 2108 | sep = "[" + QRegExp::escape(Option::dir_sep) + "/]"; | 
|---|
|  | 2109 | if(func_t == E_DIRNAME) | 
|---|
|  | 2110 | end = -2; | 
|---|
|  | 2111 | else | 
|---|
|  | 2112 | beg = -1; | 
|---|
|  | 2113 | } | 
|---|
|  | 2114 | } | 
|---|
|  | 2115 | if(!var.isNull()) { | 
|---|
|  | 2116 | const QStringList &l = values(var, place); | 
|---|
|  | 2117 | for(QStringList::ConstIterator it = l.begin(); it != l.end(); ++it) { | 
|---|
|  | 2118 | QString separator = sep; | 
|---|
|  | 2119 | if(regexp) | 
|---|
|  | 2120 | ret += (*it).section(QRegExp(separator), beg, end); | 
|---|
|  | 2121 | else | 
|---|
|  | 2122 | ret += (*it).section(separator, beg, end); | 
|---|
|  | 2123 | } | 
|---|
|  | 2124 | } | 
|---|
|  | 2125 | break; } | 
|---|
|  | 2126 | case E_FIND: { | 
|---|
|  | 2127 | if(args.count() != 2) { | 
|---|
|  | 2128 | fprintf(stderr, "%s:%d find(var, str) requires two arguments\n", | 
|---|
|  | 2129 | parser.file.toLatin1().constData(), parser.line_no); | 
|---|
|  | 2130 | } else { | 
|---|
|  | 2131 | QRegExp regx(args[1]); | 
|---|
|  | 2132 | const QStringList &var = values(args.first(), place); | 
|---|
|  | 2133 | for(QStringList::ConstIterator vit = var.begin(); | 
|---|
|  | 2134 | vit != var.end(); ++vit) { | 
|---|
|  | 2135 | if(regx.indexIn(*vit) != -1) | 
|---|
|  | 2136 | ret += (*vit); | 
|---|
|  | 2137 | } | 
|---|
|  | 2138 | } | 
|---|
|  | 2139 | break;  } | 
|---|
|  | 2140 | case E_SYSTEM: { | 
|---|
|  | 2141 | if(args.count() < 1 || args.count() > 2) { | 
|---|
|  | 2142 | fprintf(stderr, "%s:%d system(execut) requires one argument.\n", | 
|---|
|  | 2143 | parser.file.toLatin1().constData(), parser.line_no); | 
|---|
|  | 2144 | } else { | 
|---|
|  | 2145 | QMakeProjectEnv env(place); | 
|---|
|  | 2146 | char buff[256]; | 
|---|
|  | 2147 | bool singleLine = true; | 
|---|
|  | 2148 | if(args.count() > 1) | 
|---|
|  | 2149 | singleLine = (args[1].toLower() == "true"); | 
|---|
|  | 2150 | QString output; | 
|---|
| [561] | 2151 | FILE *proc = QT_POPEN(args[0].toLatin1(), "r"); | 
|---|
| [2] | 2152 | while(proc && !feof(proc)) { | 
|---|
|  | 2153 | int read_in = int(fread(buff, 1, 255, proc)); | 
|---|
|  | 2154 | if(!read_in) | 
|---|
|  | 2155 | break; | 
|---|
|  | 2156 | for(int i = 0; i < read_in; i++) { | 
|---|
|  | 2157 | if((singleLine && buff[i] == '\n') || buff[i] == '\t') | 
|---|
|  | 2158 | buff[i] = ' '; | 
|---|
|  | 2159 | } | 
|---|
|  | 2160 | buff[read_in] = '\0'; | 
|---|
|  | 2161 | output += buff; | 
|---|
|  | 2162 | } | 
|---|
|  | 2163 | ret += split_value_list(output); | 
|---|
|  | 2164 | if(proc) | 
|---|
|  | 2165 | QT_PCLOSE(proc); | 
|---|
|  | 2166 | } | 
|---|
|  | 2167 | break; } | 
|---|
|  | 2168 | case E_UNIQUE: { | 
|---|
|  | 2169 | if(args.count() != 1) { | 
|---|
|  | 2170 | fprintf(stderr, "%s:%d unique(var) requires one argument.\n", | 
|---|
|  | 2171 | parser.file.toLatin1().constData(), parser.line_no); | 
|---|
|  | 2172 | } else { | 
|---|
|  | 2173 | const QStringList &var = values(args.first(), place); | 
|---|
|  | 2174 | for(int i = 0; i < var.count(); i++) { | 
|---|
|  | 2175 | if(!ret.contains(var[i])) | 
|---|
|  | 2176 | ret.append(var[i]); | 
|---|
|  | 2177 | } | 
|---|
|  | 2178 | } | 
|---|
|  | 2179 | break; } | 
|---|
|  | 2180 | case E_QUOTE: | 
|---|
|  | 2181 | ret = args; | 
|---|
|  | 2182 | break; | 
|---|
|  | 2183 | case E_ESCAPE_EXPAND: { | 
|---|
|  | 2184 | for(int i = 0; i < args.size(); ++i) { | 
|---|
|  | 2185 | QChar *i_data = args[i].data(); | 
|---|
|  | 2186 | int i_len = args[i].length(); | 
|---|
|  | 2187 | for(int x = 0; x < i_len; ++x) { | 
|---|
|  | 2188 | if(*(i_data+x) == '\\' && x < i_len-1) { | 
|---|
|  | 2189 | if(*(i_data+x+1) == '\\') { | 
|---|
|  | 2190 | ++x; | 
|---|
|  | 2191 | } else { | 
|---|
|  | 2192 | struct { | 
|---|
|  | 2193 | char in, out; | 
|---|
|  | 2194 | } mapped_quotes[] = { | 
|---|
|  | 2195 | { 'n', '\n' }, | 
|---|
|  | 2196 | { 't', '\t' }, | 
|---|
|  | 2197 | { 'r', '\r' }, | 
|---|
|  | 2198 | { 0, 0 } | 
|---|
|  | 2199 | }; | 
|---|
|  | 2200 | for(int i = 0; mapped_quotes[i].in; ++i) { | 
|---|
|  | 2201 | if(*(i_data+x+1) == mapped_quotes[i].in) { | 
|---|
|  | 2202 | *(i_data+x) = mapped_quotes[i].out; | 
|---|
|  | 2203 | if(x < i_len-2) | 
|---|
|  | 2204 | memmove(i_data+x+1, i_data+x+2, (i_len-x-2)*sizeof(QChar)); | 
|---|
|  | 2205 | --i_len; | 
|---|
|  | 2206 | break; | 
|---|
|  | 2207 | } | 
|---|
|  | 2208 | } | 
|---|
|  | 2209 | } | 
|---|
|  | 2210 | } | 
|---|
|  | 2211 | } | 
|---|
|  | 2212 | ret.append(QString(i_data, i_len)); | 
|---|
|  | 2213 | } | 
|---|
|  | 2214 | break; } | 
|---|
|  | 2215 | case E_RE_ESCAPE: { | 
|---|
|  | 2216 | for(int i = 0; i < args.size(); ++i) | 
|---|
|  | 2217 | ret += QRegExp::escape(args[i]); | 
|---|
|  | 2218 | break; } | 
|---|
|  | 2219 | case E_UPPER: | 
|---|
|  | 2220 | case E_LOWER: { | 
|---|
|  | 2221 | for(int i = 0; i < args.size(); ++i) { | 
|---|
|  | 2222 | if(func_t == E_UPPER) | 
|---|
|  | 2223 | ret += args[i].toUpper(); | 
|---|
|  | 2224 | else | 
|---|
|  | 2225 | ret += args[i].toLower(); | 
|---|
|  | 2226 | } | 
|---|
|  | 2227 | break; } | 
|---|
|  | 2228 | case E_FILES: { | 
|---|
|  | 2229 | if(args.count() != 1 && args.count() != 2) { | 
|---|
|  | 2230 | fprintf(stderr, "%s:%d files(pattern) requires one argument.\n", | 
|---|
|  | 2231 | parser.file.toLatin1().constData(), parser.line_no); | 
|---|
|  | 2232 | } else { | 
|---|
|  | 2233 | bool recursive = false; | 
|---|
|  | 2234 | if(args.count() == 2) | 
|---|
|  | 2235 | recursive = (args[1].toLower() == "true" || args[1].toInt()); | 
|---|
|  | 2236 | QStringList dirs; | 
|---|
|  | 2237 | QString r = Option::fixPathToLocalOS(args[0]); | 
|---|
|  | 2238 | int slash = r.lastIndexOf(QDir::separator()); | 
|---|
|  | 2239 | if(slash != -1) { | 
|---|
|  | 2240 | dirs.append(r.left(slash)); | 
|---|
|  | 2241 | r = r.mid(slash+1); | 
|---|
|  | 2242 | } else { | 
|---|
|  | 2243 | dirs.append(""); | 
|---|
|  | 2244 | } | 
|---|
|  | 2245 |  | 
|---|
|  | 2246 | const QRegExp regex(r, Qt::CaseSensitive, QRegExp::Wildcard); | 
|---|
|  | 2247 | for(int d = 0; d < dirs.count(); d++) { | 
|---|
|  | 2248 | QString dir = dirs[d]; | 
|---|
|  | 2249 | if(!dir.isEmpty() && !dir.endsWith(Option::dir_sep)) | 
|---|
|  | 2250 | dir += "/"; | 
|---|
|  | 2251 |  | 
|---|
|  | 2252 | QDir qdir(dir); | 
|---|
|  | 2253 | for(int i = 0; i < (int)qdir.count(); ++i) { | 
|---|
|  | 2254 | if(qdir[i] == "." || qdir[i] == "..") | 
|---|
|  | 2255 | continue; | 
|---|
|  | 2256 | QString fname = dir + qdir[i]; | 
|---|
|  | 2257 | if(QFileInfo(fname).isDir()) { | 
|---|
|  | 2258 | if(recursive) | 
|---|
|  | 2259 | dirs.append(fname); | 
|---|
|  | 2260 | } | 
|---|
|  | 2261 | if(regex.exactMatch(qdir[i])) | 
|---|
|  | 2262 | ret += fname; | 
|---|
|  | 2263 | } | 
|---|
|  | 2264 | } | 
|---|
|  | 2265 | } | 
|---|
|  | 2266 | break; } | 
|---|
|  | 2267 | case E_PROMPT: { | 
|---|
|  | 2268 | if(args.count() != 1) { | 
|---|
|  | 2269 | fprintf(stderr, "%s:%d prompt(question) requires one argument.\n", | 
|---|
|  | 2270 | parser.file.toLatin1().constData(), parser.line_no); | 
|---|
|  | 2271 | } else if(projectFile() == "-") { | 
|---|
|  | 2272 | fprintf(stderr, "%s:%d prompt(question) cannot be used when '-o -' is used.\n", | 
|---|
|  | 2273 | parser.file.toLatin1().constData(), parser.line_no); | 
|---|
|  | 2274 | } else { | 
|---|
|  | 2275 | QString msg = fixEnvVariables(args.first()); | 
|---|
|  | 2276 | if(!msg.endsWith("?")) | 
|---|
|  | 2277 | msg += "?"; | 
|---|
|  | 2278 | fprintf(stderr, "Project %s: %s ", func.toUpper().toLatin1().constData(), | 
|---|
|  | 2279 | msg.toLatin1().constData()); | 
|---|
|  | 2280 |  | 
|---|
|  | 2281 | QFile qfile; | 
|---|
|  | 2282 | if(qfile.open(stdin, QIODevice::ReadOnly)) { | 
|---|
|  | 2283 | QTextStream t(&qfile); | 
|---|
|  | 2284 | ret = split_value_list(t.readLine()); | 
|---|
|  | 2285 | } | 
|---|
|  | 2286 | } | 
|---|
|  | 2287 | break; } | 
|---|
|  | 2288 | case E_REPLACE: { | 
|---|
|  | 2289 | if(args.count() != 3 ) { | 
|---|
|  | 2290 | fprintf(stderr, "%s:%d replace(var, before, after) requires three arguments\n", | 
|---|
|  | 2291 | parser.file.toLatin1().constData(), parser.line_no); | 
|---|
|  | 2292 | } else { | 
|---|
|  | 2293 | const QRegExp before( args[1] ); | 
|---|
|  | 2294 | const QString after( args[2] ); | 
|---|
|  | 2295 | QStringList var = values(args.first(), place); | 
|---|
|  | 2296 | for(QStringList::Iterator it = var.begin(); it != var.end(); ++it) | 
|---|
|  | 2297 | ret += it->replace(before, after); | 
|---|
|  | 2298 | } | 
|---|
|  | 2299 | break; } | 
|---|
| [561] | 2300 | case E_SIZE: { | 
|---|
|  | 2301 | if(args.count() != 1) { | 
|---|
|  | 2302 | fprintf(stderr, "%s:%d: size(var) requires one argument.\n", | 
|---|
|  | 2303 | parser.file.toLatin1().constData(), parser.line_no); | 
|---|
|  | 2304 | } else { | 
|---|
|  | 2305 | //QString target = args[0]; | 
|---|
|  | 2306 | int size = values(args[0]).size(); | 
|---|
|  | 2307 | ret += QString::number(size); | 
|---|
|  | 2308 | } | 
|---|
|  | 2309 | break; } | 
|---|
| [2] | 2310 | default: { | 
|---|
|  | 2311 | fprintf(stderr, "%s:%d: Unknown replace function: %s\n", | 
|---|
|  | 2312 | parser.file.toLatin1().constData(), parser.line_no, | 
|---|
|  | 2313 | func.toLatin1().constData()); | 
|---|
|  | 2314 | break; } | 
|---|
|  | 2315 | } | 
|---|
|  | 2316 | return ret; | 
|---|
|  | 2317 | } | 
|---|
|  | 2318 |  | 
|---|
|  | 2319 | bool | 
|---|
|  | 2320 | QMakeProject::doProjectTest(QString func, QStringList args, QMap<QString, QStringList> &place) | 
|---|
|  | 2321 | { | 
|---|
|  | 2322 | QList<QStringList> args_list; | 
|---|
|  | 2323 | for(int i = 0; i < args.size(); ++i) { | 
|---|
|  | 2324 | QStringList arg = split_value_list(args[i]), tmp; | 
|---|
|  | 2325 | for(int i = 0; i < arg.size(); ++i) | 
|---|
|  | 2326 | tmp += doVariableReplaceExpand(arg[i], place); | 
|---|
|  | 2327 | args_list += tmp; | 
|---|
|  | 2328 | } | 
|---|
|  | 2329 | return doProjectTest(func, args_list, place); | 
|---|
|  | 2330 | } | 
|---|
|  | 2331 |  | 
|---|
|  | 2332 | bool | 
|---|
|  | 2333 | QMakeProject::doProjectTest(QString func, QList<QStringList> args_list, QMap<QString, QStringList> &place) | 
|---|
|  | 2334 | { | 
|---|
|  | 2335 | func = func.trimmed(); | 
|---|
|  | 2336 |  | 
|---|
|  | 2337 | if(testFunctions.contains(func)) { | 
|---|
|  | 2338 | FunctionBlock *defined = testFunctions[func]; | 
|---|
|  | 2339 | QStringList ret; | 
|---|
|  | 2340 | function_blocks.push(defined); | 
|---|
|  | 2341 | defined->exec(args_list, this, place, ret); | 
|---|
| [405] | 2342 | FunctionBlock *popped = function_blocks.pop(); | 
|---|
|  | 2343 | Q_ASSERT(popped == defined); | 
|---|
|  | 2344 | Q_UNUSED(popped); | 
|---|
| [2] | 2345 |  | 
|---|
|  | 2346 | if(ret.isEmpty()) { | 
|---|
|  | 2347 | return true; | 
|---|
|  | 2348 | } else { | 
|---|
|  | 2349 | if(ret.first() == "true") { | 
|---|
|  | 2350 | return true; | 
|---|
|  | 2351 | } else if(ret.first() == "false") { | 
|---|
|  | 2352 | return false; | 
|---|
|  | 2353 | } else { | 
|---|
|  | 2354 | bool ok; | 
|---|
|  | 2355 | int val = ret.first().toInt(&ok); | 
|---|
|  | 2356 | if(ok) | 
|---|
|  | 2357 | return val; | 
|---|
|  | 2358 | fprintf(stderr, "%s:%d Unexpected return value from test %s [%s].\n", | 
|---|
|  | 2359 | parser.file.toLatin1().constData(), | 
|---|
|  | 2360 | parser.line_no, func.toLatin1().constData(), | 
|---|
|  | 2361 | ret.join("::").toLatin1().constData()); | 
|---|
|  | 2362 | } | 
|---|
|  | 2363 | return false; | 
|---|
|  | 2364 | } | 
|---|
|  | 2365 | return false; | 
|---|
|  | 2366 | } | 
|---|
|  | 2367 |  | 
|---|
|  | 2368 | QStringList args; //why don't the builtin functions just use args_list? --Sam | 
|---|
|  | 2369 | for(int i = 0; i < args_list.size(); ++i) | 
|---|
|  | 2370 | args += args_list[i].join(QString(Option::field_sep)); | 
|---|
|  | 2371 |  | 
|---|
|  | 2372 | TestFunc func_t = qmake_testFunctions().value(func); | 
|---|
|  | 2373 | debug_msg(1, "Running project test: %s(%s) [%d]", | 
|---|
|  | 2374 | func.toLatin1().constData(), args.join("::").toLatin1().constData(), func_t); | 
|---|
|  | 2375 |  | 
|---|
|  | 2376 | switch(func_t) { | 
|---|
|  | 2377 | case T_REQUIRES: | 
|---|
|  | 2378 | return doProjectCheckReqs(args, place); | 
|---|
|  | 2379 | case T_LESSTHAN: | 
|---|
|  | 2380 | case T_GREATERTHAN: { | 
|---|
|  | 2381 | if(args.count() != 2) { | 
|---|
|  | 2382 | fprintf(stderr, "%s:%d: %s(variable, value) requires two arguments.\n", parser.file.toLatin1().constData(), | 
|---|
|  | 2383 | parser.line_no, func.toLatin1().constData()); | 
|---|
|  | 2384 | return false; | 
|---|
|  | 2385 | } | 
|---|
|  | 2386 | QString rhs(args[1]), lhs(values(args[0], place).join(QString(Option::field_sep))); | 
|---|
|  | 2387 | bool ok; | 
|---|
|  | 2388 | int rhs_int = rhs.toInt(&ok); | 
|---|
|  | 2389 | if(ok) { // do integer compare | 
|---|
|  | 2390 | int lhs_int = lhs.toInt(&ok); | 
|---|
|  | 2391 | if(ok) { | 
|---|
| [561] | 2392 | if(func_t == T_GREATERTHAN) | 
|---|
| [2] | 2393 | return lhs_int > rhs_int; | 
|---|
|  | 2394 | return lhs_int < rhs_int; | 
|---|
|  | 2395 | } | 
|---|
|  | 2396 | } | 
|---|
|  | 2397 | if(func_t == T_GREATERTHAN) | 
|---|
|  | 2398 | return lhs > rhs; | 
|---|
|  | 2399 | return lhs < rhs; } | 
|---|
|  | 2400 | case T_IF: { | 
|---|
|  | 2401 | if(args.count() != 1) { | 
|---|
|  | 2402 | fprintf(stderr, "%s:%d: if(condition) requires one argument.\n", parser.file.toLatin1().constData(), | 
|---|
|  | 2403 | parser.line_no); | 
|---|
|  | 2404 | return false; | 
|---|
|  | 2405 | } | 
|---|
|  | 2406 | const QString cond = args.first(); | 
|---|
|  | 2407 | const QChar *d = cond.unicode(); | 
|---|
|  | 2408 | QChar quote = 0; | 
|---|
|  | 2409 | bool ret = true, or_op = false; | 
|---|
|  | 2410 | QString test; | 
|---|
|  | 2411 | for(int d_off = 0, parens = 0, d_len = cond.size(); d_off < d_len; ++d_off) { | 
|---|
|  | 2412 | if(!quote.isNull()) { | 
|---|
|  | 2413 | if(*(d+d_off) == quote) | 
|---|
|  | 2414 | quote = QChar(); | 
|---|
|  | 2415 | } else if(*(d+d_off) == '(') { | 
|---|
|  | 2416 | ++parens; | 
|---|
|  | 2417 | } else if(*(d+d_off) == ')') { | 
|---|
|  | 2418 | --parens; | 
|---|
|  | 2419 | } else if(*(d+d_off) == '"' /*|| *(d+d_off) == '\''*/) { | 
|---|
|  | 2420 | quote = *(d+d_off); | 
|---|
|  | 2421 | } | 
|---|
|  | 2422 | if(!parens && quote.isNull() && (*(d+d_off) == QLatin1Char(':') || *(d+d_off) == QLatin1Char('|') || d_off == d_len-1)) { | 
|---|
|  | 2423 | if(d_off == d_len-1) | 
|---|
|  | 2424 | test += *(d+d_off); | 
|---|
|  | 2425 | if(!test.isEmpty()) { | 
|---|
|  | 2426 | const bool success = doProjectTest(test, place); | 
|---|
|  | 2427 | test = ""; | 
|---|
|  | 2428 | if(or_op) | 
|---|
|  | 2429 | ret = ret || success; | 
|---|
|  | 2430 | else | 
|---|
|  | 2431 | ret = ret && success; | 
|---|
|  | 2432 | } | 
|---|
|  | 2433 | if(*(d+d_off) == QLatin1Char(':')) { | 
|---|
|  | 2434 | or_op = false; | 
|---|
|  | 2435 | } else if(*(d+d_off) == QLatin1Char('|')) { | 
|---|
|  | 2436 | or_op = true; | 
|---|
|  | 2437 | } | 
|---|
|  | 2438 | } else { | 
|---|
|  | 2439 | test += *(d+d_off); | 
|---|
|  | 2440 | } | 
|---|
|  | 2441 | } | 
|---|
|  | 2442 | return ret; } | 
|---|
|  | 2443 | case T_EQUALS: | 
|---|
|  | 2444 | if(args.count() != 2) { | 
|---|
|  | 2445 | fprintf(stderr, "%s:%d: %s(variable, value) requires two arguments.\n", parser.file.toLatin1().constData(), | 
|---|
|  | 2446 | parser.line_no, func.toLatin1().constData()); | 
|---|
|  | 2447 | return false; | 
|---|
|  | 2448 | } | 
|---|
|  | 2449 | return values(args[0], place).join(QString(Option::field_sep)) == args[1]; | 
|---|
|  | 2450 | case T_EXISTS: { | 
|---|
|  | 2451 | if(args.count() != 1) { | 
|---|
|  | 2452 | fprintf(stderr, "%s:%d: exists(file) requires one argument.\n", parser.file.toLatin1().constData(), | 
|---|
|  | 2453 | parser.line_no); | 
|---|
|  | 2454 | return false; | 
|---|
|  | 2455 | } | 
|---|
|  | 2456 | QString file = args.first(); | 
|---|
|  | 2457 | file = Option::fixPathToLocalOS(file); | 
|---|
|  | 2458 |  | 
|---|
|  | 2459 | if(QFile::exists(file)) | 
|---|
|  | 2460 | return true; | 
|---|
|  | 2461 | //regular expression I guess | 
|---|
|  | 2462 | QString dirstr = qmake_getpwd(); | 
|---|
|  | 2463 | int slsh = file.lastIndexOf(Option::dir_sep); | 
|---|
|  | 2464 | if(slsh != -1) { | 
|---|
|  | 2465 | dirstr = file.left(slsh+1); | 
|---|
|  | 2466 | file = file.right(file.length() - slsh - 1); | 
|---|
|  | 2467 | } | 
|---|
|  | 2468 | return QDir(dirstr).entryList(QStringList(file)).count(); } | 
|---|
|  | 2469 | case T_EXPORT: | 
|---|
|  | 2470 | if(args.count() != 1) { | 
|---|
|  | 2471 | fprintf(stderr, "%s:%d: export(variable) requires one argument.\n", parser.file.toLatin1().constData(), | 
|---|
|  | 2472 | parser.line_no); | 
|---|
|  | 2473 | return false; | 
|---|
|  | 2474 | } | 
|---|
|  | 2475 | for(int i = 0; i < function_blocks.size(); ++i) { | 
|---|
|  | 2476 | FunctionBlock *f = function_blocks.at(i); | 
|---|
|  | 2477 | f->vars[args[0]] = values(args[0], place); | 
|---|
|  | 2478 | if(!i && f->calling_place) | 
|---|
|  | 2479 | (*f->calling_place)[args[0]] = values(args[0], place); | 
|---|
|  | 2480 | } | 
|---|
|  | 2481 | return true; | 
|---|
|  | 2482 | case T_CLEAR: | 
|---|
|  | 2483 | if(args.count() != 1) { | 
|---|
|  | 2484 | fprintf(stderr, "%s:%d: clear(variable) requires one argument.\n", parser.file.toLatin1().constData(), | 
|---|
|  | 2485 | parser.line_no); | 
|---|
|  | 2486 | return false; | 
|---|
|  | 2487 | } | 
|---|
|  | 2488 | if(!place.contains(args[0])) | 
|---|
|  | 2489 | return false; | 
|---|
|  | 2490 | place[args[0]].clear(); | 
|---|
|  | 2491 | return true; | 
|---|
|  | 2492 | case T_UNSET: | 
|---|
|  | 2493 | if(args.count() != 1) { | 
|---|
|  | 2494 | fprintf(stderr, "%s:%d: unset(variable) requires one argument.\n", parser.file.toLatin1().constData(), | 
|---|
|  | 2495 | parser.line_no); | 
|---|
|  | 2496 | return false; | 
|---|
|  | 2497 | } | 
|---|
|  | 2498 | if(!place.contains(args[0])) | 
|---|
|  | 2499 | return false; | 
|---|
|  | 2500 | place.remove(args[0]); | 
|---|
|  | 2501 | return true; | 
|---|
|  | 2502 | case T_EVAL: { | 
|---|
|  | 2503 | if(args.count() < 1 && 0) { | 
|---|
|  | 2504 | fprintf(stderr, "%s:%d: eval(project) requires one argument.\n", parser.file.toLatin1().constData(), | 
|---|
|  | 2505 | parser.line_no); | 
|---|
|  | 2506 | return false; | 
|---|
|  | 2507 | } | 
|---|
|  | 2508 | QString project = args.join(" "); | 
|---|
|  | 2509 | parser_info pi = parser; | 
|---|
|  | 2510 | parser.from_file = false; | 
|---|
|  | 2511 | parser.file = "(eval)"; | 
|---|
|  | 2512 | parser.line_no = 0; | 
|---|
|  | 2513 | QTextStream t(&project, QIODevice::ReadOnly); | 
|---|
|  | 2514 | bool ret = read(t, place); | 
|---|
|  | 2515 | parser = pi; | 
|---|
|  | 2516 | return ret; } | 
|---|
|  | 2517 | case T_CONFIG: { | 
|---|
|  | 2518 | if(args.count() < 1 || args.count() > 2) { | 
|---|
|  | 2519 | fprintf(stderr, "%s:%d: CONFIG(config) requires one argument.\n", parser.file.toLatin1().constData(), | 
|---|
|  | 2520 | parser.line_no); | 
|---|
|  | 2521 | return false; | 
|---|
|  | 2522 | } | 
|---|
|  | 2523 | if(args.count() == 1) | 
|---|
|  | 2524 | return isActiveConfig(args[0]); | 
|---|
|  | 2525 | const QStringList mutuals = args[1].split('|'); | 
|---|
|  | 2526 | const QStringList &configs = values("CONFIG", place); | 
|---|
|  | 2527 | for(int i = configs.size()-1; i >= 0; i--) { | 
|---|
|  | 2528 | for(int mut = 0; mut < mutuals.count(); mut++) { | 
|---|
|  | 2529 | if(configs[i] == mutuals[mut].trimmed()) | 
|---|
|  | 2530 | return (configs[i] == args[0]); | 
|---|
|  | 2531 | } | 
|---|
|  | 2532 | } | 
|---|
|  | 2533 | return false; } | 
|---|
|  | 2534 | case T_SYSTEM: { | 
|---|
|  | 2535 | bool setup_env = true; | 
|---|
|  | 2536 | if(args.count() < 1 || args.count() > 2) { | 
|---|
|  | 2537 | fprintf(stderr, "%s:%d: system(exec) requires one argument.\n", parser.file.toLatin1().constData(), | 
|---|
|  | 2538 | parser.line_no); | 
|---|
|  | 2539 | return false; | 
|---|
|  | 2540 | } | 
|---|
|  | 2541 | if(args.count() == 2) { | 
|---|
|  | 2542 | const QString sarg = args[1]; | 
|---|
|  | 2543 | setup_env = (sarg.toLower() == "true" || sarg.toInt()); | 
|---|
|  | 2544 | } | 
|---|
|  | 2545 | QMakeProjectEnv env; | 
|---|
|  | 2546 | if(setup_env) | 
|---|
|  | 2547 | env.execute(place); | 
|---|
|  | 2548 | bool ret = system(args[0].toLatin1().constData()) == 0; | 
|---|
|  | 2549 | return ret; } | 
|---|
|  | 2550 | case T_RETURN: | 
|---|
|  | 2551 | if(function_blocks.isEmpty()) { | 
|---|
|  | 2552 | fprintf(stderr, "%s:%d unexpected return()\n", | 
|---|
|  | 2553 | parser.file.toLatin1().constData(), parser.line_no); | 
|---|
|  | 2554 | } else { | 
|---|
|  | 2555 | FunctionBlock *f = function_blocks.top(); | 
|---|
|  | 2556 | f->cause_return = true; | 
|---|
|  | 2557 | if(args_list.count() >= 1) | 
|---|
|  | 2558 | f->return_value += args_list[0]; | 
|---|
|  | 2559 | } | 
|---|
|  | 2560 | return true; | 
|---|
|  | 2561 | case T_BREAK: | 
|---|
|  | 2562 | if(iterator) | 
|---|
|  | 2563 | iterator->cause_break = true; | 
|---|
|  | 2564 | else if(!scope_blocks.isEmpty()) | 
|---|
|  | 2565 | scope_blocks.top().ignore = true; | 
|---|
|  | 2566 | else | 
|---|
|  | 2567 | fprintf(stderr, "%s:%d unexpected break()\n", | 
|---|
|  | 2568 | parser.file.toLatin1().constData(), parser.line_no); | 
|---|
|  | 2569 | return true; | 
|---|
|  | 2570 | case T_NEXT: | 
|---|
|  | 2571 | if(iterator) | 
|---|
|  | 2572 | iterator->cause_next = true; | 
|---|
|  | 2573 | else | 
|---|
|  | 2574 | fprintf(stderr, "%s:%d unexpected next()\n", | 
|---|
|  | 2575 | parser.file.toLatin1().constData(), parser.line_no); | 
|---|
|  | 2576 | return true; | 
|---|
|  | 2577 | case T_DEFINED: | 
|---|
|  | 2578 | if(args.count() < 1 || args.count() > 2) { | 
|---|
|  | 2579 | fprintf(stderr, "%s:%d: defined(function) requires one argument.\n", | 
|---|
|  | 2580 | parser.file.toLatin1().constData(), parser.line_no); | 
|---|
|  | 2581 | } else { | 
|---|
|  | 2582 | if(args.count() > 1) { | 
|---|
|  | 2583 | if(args[1] == "test") | 
|---|
|  | 2584 | return testFunctions.contains(args[0]); | 
|---|
|  | 2585 | else if(args[1] == "replace") | 
|---|
|  | 2586 | return replaceFunctions.contains(args[0]); | 
|---|
|  | 2587 | fprintf(stderr, "%s:%d: defined(function, type): unexpected type [%s].\n", | 
|---|
|  | 2588 | parser.file.toLatin1().constData(), parser.line_no, | 
|---|
|  | 2589 | args[1].toLatin1().constData()); | 
|---|
|  | 2590 | } else { | 
|---|
|  | 2591 | if(replaceFunctions.contains(args[0]) || testFunctions.contains(args[0])) | 
|---|
|  | 2592 | return true; | 
|---|
|  | 2593 | } | 
|---|
|  | 2594 | } | 
|---|
|  | 2595 | return false; | 
|---|
|  | 2596 | case T_CONTAINS: { | 
|---|
|  | 2597 | if(args.count() < 2 || args.count() > 3) { | 
|---|
|  | 2598 | fprintf(stderr, "%s:%d: contains(var, val) requires at lesat 2 arguments.\n", | 
|---|
|  | 2599 | parser.file.toLatin1().constData(), parser.line_no); | 
|---|
|  | 2600 | return false; | 
|---|
|  | 2601 | } | 
|---|
|  | 2602 | QRegExp regx(args[1]); | 
|---|
|  | 2603 | const QStringList &l = values(args[0], place); | 
|---|
|  | 2604 | if(args.count() == 2) { | 
|---|
|  | 2605 | for(int i = 0; i < l.size(); ++i) { | 
|---|
|  | 2606 | const QString val = l[i]; | 
|---|
|  | 2607 | if(regx.exactMatch(val) || val == args[1]) | 
|---|
|  | 2608 | return true; | 
|---|
|  | 2609 | } | 
|---|
|  | 2610 | } else { | 
|---|
|  | 2611 | const QStringList mutuals = args[2].split('|'); | 
|---|
|  | 2612 | for(int i = l.size()-1; i >= 0; i--) { | 
|---|
|  | 2613 | const QString val = l[i]; | 
|---|
|  | 2614 | for(int mut = 0; mut < mutuals.count(); mut++) { | 
|---|
|  | 2615 | if(val == mutuals[mut].trimmed()) | 
|---|
|  | 2616 | return (regx.exactMatch(val) || val == args[1]); | 
|---|
|  | 2617 | } | 
|---|
|  | 2618 | } | 
|---|
|  | 2619 | } | 
|---|
|  | 2620 | return false; } | 
|---|
|  | 2621 | case T_INFILE: { | 
|---|
|  | 2622 | if(args.count() < 2 || args.count() > 3) { | 
|---|
|  | 2623 | fprintf(stderr, "%s:%d: infile(file, var, val) requires at least 2 arguments.\n", | 
|---|
|  | 2624 | parser.file.toLatin1().constData(), parser.line_no); | 
|---|
|  | 2625 | return false; | 
|---|
|  | 2626 | } | 
|---|
|  | 2627 |  | 
|---|
|  | 2628 | bool ret = false; | 
|---|
|  | 2629 | QMap<QString, QStringList> tmp; | 
|---|
|  | 2630 | if(doProjectInclude(Option::fixPathToLocalOS(args[0]), IncludeFlagNewParser, tmp) == IncludeSuccess) { | 
|---|
|  | 2631 | if(tmp.contains("QMAKE_INTERNAL_INCLUDED_FILES")) { | 
|---|
|  | 2632 | QStringList &out = place["QMAKE_INTERNAL_INCLUDED_FILES"]; | 
|---|
|  | 2633 | const QStringList &in = tmp["QMAKE_INTERNAL_INCLUDED_FILES"]; | 
|---|
|  | 2634 | for(int i = 0; i < in.size(); ++i) { | 
|---|
|  | 2635 | if(out.indexOf(in[i]) == -1) | 
|---|
|  | 2636 | out += in[i]; | 
|---|
|  | 2637 | } | 
|---|
|  | 2638 | } | 
|---|
|  | 2639 | if(args.count() == 2) { | 
|---|
|  | 2640 | ret = tmp.contains(args[1]); | 
|---|
|  | 2641 | } else { | 
|---|
|  | 2642 | QRegExp regx(args[2]); | 
|---|
|  | 2643 | const QStringList &l = tmp[args[1]]; | 
|---|
|  | 2644 | for(QStringList::ConstIterator it = l.begin(); it != l.end(); ++it) { | 
|---|
|  | 2645 | if(regx.exactMatch((*it)) || (*it) == args[2]) { | 
|---|
|  | 2646 | ret = true; | 
|---|
|  | 2647 | break; | 
|---|
|  | 2648 | } | 
|---|
|  | 2649 | } | 
|---|
|  | 2650 | } | 
|---|
|  | 2651 | } | 
|---|
|  | 2652 | return ret; } | 
|---|
|  | 2653 | case T_COUNT: | 
|---|
|  | 2654 | if(args.count() != 2 && args.count() != 3) { | 
|---|
|  | 2655 | fprintf(stderr, "%s:%d: count(var, count) requires two arguments.\n", parser.file.toLatin1().constData(), | 
|---|
|  | 2656 | parser.line_no); | 
|---|
|  | 2657 | return false; | 
|---|
|  | 2658 | } | 
|---|
|  | 2659 | if(args.count() == 3) { | 
|---|
|  | 2660 | QString comp = args[2]; | 
|---|
|  | 2661 | if(comp == ">" || comp == "greaterThan") | 
|---|
|  | 2662 | return values(args[0], place).count() > args[1].toInt(); | 
|---|
|  | 2663 | if(comp == ">=") | 
|---|
|  | 2664 | return values(args[0], place).count() >= args[1].toInt(); | 
|---|
|  | 2665 | if(comp == "<" || comp == "lessThan") | 
|---|
|  | 2666 | return values(args[0], place).count() < args[1].toInt(); | 
|---|
|  | 2667 | if(comp == "<=") | 
|---|
|  | 2668 | return values(args[0], place).count() <= args[1].toInt(); | 
|---|
|  | 2669 | if(comp == "equals" || comp == "isEqual" || comp == "=" || comp == "==") | 
|---|
|  | 2670 | return values(args[0], place).count() == args[1].toInt(); | 
|---|
|  | 2671 | fprintf(stderr, "%s:%d: unexpected modifier to count(%s)\n", parser.file.toLatin1().constData(), | 
|---|
|  | 2672 | parser.line_no, comp.toLatin1().constData()); | 
|---|
|  | 2673 | return false; | 
|---|
|  | 2674 | } | 
|---|
|  | 2675 | return values(args[0], place).count() == args[1].toInt(); | 
|---|
|  | 2676 | case T_ISEMPTY: | 
|---|
|  | 2677 | if(args.count() != 1) { | 
|---|
|  | 2678 | fprintf(stderr, "%s:%d: isEmpty(var) requires one argument.\n", parser.file.toLatin1().constData(), | 
|---|
|  | 2679 | parser.line_no); | 
|---|
|  | 2680 | return false; | 
|---|
|  | 2681 | } | 
|---|
|  | 2682 | return values(args[0], place).isEmpty(); | 
|---|
|  | 2683 | case T_INCLUDE: | 
|---|
|  | 2684 | case T_LOAD: { | 
|---|
|  | 2685 | QString parseInto; | 
|---|
|  | 2686 | const bool include_statement = (func_t == T_INCLUDE); | 
|---|
| [561] | 2687 | bool ignore_error = false; | 
|---|
|  | 2688 | if(args.count() >= 2) { | 
|---|
| [2] | 2689 | if(func_t == T_INCLUDE) { | 
|---|
|  | 2690 | parseInto = args[1]; | 
|---|
| [561] | 2691 | if (args.count() == 3){ | 
|---|
|  | 2692 | QString sarg = args[2]; | 
|---|
|  | 2693 | if (sarg.toLower() == "true" || sarg.toInt()) | 
|---|
|  | 2694 | ignore_error = true; | 
|---|
|  | 2695 | } | 
|---|
| [2] | 2696 | } else { | 
|---|
|  | 2697 | QString sarg = args[1]; | 
|---|
|  | 2698 | ignore_error = (sarg.toLower() == "true" || sarg.toInt()); | 
|---|
|  | 2699 | } | 
|---|
|  | 2700 | } else if(args.count() != 1) { | 
|---|
|  | 2701 | QString func_desc = "load(feature)"; | 
|---|
|  | 2702 | if(include_statement) | 
|---|
|  | 2703 | func_desc = "include(file)"; | 
|---|
|  | 2704 | fprintf(stderr, "%s:%d: %s requires one argument.\n", parser.file.toLatin1().constData(), | 
|---|
|  | 2705 | parser.line_no, func_desc.toLatin1().constData()); | 
|---|
|  | 2706 | return false; | 
|---|
|  | 2707 | } | 
|---|
|  | 2708 | QString file = args.first(); | 
|---|
|  | 2709 | file = Option::fixPathToLocalOS(file); | 
|---|
|  | 2710 | uchar flags = IncludeFlagNone; | 
|---|
|  | 2711 | if(!include_statement) | 
|---|
|  | 2712 | flags |= IncludeFlagFeature; | 
|---|
|  | 2713 | IncludeStatus stat = IncludeFailure; | 
|---|
|  | 2714 | if(!parseInto.isEmpty()) { | 
|---|
|  | 2715 | QMap<QString, QStringList> symbols; | 
|---|
|  | 2716 | stat = doProjectInclude(file, flags|IncludeFlagNewProject, symbols); | 
|---|
|  | 2717 | if(stat == IncludeSuccess) { | 
|---|
|  | 2718 | QMap<QString, QStringList> out_place; | 
|---|
|  | 2719 | for(QMap<QString, QStringList>::ConstIterator it = place.begin(); it != place.end(); ++it) { | 
|---|
|  | 2720 | const QString var = it.key(); | 
|---|
|  | 2721 | if(var != parseInto && !var.startsWith(parseInto + ".")) | 
|---|
|  | 2722 | out_place.insert(var, it.value()); | 
|---|
|  | 2723 | } | 
|---|
|  | 2724 | for(QMap<QString, QStringList>::ConstIterator it = symbols.begin(); it != symbols.end(); ++it) { | 
|---|
|  | 2725 | const QString var = it.key(); | 
|---|
|  | 2726 | if(!var.startsWith(".")) | 
|---|
|  | 2727 | out_place.insert(parseInto + "." + it.key(), it.value()); | 
|---|
|  | 2728 | } | 
|---|
|  | 2729 | place = out_place; | 
|---|
|  | 2730 | } | 
|---|
|  | 2731 | } else { | 
|---|
|  | 2732 | stat = doProjectInclude(file, flags, place); | 
|---|
|  | 2733 | } | 
|---|
|  | 2734 | if(stat == IncludeFeatureAlreadyLoaded) { | 
|---|
|  | 2735 | warn_msg(WarnParser, "%s:%d: Duplicate of loaded feature %s", | 
|---|
|  | 2736 | parser.file.toLatin1().constData(), parser.line_no, file.toLatin1().constData()); | 
|---|
| [561] | 2737 | } else if(stat == IncludeNoExist && !ignore_error) { | 
|---|
|  | 2738 | warn_msg(WarnAll, "%s:%d: Unable to find file for inclusion %s", | 
|---|
| [2] | 2739 | parser.file.toLatin1().constData(), parser.line_no, file.toLatin1().constData()); | 
|---|
|  | 2740 | return false; | 
|---|
|  | 2741 | } else if(stat >= IncludeFailure) { | 
|---|
|  | 2742 | if(!ignore_error) { | 
|---|
|  | 2743 | printf("Project LOAD(): Feature %s cannot be found.\n", file.toLatin1().constData()); | 
|---|
|  | 2744 | if (!ignore_error) | 
|---|
|  | 2745 | #if defined(QT_BUILD_QMAKE_LIBRARY) | 
|---|
|  | 2746 | return false; | 
|---|
|  | 2747 | #else | 
|---|
|  | 2748 | exit(3); | 
|---|
|  | 2749 | #endif | 
|---|
|  | 2750 | } | 
|---|
|  | 2751 | return false; | 
|---|
|  | 2752 | } | 
|---|
|  | 2753 | return true; } | 
|---|
|  | 2754 | case T_DEBUG: { | 
|---|
|  | 2755 | if(args.count() != 2) { | 
|---|
|  | 2756 | fprintf(stderr, "%s:%d: debug(level, message) requires one argument.\n", parser.file.toLatin1().constData(), | 
|---|
|  | 2757 | parser.line_no); | 
|---|
|  | 2758 | return false; | 
|---|
|  | 2759 | } | 
|---|
|  | 2760 | QString msg = fixEnvVariables(args[1]); | 
|---|
|  | 2761 | debug_msg(args[0].toInt(), "Project DEBUG: %s", msg.toLatin1().constData()); | 
|---|
|  | 2762 | return true; } | 
|---|
|  | 2763 | case T_ERROR: | 
|---|
|  | 2764 | case T_MESSAGE: | 
|---|
|  | 2765 | case T_WARNING: { | 
|---|
|  | 2766 | if(args.count() != 1) { | 
|---|
|  | 2767 | fprintf(stderr, "%s:%d: %s(message) requires one argument.\n", parser.file.toLatin1().constData(), | 
|---|
|  | 2768 | parser.line_no, func.toLatin1().constData()); | 
|---|
|  | 2769 | return false; | 
|---|
|  | 2770 | } | 
|---|
|  | 2771 | QString msg = fixEnvVariables(args.first()); | 
|---|
|  | 2772 | fprintf(stderr, "Project %s: %s\n", func.toUpper().toLatin1().constData(), msg.toLatin1().constData()); | 
|---|
|  | 2773 | if(func == "error") | 
|---|
|  | 2774 | #if defined(QT_BUILD_QMAKE_LIBRARY) | 
|---|
|  | 2775 | return false; | 
|---|
|  | 2776 | #else | 
|---|
|  | 2777 | exit(2); | 
|---|
|  | 2778 | #endif | 
|---|
|  | 2779 | return true; } | 
|---|
|  | 2780 | default: | 
|---|
|  | 2781 | fprintf(stderr, "%s:%d: Unknown test function: %s\n", parser.file.toLatin1().constData(), parser.line_no, | 
|---|
|  | 2782 | func.toLatin1().constData()); | 
|---|
|  | 2783 | } | 
|---|
|  | 2784 | return false; | 
|---|
|  | 2785 | } | 
|---|
|  | 2786 |  | 
|---|
|  | 2787 | bool | 
|---|
|  | 2788 | QMakeProject::doProjectCheckReqs(const QStringList &deps, QMap<QString, QStringList> &place) | 
|---|
|  | 2789 | { | 
|---|
|  | 2790 | bool ret = false; | 
|---|
|  | 2791 | for(QStringList::ConstIterator it = deps.begin(); it != deps.end(); ++it) { | 
|---|
|  | 2792 | bool test = doProjectTest((*it), place); | 
|---|
|  | 2793 | if(!test) { | 
|---|
|  | 2794 | debug_msg(1, "Project Parser: %s:%d Failed test: REQUIRES = %s", | 
|---|
|  | 2795 | parser.file.toLatin1().constData(), parser.line_no, | 
|---|
|  | 2796 | (*it).toLatin1().constData()); | 
|---|
|  | 2797 | place["QMAKE_FAILED_REQUIREMENTS"].append((*it)); | 
|---|
|  | 2798 | ret = false; | 
|---|
|  | 2799 | } | 
|---|
|  | 2800 | } | 
|---|
|  | 2801 | return ret; | 
|---|
|  | 2802 | } | 
|---|
|  | 2803 |  | 
|---|
|  | 2804 | bool | 
|---|
|  | 2805 | QMakeProject::test(const QString &v) | 
|---|
|  | 2806 | { | 
|---|
|  | 2807 | QMap<QString, QStringList> tmp = vars; | 
|---|
|  | 2808 | return doProjectTest(v, tmp); | 
|---|
|  | 2809 | } | 
|---|
|  | 2810 |  | 
|---|
|  | 2811 | bool | 
|---|
|  | 2812 | QMakeProject::test(const QString &func, const QList<QStringList> &args) | 
|---|
|  | 2813 | { | 
|---|
|  | 2814 | QMap<QString, QStringList> tmp = vars; | 
|---|
|  | 2815 | return doProjectTest(func, args, tmp); | 
|---|
|  | 2816 | } | 
|---|
|  | 2817 |  | 
|---|
|  | 2818 | QStringList | 
|---|
|  | 2819 | QMakeProject::expand(const QString &str) | 
|---|
|  | 2820 | { | 
|---|
|  | 2821 | bool ok; | 
|---|
|  | 2822 | QMap<QString, QStringList> tmp = vars; | 
|---|
|  | 2823 | const QStringList ret = doVariableReplaceExpand(str, tmp, &ok); | 
|---|
|  | 2824 | if(ok) | 
|---|
|  | 2825 | return ret; | 
|---|
|  | 2826 | return QStringList(); | 
|---|
|  | 2827 | } | 
|---|
|  | 2828 |  | 
|---|
|  | 2829 | QStringList | 
|---|
|  | 2830 | QMakeProject::expand(const QString &func, const QList<QStringList> &args) | 
|---|
|  | 2831 | { | 
|---|
|  | 2832 | QMap<QString, QStringList> tmp = vars; | 
|---|
|  | 2833 | return doProjectExpand(func, args, tmp); | 
|---|
|  | 2834 | } | 
|---|
|  | 2835 |  | 
|---|
|  | 2836 | bool | 
|---|
|  | 2837 | QMakeProject::doVariableReplace(QString &str, QMap<QString, QStringList> &place) | 
|---|
|  | 2838 | { | 
|---|
|  | 2839 | bool ret; | 
|---|
|  | 2840 | str = doVariableReplaceExpand(str, place, &ret).join(QString(Option::field_sep)); | 
|---|
|  | 2841 | return ret; | 
|---|
|  | 2842 | } | 
|---|
|  | 2843 |  | 
|---|
|  | 2844 | QStringList | 
|---|
|  | 2845 | QMakeProject::doVariableReplaceExpand(const QString &str, QMap<QString, QStringList> &place, bool *ok) | 
|---|
|  | 2846 | { | 
|---|
|  | 2847 | QStringList ret; | 
|---|
|  | 2848 | if(ok) | 
|---|
|  | 2849 | *ok = true; | 
|---|
|  | 2850 | if(str.isEmpty()) | 
|---|
|  | 2851 | return ret; | 
|---|
|  | 2852 |  | 
|---|
|  | 2853 | const ushort LSQUARE = '['; | 
|---|
|  | 2854 | const ushort RSQUARE = ']'; | 
|---|
|  | 2855 | const ushort LCURLY = '{'; | 
|---|
|  | 2856 | const ushort RCURLY = '}'; | 
|---|
|  | 2857 | const ushort LPAREN = '('; | 
|---|
|  | 2858 | const ushort RPAREN = ')'; | 
|---|
|  | 2859 | const ushort DOLLAR = '$'; | 
|---|
|  | 2860 | const ushort SLASH = '\\'; | 
|---|
|  | 2861 | const ushort UNDERSCORE = '_'; | 
|---|
|  | 2862 | const ushort DOT = '.'; | 
|---|
|  | 2863 | const ushort SPACE = ' '; | 
|---|
|  | 2864 | const ushort TAB = '\t'; | 
|---|
|  | 2865 | const ushort SINGLEQUOTE = '\''; | 
|---|
|  | 2866 | const ushort DOUBLEQUOTE = '"'; | 
|---|
|  | 2867 |  | 
|---|
|  | 2868 | ushort unicode, quote = 0; | 
|---|
|  | 2869 | const QChar *str_data = str.data(); | 
|---|
|  | 2870 | const int str_len = str.length(); | 
|---|
|  | 2871 |  | 
|---|
|  | 2872 | ushort term; | 
|---|
|  | 2873 | QString var, args; | 
|---|
|  | 2874 |  | 
|---|
|  | 2875 | int replaced = 0; | 
|---|
|  | 2876 | QString current; | 
|---|
|  | 2877 | for(int i = 0; i < str_len; ++i) { | 
|---|
|  | 2878 | unicode = str_data[i].unicode(); | 
|---|
|  | 2879 | const int start_var = i; | 
|---|
|  | 2880 | if(unicode == DOLLAR && str_len > i+2) { | 
|---|
|  | 2881 | unicode = str_data[++i].unicode(); | 
|---|
|  | 2882 | if(unicode == DOLLAR) { | 
|---|
|  | 2883 | term = 0; | 
|---|
|  | 2884 | var.clear(); | 
|---|
|  | 2885 | args.clear(); | 
|---|
|  | 2886 | enum { VAR, ENVIRON, FUNCTION, PROPERTY } var_type = VAR; | 
|---|
|  | 2887 | unicode = str_data[++i].unicode(); | 
|---|
|  | 2888 | if(unicode == LSQUARE) { | 
|---|
|  | 2889 | unicode = str_data[++i].unicode(); | 
|---|
|  | 2890 | term = RSQUARE; | 
|---|
|  | 2891 | var_type = PROPERTY; | 
|---|
|  | 2892 | } else if(unicode == LCURLY) { | 
|---|
|  | 2893 | unicode = str_data[++i].unicode(); | 
|---|
|  | 2894 | var_type = VAR; | 
|---|
|  | 2895 | term = RCURLY; | 
|---|
|  | 2896 | } else if(unicode == LPAREN) { | 
|---|
|  | 2897 | unicode = str_data[++i].unicode(); | 
|---|
|  | 2898 | var_type = ENVIRON; | 
|---|
|  | 2899 | term = RPAREN; | 
|---|
|  | 2900 | } | 
|---|
|  | 2901 | while(1) { | 
|---|
|  | 2902 | if(!(unicode & (0xFF<<8)) && | 
|---|
|  | 2903 | unicode != DOT && unicode != UNDERSCORE && | 
|---|
|  | 2904 | //unicode != SINGLEQUOTE && unicode != DOUBLEQUOTE && | 
|---|
|  | 2905 | (unicode < 'a' || unicode > 'z') && (unicode < 'A' || unicode > 'Z') && | 
|---|
|  | 2906 | (unicode < '0' || unicode > '9')) | 
|---|
|  | 2907 | break; | 
|---|
|  | 2908 | var.append(QChar(unicode)); | 
|---|
|  | 2909 | if(++i == str_len) | 
|---|
|  | 2910 | break; | 
|---|
|  | 2911 | unicode = str_data[i].unicode(); | 
|---|
|  | 2912 | // at this point, i points to either the 'term' or 'next' character (which is in unicode) | 
|---|
|  | 2913 | } | 
|---|
|  | 2914 | if(var_type == VAR && unicode == LPAREN) { | 
|---|
|  | 2915 | var_type = FUNCTION; | 
|---|
|  | 2916 | int depth = 0; | 
|---|
|  | 2917 | while(1) { | 
|---|
|  | 2918 | if(++i == str_len) | 
|---|
|  | 2919 | break; | 
|---|
|  | 2920 | unicode = str_data[i].unicode(); | 
|---|
|  | 2921 | if(unicode == LPAREN) { | 
|---|
|  | 2922 | depth++; | 
|---|
|  | 2923 | } else if(unicode == RPAREN) { | 
|---|
|  | 2924 | if(!depth) | 
|---|
|  | 2925 | break; | 
|---|
|  | 2926 | --depth; | 
|---|
|  | 2927 | } | 
|---|
|  | 2928 | args.append(QChar(unicode)); | 
|---|
|  | 2929 | } | 
|---|
|  | 2930 | if(++i < str_len) | 
|---|
|  | 2931 | unicode = str_data[i].unicode(); | 
|---|
|  | 2932 | else | 
|---|
|  | 2933 | unicode = 0; | 
|---|
|  | 2934 | // at this point i is pointing to the 'next' character (which is in unicode) | 
|---|
|  | 2935 | // this might actually be a term character since you can do $${func()} | 
|---|
|  | 2936 | } | 
|---|
|  | 2937 | if(term) { | 
|---|
|  | 2938 | if(unicode != term) { | 
|---|
|  | 2939 | qmake_error_msg("Missing " + QString(term) + " terminator [found " + (unicode?QString(unicode):QString("end-of-line")) + "]"); | 
|---|
|  | 2940 | if(ok) | 
|---|
|  | 2941 | *ok = false; | 
|---|
|  | 2942 | return QStringList(); | 
|---|
|  | 2943 | } | 
|---|
|  | 2944 | } else { | 
|---|
|  | 2945 | // move the 'cursor' back to the last char of the thing we were looking at | 
|---|
|  | 2946 | --i; | 
|---|
|  | 2947 | } | 
|---|
|  | 2948 | // since i never points to the 'next' character, there is no reason for this to be set | 
|---|
|  | 2949 | unicode = 0; | 
|---|
|  | 2950 |  | 
|---|
|  | 2951 | QStringList replacement; | 
|---|
|  | 2952 | if(var_type == ENVIRON) { | 
|---|
|  | 2953 | replacement = split_value_list(QString::fromLocal8Bit(qgetenv(var.toLatin1().constData()))); | 
|---|
|  | 2954 | } else if(var_type == PROPERTY) { | 
|---|
|  | 2955 | if(prop) | 
|---|
|  | 2956 | replacement = split_value_list(prop->value(var)); | 
|---|
|  | 2957 | } else if(var_type == FUNCTION) { | 
|---|
|  | 2958 | replacement = doProjectExpand(var, args, place); | 
|---|
|  | 2959 | } else if(var_type == VAR) { | 
|---|
|  | 2960 | replacement = values(var, place); | 
|---|
|  | 2961 | } | 
|---|
|  | 2962 | if(!(replaced++) && start_var) | 
|---|
|  | 2963 | current = str.left(start_var); | 
|---|
|  | 2964 | if(!replacement.isEmpty()) { | 
|---|
|  | 2965 | if(quote) { | 
|---|
|  | 2966 | current += replacement.join(QString(Option::field_sep)); | 
|---|
|  | 2967 | } else { | 
|---|
|  | 2968 | current += replacement.takeFirst(); | 
|---|
|  | 2969 | if(!replacement.isEmpty()) { | 
|---|
|  | 2970 | if(!current.isEmpty()) | 
|---|
|  | 2971 | ret.append(current); | 
|---|
|  | 2972 | current = replacement.takeLast(); | 
|---|
|  | 2973 | if(!replacement.isEmpty()) | 
|---|
|  | 2974 | ret += replacement; | 
|---|
|  | 2975 | } | 
|---|
|  | 2976 | } | 
|---|
|  | 2977 | } | 
|---|
|  | 2978 | debug_msg(2, "Project Parser [var replace]: %s -> %s", | 
|---|
|  | 2979 | str.toLatin1().constData(), var.toLatin1().constData(), | 
|---|
|  | 2980 | replacement.join("::").toLatin1().constData()); | 
|---|
|  | 2981 | } else { | 
|---|
|  | 2982 | if(replaced) | 
|---|
|  | 2983 | current.append("$"); | 
|---|
|  | 2984 | } | 
|---|
|  | 2985 | } | 
|---|
|  | 2986 | if(quote && unicode == quote) { | 
|---|
|  | 2987 | unicode = 0; | 
|---|
|  | 2988 | quote = 0; | 
|---|
|  | 2989 | } else if(unicode == SLASH) { | 
|---|
|  | 2990 | bool escape = false; | 
|---|
|  | 2991 | const char *symbols = "[]{}()$\\'\""; | 
|---|
|  | 2992 | for(const char *s = symbols; *s; ++s) { | 
|---|
|  | 2993 | if(str_data[i+1].unicode() == (ushort)*s) { | 
|---|
|  | 2994 | i++; | 
|---|
|  | 2995 | escape = true; | 
|---|
|  | 2996 | if(!(replaced++)) | 
|---|
|  | 2997 | current = str.left(start_var); | 
|---|
|  | 2998 | current.append(str.at(i)); | 
|---|
|  | 2999 | break; | 
|---|
|  | 3000 | } | 
|---|
|  | 3001 | } | 
|---|
|  | 3002 | if(escape || !replaced) | 
|---|
|  | 3003 | unicode =0; | 
|---|
|  | 3004 | } else if(!quote && (unicode == SINGLEQUOTE || unicode == DOUBLEQUOTE)) { | 
|---|
|  | 3005 | quote = unicode; | 
|---|
|  | 3006 | unicode = 0; | 
|---|
|  | 3007 | if(!(replaced++) && i) | 
|---|
|  | 3008 | current = str.left(i); | 
|---|
|  | 3009 | } else if(!quote && (unicode == SPACE || unicode == TAB)) { | 
|---|
|  | 3010 | unicode = 0; | 
|---|
|  | 3011 | if(!current.isEmpty()) { | 
|---|
|  | 3012 | ret.append(current); | 
|---|
|  | 3013 | current.clear(); | 
|---|
|  | 3014 | } | 
|---|
|  | 3015 | } | 
|---|
|  | 3016 | if(replaced && unicode) | 
|---|
|  | 3017 | current.append(QChar(unicode)); | 
|---|
|  | 3018 | } | 
|---|
|  | 3019 | if(!replaced) | 
|---|
|  | 3020 | ret = QStringList(str); | 
|---|
|  | 3021 | else if(!current.isEmpty()) | 
|---|
|  | 3022 | ret.append(current); | 
|---|
|  | 3023 | //qDebug() << "REPLACE" << str << ret; | 
|---|
|  | 3024 | return ret; | 
|---|
|  | 3025 | } | 
|---|
|  | 3026 |  | 
|---|
|  | 3027 | QStringList &QMakeProject::values(const QString &_var, QMap<QString, QStringList> &place) | 
|---|
|  | 3028 | { | 
|---|
|  | 3029 | QString var = varMap(_var); | 
|---|
|  | 3030 | if(var == QLatin1String("LITERAL_WHITESPACE")) { //a real space in a token) | 
|---|
|  | 3031 | var = ".BUILTIN." + var; | 
|---|
|  | 3032 | place[var] = QStringList(QLatin1String("\t")); | 
|---|
|  | 3033 | } else if(var == QLatin1String("LITERAL_DOLLAR")) { //a real $ | 
|---|
|  | 3034 | var = ".BUILTIN." + var; | 
|---|
|  | 3035 | place[var] = QStringList(QLatin1String("$")); | 
|---|
|  | 3036 | } else if(var == QLatin1String("LITERAL_HASH")) { //a real # | 
|---|
|  | 3037 | var = ".BUILTIN." + var; | 
|---|
|  | 3038 | place[var] = QStringList("#"); | 
|---|
|  | 3039 | } else if(var == QLatin1String("OUT_PWD")) { //the out going dir | 
|---|
|  | 3040 | var = ".BUILTIN." + var; | 
|---|
|  | 3041 | place[var] =  QStringList(Option::output_dir); | 
|---|
|  | 3042 | } else if(var == QLatin1String("PWD") ||  //current working dir (of _FILE_) | 
|---|
|  | 3043 | var == QLatin1String("IN_PWD")) { | 
|---|
|  | 3044 | var = ".BUILTIN." + var; | 
|---|
|  | 3045 | place[var] = QStringList(qmake_getpwd()); | 
|---|
|  | 3046 | } else if(var == QLatin1String("DIR_SEPARATOR")) { | 
|---|
|  | 3047 | var = ".BUILTIN." + var; | 
|---|
|  | 3048 | place[var] =  QStringList(Option::dir_sep); | 
|---|
|  | 3049 | } else if(var == QLatin1String("DIRLIST_SEPARATOR")) { | 
|---|
|  | 3050 | var = ".BUILTIN." + var; | 
|---|
|  | 3051 | place[var] = QStringList(Option::dirlist_sep); | 
|---|
|  | 3052 | } else if(var == QLatin1String("_LINE_")) { //parser line number | 
|---|
|  | 3053 | var = ".BUILTIN." + var; | 
|---|
|  | 3054 | place[var] = QStringList(QString::number(parser.line_no)); | 
|---|
|  | 3055 | } else if(var == QLatin1String("_FILE_")) { //parser file | 
|---|
|  | 3056 | var = ".BUILTIN." + var; | 
|---|
|  | 3057 | place[var] = QStringList(parser.file); | 
|---|
|  | 3058 | } else if(var == QLatin1String("_DATE_")) { //current date/time | 
|---|
|  | 3059 | var = ".BUILTIN." + var; | 
|---|
|  | 3060 | place[var] = QStringList(QDateTime::currentDateTime().toString()); | 
|---|
|  | 3061 | } else if(var == QLatin1String("_PRO_FILE_")) { | 
|---|
|  | 3062 | var = ".BUILTIN." + var; | 
|---|
|  | 3063 | place[var] = QStringList(pfile); | 
|---|
|  | 3064 | } else if(var == QLatin1String("_PRO_FILE_PWD_")) { | 
|---|
|  | 3065 | var = ".BUILTIN." + var; | 
|---|
|  | 3066 | place[var] =  QStringList(QFileInfo(pfile).absolutePath()); | 
|---|
|  | 3067 | } else if(var == QLatin1String("_QMAKE_CACHE_")) { | 
|---|
|  | 3068 | var = ".BUILTIN." + var; | 
|---|
|  | 3069 | if(Option::mkfile::do_cache) | 
|---|
|  | 3070 | place[var] = QStringList(Option::mkfile::cachefile); | 
|---|
|  | 3071 | } else if(var == QLatin1String("TEMPLATE")) { | 
|---|
|  | 3072 | if(!Option::user_template.isEmpty()) { | 
|---|
|  | 3073 | var = ".BUILTIN.USER." + var; | 
|---|
|  | 3074 | place[var] =  QStringList(Option::user_template); | 
|---|
|  | 3075 | } else if(!place[var].isEmpty()) { | 
|---|
|  | 3076 | QString orig_template = place["TEMPLATE"].first(), real_template; | 
|---|
|  | 3077 | if(!Option::user_template_prefix.isEmpty() && !orig_template.startsWith(Option::user_template_prefix)) | 
|---|
|  | 3078 | real_template = Option::user_template_prefix + orig_template; | 
|---|
|  | 3079 | if(real_template.endsWith(".t")) | 
|---|
|  | 3080 | real_template = real_template.left(real_template.length()-2); | 
|---|
|  | 3081 | if(!real_template.isEmpty()) { | 
|---|
|  | 3082 | var = ".BUILTIN." + var; | 
|---|
|  | 3083 | place[var] = QStringList(real_template); | 
|---|
|  | 3084 | } | 
|---|
|  | 3085 | } else { | 
|---|
|  | 3086 | var = ".BUILTIN." + var; | 
|---|
|  | 3087 | place[var] =  QStringList("app"); | 
|---|
|  | 3088 | } | 
|---|
|  | 3089 | } else if(var.startsWith(QLatin1String("QMAKE_HOST."))) { | 
|---|
|  | 3090 | QString ret, type = var.mid(11); | 
|---|
|  | 3091 | #if defined(Q_OS_WIN32) | 
|---|
|  | 3092 | if(type == "os") { | 
|---|
|  | 3093 | ret = "Windows"; | 
|---|
|  | 3094 | } else if(type == "name") { | 
|---|
|  | 3095 | DWORD name_length = 1024; | 
|---|
| [561] | 3096 | wchar_t name[1024]; | 
|---|
|  | 3097 | if (GetComputerName(name, &name_length)) | 
|---|
|  | 3098 | ret = QString::fromWCharArray(name); | 
|---|
| [2] | 3099 | } else if(type == "version" || type == "version_string") { | 
|---|
|  | 3100 | QSysInfo::WinVersion ver = QSysInfo::WindowsVersion; | 
|---|
|  | 3101 | if(type == "version") | 
|---|
|  | 3102 | ret = QString::number(ver); | 
|---|
|  | 3103 | else if(ver == QSysInfo::WV_Me) | 
|---|
|  | 3104 | ret = "WinMe"; | 
|---|
|  | 3105 | else if(ver == QSysInfo::WV_95) | 
|---|
|  | 3106 | ret = "Win95"; | 
|---|
|  | 3107 | else if(ver == QSysInfo::WV_98) | 
|---|
|  | 3108 | ret = "Win98"; | 
|---|
|  | 3109 | else if(ver == QSysInfo::WV_NT) | 
|---|
|  | 3110 | ret = "WinNT"; | 
|---|
|  | 3111 | else if(ver == QSysInfo::WV_2000) | 
|---|
|  | 3112 | ret = "Win2000"; | 
|---|
|  | 3113 | else if(ver == QSysInfo::WV_2000) | 
|---|
|  | 3114 | ret = "Win2003"; | 
|---|
|  | 3115 | else if(ver == QSysInfo::WV_XP) | 
|---|
|  | 3116 | ret = "WinXP"; | 
|---|
|  | 3117 | else if(ver == QSysInfo::WV_VISTA) | 
|---|
|  | 3118 | ret = "WinVista"; | 
|---|
|  | 3119 | else | 
|---|
|  | 3120 | ret = "Unknown"; | 
|---|
|  | 3121 | } else if(type == "arch") { | 
|---|
|  | 3122 | SYSTEM_INFO info; | 
|---|
|  | 3123 | GetSystemInfo(&info); | 
|---|
|  | 3124 | switch(info.wProcessorArchitecture) { | 
|---|
|  | 3125 | #ifdef PROCESSOR_ARCHITECTURE_AMD64 | 
|---|
|  | 3126 | case PROCESSOR_ARCHITECTURE_AMD64: | 
|---|
|  | 3127 | ret = "x86_64"; | 
|---|
|  | 3128 | break; | 
|---|
|  | 3129 | #endif | 
|---|
|  | 3130 | case PROCESSOR_ARCHITECTURE_INTEL: | 
|---|
|  | 3131 | ret = "x86"; | 
|---|
|  | 3132 | break; | 
|---|
|  | 3133 | case PROCESSOR_ARCHITECTURE_IA64: | 
|---|
|  | 3134 | #ifdef PROCESSOR_ARCHITECTURE_IA32_ON_WIN64 | 
|---|
|  | 3135 | case PROCESSOR_ARCHITECTURE_IA32_ON_WIN64: | 
|---|
|  | 3136 | #endif | 
|---|
|  | 3137 | ret = "IA64"; | 
|---|
|  | 3138 | break; | 
|---|
|  | 3139 | default: | 
|---|
|  | 3140 | ret = "Unknown"; | 
|---|
|  | 3141 | break; | 
|---|
|  | 3142 | } | 
|---|
|  | 3143 | } | 
|---|
| [29] | 3144 | #elif defined(Q_OS_OS2) | 
|---|
|  | 3145 | if(type == "os") { | 
|---|
|  | 3146 | ret = "OS2"; | 
|---|
|  | 3147 | } else if(type == "name") { | 
|---|
|  | 3148 | ret = QString::fromLocal8Bit(qgetenv("HOSTNAME")); | 
|---|
|  | 3149 | } else if(type == "version" || type == "version_string") { | 
|---|
|  | 3150 | ULONG buf [3]; | 
|---|
|  | 3151 | DosQuerySysInfo(QSV_VERSION_MAJOR, QSV_VERSION_REVISION, | 
|---|
|  | 3152 | &buf, sizeof(buf)); | 
|---|
|  | 3153 | if(type == "version") | 
|---|
| [388] | 3154 | ret = QString().sprintf("%lu.%lu.%lu", buf[0], buf[1], buf[2]); | 
|---|
| [29] | 3155 | else { | 
|---|
|  | 3156 | /* Warp 3 is reported as 20.30 */ | 
|---|
|  | 3157 | /* Warp 4 is reported as 20.40 */ | 
|---|
|  | 3158 | /* Aurora and eCS are reported as 20.45 */ | 
|---|
|  | 3159 | if (buf[0] == 20 && buf[1] == 30) | 
|---|
|  | 3160 | ret = "Warp3"; | 
|---|
|  | 3161 | else if (buf[0] == 20 && buf[1] == 40) | 
|---|
|  | 3162 | ret = "Warp4"; | 
|---|
|  | 3163 | else if (buf[0] == 20 && buf[1] == 45) { | 
|---|
|  | 3164 | if (QString::fromLocal8Bit(qgetenv("OS")) == "ecs") | 
|---|
|  | 3165 | ret = "eComStation"; | 
|---|
|  | 3166 | else | 
|---|
|  | 3167 | ret = "Aurora"; | 
|---|
|  | 3168 | } | 
|---|
|  | 3169 | else | 
|---|
|  | 3170 | ret = "Unknown"; | 
|---|
|  | 3171 | } | 
|---|
|  | 3172 | } else if(type == "arch") { | 
|---|
|  | 3173 | ret = "x86"; | 
|---|
|  | 3174 | } | 
|---|
| [2] | 3175 | #elif defined(Q_OS_UNIX) | 
|---|
|  | 3176 | struct utsname name; | 
|---|
|  | 3177 | if(!uname(&name)) { | 
|---|
|  | 3178 | if(type == "os") | 
|---|
|  | 3179 | ret = name.sysname; | 
|---|
|  | 3180 | else if(type == "name") | 
|---|
|  | 3181 | ret = name.nodename; | 
|---|
|  | 3182 | else if(type == "version") | 
|---|
|  | 3183 | ret = name.release; | 
|---|
|  | 3184 | else if(type == "version_string") | 
|---|
|  | 3185 | ret = name.version; | 
|---|
|  | 3186 | else if(type == "arch") | 
|---|
|  | 3187 | ret = name.machine; | 
|---|
|  | 3188 | } | 
|---|
|  | 3189 | #endif | 
|---|
|  | 3190 | var = ".BUILTIN.HOST." + type; | 
|---|
|  | 3191 | place[var] = QStringList(ret); | 
|---|
|  | 3192 | } else if (var == QLatin1String("QMAKE_DIR_SEP")) { | 
|---|
|  | 3193 | if (place[var].isEmpty()) | 
|---|
|  | 3194 | return values("DIR_SEPARATOR", place); | 
|---|
| [561] | 3195 | } else if (var == QLatin1String("EPOCROOT")) { | 
|---|
|  | 3196 | if (place[var].isEmpty()) | 
|---|
|  | 3197 | place[var] = QStringList(epocRoot()); | 
|---|
| [2] | 3198 | } | 
|---|
|  | 3199 | //qDebug("REPLACE [%s]->[%s]", qPrintable(var), qPrintable(place[var].join("::"))); | 
|---|
|  | 3200 | return place[var]; | 
|---|
|  | 3201 | } | 
|---|
|  | 3202 |  | 
|---|
|  | 3203 | QT_END_NAMESPACE | 
|---|