qmakeevaluator.cpp 67.6 KB
Newer Older
hjk's avatar
hjk committed
1
/****************************************************************************
2
**
3
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
hjk's avatar
hjk committed
4
** Contact: http://www.qt-project.org/legal
5
**
hjk's avatar
hjk committed
6
** This file is part of Qt Creator.
7
**
hjk's avatar
hjk committed
8
9
10
11
12
13
14
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia.  For licensing terms and
** conditions see http://qt.digia.com/licensing.  For further information
** use the contact form at http://qt.digia.com/contact-us.
15
16
**
** GNU Lesser General Public License Usage
hjk's avatar
hjk committed
17
18
19
20
21
22
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file.  Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
23
**
hjk's avatar
hjk committed
24
25
** In addition, as a special exception, Digia gives you certain additional
** rights.  These rights are described in the Digia Qt LGPL Exception
26
27
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
hjk's avatar
hjk committed
28
****************************************************************************/
29
30

#include "qmakeevaluator.h"
31
#include "qmakeevaluator_p.h"
32
33
34

#include "qmakeglobals.h"
#include "qmakeparser.h"
35
#include "qmakevfs.h"
36
37
#include "ioutils.h"

38
39
40
41
42
43
44
45
46
47
48
49
#include <qbytearray.h>
#include <qdatetime.h>
#include <qdebug.h>
#include <qdir.h>
#include <qfile.h>
#include <qfileinfo.h>
#include <qlist.h>
#include <qregexp.h>
#include <qset.h>
#include <qstack.h>
#include <qstring.h>
#include <qstringlist.h>
50
#ifdef PROEVALUATOR_THREAD_SAFE
51
# include <qthreadpool.h>
52
53
54
55
56
57
#endif

#ifdef Q_OS_UNIX
#include <unistd.h>
#include <sys/utsname.h>
#else
Yuchen Deng's avatar
Yuchen Deng committed
58
#include <windows.h>
59
60
61
62
#endif
#include <stdio.h>
#include <stdlib.h>

63
using namespace QMakeInternal;
64
65
66
67
68

QT_BEGIN_NAMESPACE

#define fL1S(s) QString::fromLatin1(s)

69

70
71
72
73
74
75
76
QMakeBaseKey::QMakeBaseKey(const QString &_root, bool _hostBuild)
    : root(_root), hostBuild(_hostBuild)
{
}

uint qHash(const QMakeBaseKey &key)
{
Orgad Shaneh's avatar
Orgad Shaneh committed
77
    return qHash(key.root) ^ (uint)key.hostBuild;
78
79
80
81
82
83
84
}

bool operator==(const QMakeBaseKey &one, const QMakeBaseKey &two)
{
    return one.root == two.root && one.hostBuild == two.hostBuild;
}

85
86
87
88
89
90
91
92
93
94
95
96
97
QMakeBaseEnv::QMakeBaseEnv()
    : evaluator(0)
{
#ifdef PROEVALUATOR_THREAD_SAFE
    inProgress = false;
#endif
}

QMakeBaseEnv::~QMakeBaseEnv()
{
    delete evaluator;
}

98
namespace QMakeInternal {
99
100
101
102
103
104
105
106
107
108
109
QMakeStatics statics;
}

void QMakeEvaluator::initStatics()
{
    if (!statics.field_sep.isNull())
        return;

    statics.field_sep = QLatin1String(" ");
    statics.strtrue = QLatin1String("true");
    statics.strfalse = QLatin1String("false");
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
110
111
    statics.strCONFIG = ProKey("CONFIG");
    statics.strARGS = ProKey("ARGS");
112
113
114
115
    statics.strDot = QLatin1String(".");
    statics.strDotDot = QLatin1String("..");
    statics.strever = QLatin1String("ever");
    statics.strforever = QLatin1String("forever");
116
    statics.strhost_build = QLatin1String("host_build");
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
117
    statics.strTEMPLATE = ProKey("TEMPLATE");
118
    statics.strQMAKE_PLATFORM = ProKey("QMAKE_PLATFORM");
119
#ifdef PROEVALUATOR_FULL
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
120
    statics.strREQUIRES = ProKey("REQUIRES");
121
#endif
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147

    statics.fakeValue = ProStringList(ProString("_FAKE_")); // It has to have a unique begin() value

    initFunctionStatics();

    static const struct {
        const char * const oldname, * const newname;
    } mapInits[] = {
        { "INTERFACES", "FORMS" },
        { "QMAKE_POST_BUILD", "QMAKE_POST_LINK" },
        { "TARGETDEPS", "POST_TARGETDEPS" },
        { "LIBPATH", "QMAKE_LIBDIR" },
        { "QMAKE_EXT_MOC", "QMAKE_EXT_CPP_MOC" },
        { "QMAKE_MOD_MOC", "QMAKE_H_MOD_MOC" },
        { "QMAKE_LFLAGS_SHAPP", "QMAKE_LFLAGS_APP" },
        { "PRECOMPH", "PRECOMPILED_HEADER" },
        { "PRECOMPCPP", "PRECOMPILED_SOURCE" },
        { "INCPATH", "INCLUDEPATH" },
        { "QMAKE_EXTRA_WIN_COMPILERS", "QMAKE_EXTRA_COMPILERS" },
        { "QMAKE_EXTRA_UNIX_COMPILERS", "QMAKE_EXTRA_COMPILERS" },
        { "QMAKE_EXTRA_WIN_TARGETS", "QMAKE_EXTRA_TARGETS" },
        { "QMAKE_EXTRA_UNIX_TARGETS", "QMAKE_EXTRA_TARGETS" },
        { "QMAKE_EXTRA_UNIX_INCLUDES", "QMAKE_EXTRA_INCLUDES" },
        { "QMAKE_EXTRA_UNIX_VARIABLES", "QMAKE_EXTRA_VARIABLES" },
        { "QMAKE_RPATH", "QMAKE_LFLAGS_RPATH" },
        { "QMAKE_FRAMEWORKDIR", "QMAKE_FRAMEWORKPATH" },
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
148
149
        { "QMAKE_FRAMEWORKDIR_FLAGS", "QMAKE_FRAMEWORKPATH_FLAGS" },
        { "IN_PWD", "PWD" }
150
151
    };
    for (unsigned i = 0; i < sizeof(mapInits)/sizeof(mapInits[0]); ++i)
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
152
        statics.varMap.insert(ProKey(mapInits[i].oldname), ProKey(mapInits[i].newname));
153
154
}

Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
155
const ProKey &QMakeEvaluator::map(const ProKey &var)
156
{
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
157
    QHash<ProKey, ProKey>::ConstIterator it = statics.varMap.constFind(var);
158
159
    if (it == statics.varMap.constEnd())
        return var;
Robert Loehning's avatar
Robert Loehning committed
160
    deprecationWarning(fL1S("Variable %1 is deprecated; use %2 instead.")
161
162
                       .arg(var.toQString(), it.value().toQString()));
    return it.value();
163
164
165
}


166
167
QMakeEvaluator::QMakeEvaluator(QMakeGlobals *option, QMakeParser *parser, QMakeVfs *vfs,
                               QMakeHandler *handler)
168
169
170
171
  :
#ifdef PROEVALUATOR_DEBUG
    m_debugLevel(option->debugLevel),
#endif
172
    m_option(option), m_parser(parser), m_handler(handler), m_vfs(vfs)
173
174
175
176
177
{
    // So that single-threaded apps don't have to call initialize() for now.
    initStatics();

    // Configuration, more or less
178
    m_caller = 0;
179
#ifdef PROEVALUATOR_CUMULATIVE
180
    m_cumulative = false;
181
#endif
182
    m_hostBuild = false;
183
184

    // Evaluator state
185
#ifdef PROEVALUATOR_CUMULATIVE
186
    m_skipLevel = 0;
187
#endif
188
    m_listCount = 0;
189
    m_valuemapStack.push(ProValueMap());
190
    m_valuemapInited = false;
191
192
193
194
195
196
}

QMakeEvaluator::~QMakeEvaluator()
{
}

197
198
199
200
201
void QMakeEvaluator::initFrom(const QMakeEvaluator &other)
{
    Q_ASSERT_X(&other, "QMakeEvaluator::visitProFile", "Project not prepared");
    m_functionDefs = other.m_functionDefs;
    m_valuemapStack = other.m_valuemapStack;
202
    m_valuemapInited = true;
203
204
    m_qmakespec = other.m_qmakespec;
    m_qmakespecName = other.m_qmakespecName;
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
205
    m_mkspecPaths = other.m_mkspecPaths;
206
    m_featureRoots = other.m_featureRoots;
207
    m_dirSep = other.m_dirSep;
208
209
}

210
211
212
213
214
215
216
217
218
219
220
221
//////// Evaluator tools /////////

uint QMakeEvaluator::getBlockLen(const ushort *&tokPtr)
{
    uint len = *tokPtr++;
    len |= (uint)*tokPtr++ << 16;
    return len;
}

ProString QMakeEvaluator::getStr(const ushort *&tokPtr)
{
    uint len = *tokPtr++;
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
222
    ProString ret(m_current.pro->items(), tokPtr - m_current.pro->tokPtr(), len);
223
224
225
226
227
    ret.setSource(m_current.pro);
    tokPtr += len;
    return ret;
}

Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
228
ProKey QMakeEvaluator::getHashStr(const ushort *&tokPtr)
229
230
231
{
    uint hash = getBlockLen(tokPtr);
    uint len = *tokPtr++;
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
232
    ProKey ret(m_current.pro->items(), tokPtr - m_current.pro->tokPtr(), len, hash);
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
    tokPtr += len;
    return ret;
}

void QMakeEvaluator::skipStr(const ushort *&tokPtr)
{
    uint len = *tokPtr++;
    tokPtr += len;
}

void QMakeEvaluator::skipHashStr(const ushort *&tokPtr)
{
    tokPtr += 2;
    uint len = *tokPtr++;
    tokPtr += len;
}

// FIXME: this should not build new strings for direct sections.
// Note that the E_SPRINTF and E_LIST implementations rely on the deep copy.
ProStringList QMakeEvaluator::split_value_list(const QString &vals, const ProFile *source)
{
    QString build;
    ProStringList ret;

    if (!source)
        source = currentProFile();

    const QChar *vals_data = vals.data();
    const int vals_len = vals.length();
262
263
    ushort quote = 0;
    bool hadWord = false;
264
    for (int x = 0; x < vals_len; x++) {
265
266
267
        ushort unicode = vals_data[x].unicode();
        if (unicode == quote) {
            quote = 0;
268
269
            hadWord = true;
            build += QChar(unicode);
270
            continue;
271
        }
272
273
274
275
276
        switch (unicode) {
        case '"':
        case '\'':
            quote = unicode;
            hadWord = true;
277
            break;
278
279
280
281
282
283
284
285
286
287
288
289
290
291
        case ' ':
        case '\t':
            if (!quote) {
                if (hadWord) {
                    ret << ProString(build).setSource(source);
                    build.clear();
                    hadWord = false;
                }
                continue;
            }
            break;
        case '\\':
            if (x + 1 != vals_len) {
                ushort next = vals_data[++x].unicode();
292
293
                if (next == '\'' || next == '"' || next == '\\') {
                    build += QChar(unicode);
294
                    unicode = next;
295
                } else {
296
                    --x;
297
                }
298
299
300
301
302
            }
            // fallthrough
        default:
            hadWord = true;
            break;
303
        }
304
        build += QChar(unicode);
305
    }
306
    if (hadWord)
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
307
        ret << ProString(build).setSource(source);
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
    return ret;
}

static void zipEmpty(ProStringList *value)
{
    for (int i = value->size(); --i >= 0;)
        if (value->at(i).isEmpty())
            value->remove(i);
}

static void insertUnique(ProStringList *varlist, const ProStringList &value)
{
    foreach (const ProString &str, value)
        if (!str.isEmpty() && !varlist->contains(str))
            varlist->append(str);
}

static void removeAll(ProStringList *varlist, const ProString &value)
{
    for (int i = varlist->size(); --i >= 0; )
        if (varlist->at(i) == value)
            varlist->remove(i);
}

Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
332
void QMakeEvaluator::removeEach(ProStringList *varlist, const ProStringList &value)
333
334
335
336
337
338
339
340
341
342
343
344
345
{
    foreach (const ProString &str, value)
        if (!str.isEmpty())
            removeAll(varlist, str);
}

static void replaceInList(ProStringList *varlist,
        const QRegExp &regexp, const QString &replace, bool global, QString &tmp)
{
    for (ProStringList::Iterator varit = varlist->begin(); varit != varlist->end(); ) {
        QString val = varit->toQString(tmp);
        QString copy = val; // Force detach and have a reference value
        val.replace(regexp, replace);
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
346
        if (!val.isSharedWith(copy) && val != copy) {
347
348
349
            if (val.isEmpty()) {
                varit = varlist->erase(varit);
            } else {
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
350
                (*varit).setValue(val);
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
                ++varit;
            }
            if (!global)
                break;
        } else {
            ++varit;
        }
    }
}

//////// Evaluator /////////

static ALWAYS_INLINE void addStr(
        const ProString &str, ProStringList *ret, bool &pending, bool joined)
{
    if (joined) {
        ret->last().append(str, &pending);
    } else {
        if (!pending) {
            pending = true;
            *ret << str;
        } else {
            ret->last().append(str);
        }
    }
}

static ALWAYS_INLINE void addStrList(
        const ProStringList &list, ushort tok, ProStringList *ret, bool &pending, bool joined)
{
    if (!list.isEmpty()) {
        if (joined) {
            ret->last().append(list, &pending, !(tok & TokQuoted));
        } else {
            if (tok & TokQuoted) {
                if (!pending) {
                    pending = true;
                    *ret << ProString();
                }
                ret->last().append(list);
            } else {
                if (!pending) {
                    // Another qmake bizzarity: if nothing is pending and the
                    // first element is empty, it will be eaten
                    if (!list.at(0).isEmpty()) {
                        // The common case
                        pending = true;
                        *ret += list;
                        return;
                    }
                } else {
                    ret->last().append(list.at(0));
                }
                // This is somewhat slow, but a corner case
                for (int j = 1; j < list.size(); ++j) {
                    pending = true;
                    *ret << list.at(j);
                }
            }
        }
    }
}

void QMakeEvaluator::evaluateExpression(
        const ushort *&tokPtr, ProStringList *ret, bool joined)
{
417
    debugMsg(2, joined ? "evaluating joined expression" : "evaluating expression");
418
419
420
421
422
    if (joined)
        *ret << ProString();
    bool pending = false;
    forever {
        ushort tok = *tokPtr++;
423
424
        if (tok & TokNewStr) {
            debugMsg(2, "new string");
425
            pending = false;
426
        }
427
428
429
430
431
        ushort maskedTok = tok & TokMask;
        switch (maskedTok) {
        case TokLine:
            m_current.line = *tokPtr++;
            break;
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
        case TokLiteral: {
            const ProString &val = getStr(tokPtr);
            debugMsg(2, "literal %s", dbgStr(val));
            addStr(val, ret, pending, joined);
            break; }
        case TokHashLiteral: {
            const ProKey &val = getHashStr(tokPtr);
            debugMsg(2, "hashed literal %s", dbgStr(val.toString()));
            addStr(val, ret, pending, joined);
            break; }
        case TokVariable: {
            const ProKey &var = getHashStr(tokPtr);
            const ProStringList &val = values(map(var));
            debugMsg(2, "variable %s => %s", dbgKey(var), dbgStrList(val));
            addStrList(val, tok, ret, pending, joined);
            break; }
        case TokProperty: {
            const ProKey &var = getHashStr(tokPtr);
            const ProString &val = propertyValue(var);
            debugMsg(2, "property %s => %s", dbgKey(var), dbgStr(val));
            addStr(val, ret, pending, joined);
            break; }
        case TokEnvVar: {
            const ProString &var = getStr(tokPtr);
Daniel Teske's avatar
Daniel Teske committed
456
            const ProString &val = ProString(m_option->getEnv(var.toQString()));
457
458
            debugMsg(2, "env var %s => %s", dbgStr(var), dbgStr(val));
            addStr(val, ret, pending, joined);
459
            break; }
460
        case TokFuncName: {
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
461
            const ProKey &func = getHashStr(tokPtr);
462
            debugMsg(2, "function %s", dbgKey(func));
463
464
465
            addStrList(evaluateExpandFunction(func, tokPtr), tok, ret, pending, joined);
            break; }
        default:
466
            debugMsg(2, "evaluated expression => %s", dbgStrList(*ret));
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
            tokPtr--;
            return;
        }
    }
}

void QMakeEvaluator::skipExpression(const ushort *&pTokPtr)
{
    const ushort *tokPtr = pTokPtr;
    forever {
        ushort tok = *tokPtr++;
        switch (tok) {
        case TokLine:
            m_current.line = *tokPtr++;
            break;
        case TokValueTerminator:
        case TokFuncTerminator:
            pTokPtr = tokPtr;
            return;
        case TokArgSeparator:
            break;
        default:
            switch (tok & TokMask) {
            case TokLiteral:
            case TokEnvVar:
                skipStr(tokPtr);
                break;
            case TokHashLiteral:
            case TokVariable:
496
            case TokProperty:
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
                skipHashStr(tokPtr);
                break;
            case TokFuncName:
                skipHashStr(tokPtr);
                pTokPtr = tokPtr;
                skipExpression(pTokPtr);
                tokPtr = pTokPtr;
                break;
            default:
                Q_ASSERT_X(false, "skipExpression", "Unrecognized token");
                break;
            }
        }
    }
}

QMakeEvaluator::VisitReturn QMakeEvaluator::visitProBlock(
        ProFile *pro, const ushort *tokPtr)
{
    m_current.pro = pro;
    m_current.line = 0;
    return visitProBlock(tokPtr);
}

QMakeEvaluator::VisitReturn QMakeEvaluator::visitProBlock(
        const ushort *tokPtr)
{
524
    traceMsg("entering block");
525
526
527
528
    ProStringList curr;
    bool okey = true, or_op = false, invert = false;
    uint blockLen;
    while (ushort tok = *tokPtr++) {
529
        VisitReturn ret;
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
        switch (tok) {
        case TokLine:
            m_current.line = *tokPtr++;
            continue;
        case TokAssign:
        case TokAppend:
        case TokAppendUnique:
        case TokRemove:
        case TokReplace:
            visitProVariable(tok, curr, tokPtr);
            curr.clear();
            continue;
        case TokBranch:
            blockLen = getBlockLen(tokPtr);
            if (m_cumulative) {
545
#ifdef PROEVALUATOR_CUMULATIVE
546
547
548
549
550
551
552
553
554
555
556
557
558
                if (!okey)
                    m_skipLevel++;
                ret = blockLen ? visitProBlock(tokPtr) : ReturnTrue;
                tokPtr += blockLen;
                blockLen = getBlockLen(tokPtr);
                if (!okey)
                    m_skipLevel--;
                else
                    m_skipLevel++;
                if ((ret == ReturnTrue || ret == ReturnFalse) && blockLen)
                    ret = visitProBlock(tokPtr);
                if (okey)
                    m_skipLevel--;
559
#endif
560
            } else {
561
562
                if (okey) {
                    traceMsg("taking 'then' branch");
563
                    ret = blockLen ? visitProBlock(tokPtr) : ReturnTrue;
564
565
                    traceMsg("finished 'then' branch");
                }
566
567
                tokPtr += blockLen;
                blockLen = getBlockLen(tokPtr);
568
569
                if (!okey) {
                    traceMsg("taking 'else' branch");
570
                    ret = blockLen ? visitProBlock(tokPtr) : ReturnTrue;
571
572
                    traceMsg("finished 'else' branch");
                }
573
574
575
576
577
            }
            tokPtr += blockLen;
            okey = true, or_op = false; // force next evaluation
            break;
        case TokForLoop:
578
            if (m_cumulative || okey != or_op) {
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
579
                const ProKey &variable = getHashStr(tokPtr);
580
581
582
583
584
585
586
587
588
589
                uint exprLen = getBlockLen(tokPtr);
                const ushort *exprPtr = tokPtr;
                tokPtr += exprLen;
                blockLen = getBlockLen(tokPtr);
                ret = visitProLoop(variable, exprPtr, tokPtr);
            } else {
                skipHashStr(tokPtr);
                uint exprLen = getBlockLen(tokPtr);
                tokPtr += exprLen;
                blockLen = getBlockLen(tokPtr);
590
                traceMsg("skipped loop");
591
592
593
594
595
596
597
598
                ret = ReturnTrue;
            }
            tokPtr += blockLen;
            okey = true, or_op = false; // force next evaluation
            break;
        case TokTestDef:
        case TokReplaceDef:
            if (m_cumulative || okey != or_op) {
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
599
                const ProKey &name = getHashStr(tokPtr);
600
601
                blockLen = getBlockLen(tokPtr);
                visitProFunctionDef(tok, name, tokPtr);
602
603
                traceMsg("defined %s function %s",
                      tok == TokTestDef ? "test" : "replace", dbgKey(name));
604
            } else {
605
                traceMsg("skipped function definition");
606
607
608
609
610
611
612
                skipHashStr(tokPtr);
                blockLen = getBlockLen(tokPtr);
            }
            tokPtr += blockLen;
            okey = true, or_op = false; // force next evaluation
            continue;
        case TokNot:
613
            traceMsg("NOT");
614
615
616
            invert ^= true;
            continue;
        case TokAnd:
617
            traceMsg("AND");
618
619
620
            or_op = false;
            continue;
        case TokOr:
621
            traceMsg("OR");
622
623
624
625
626
627
628
629
630
            or_op = true;
            continue;
        case TokCondition:
            if (!m_skipLevel && okey != or_op) {
                if (curr.size() != 1) {
                    if (!m_cumulative || !curr.isEmpty())
                        evalError(fL1S("Conditional must expand to exactly one word."));
                    okey = false;
                } else {
631
632
633
                    okey = isActiveConfig(curr.at(0).toQString(m_tmp2), true);
                    traceMsg("condition %s is %s", dbgStr(curr.at(0)), dbgBool(okey));
                    okey ^= invert;
634
                }
635
636
            } else {
                traceMsg("skipped condition %s", curr.size() == 1 ? dbgStr(curr.at(0)) : "<invalid>");
637
638
639
640
641
642
643
644
645
646
647
648
649
            }
            or_op = !okey; // tentatively force next evaluation
            invert = false;
            curr.clear();
            continue;
        case TokTestCall:
            if (!m_skipLevel && okey != or_op) {
                if (curr.size() != 1) {
                    if (!m_cumulative || !curr.isEmpty())
                        evalError(fL1S("Test name must expand to exactly one word."));
                    skipExpression(tokPtr);
                    okey = false;
                } else {
650
                    traceMsg("evaluating test function %s", dbgStr(curr.at(0)));
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
651
                    ret = evaluateConditionalFunction(curr.at(0).toKey(), tokPtr);
652
653
654
                    switch (ret) {
                    case ReturnTrue: okey = true; break;
                    case ReturnFalse: okey = false; break;
655
656
657
                    default:
                        traceMsg("aborting block, function status: %s", dbgReturn(ret));
                        return ret;
658
                    }
659
                    traceMsg("test function returned %s", dbgBool(okey));
660
661
662
                    okey ^= invert;
                }
            } else if (m_cumulative) {
663
#ifdef PROEVALUATOR_CUMULATIVE
664
665
666
667
                m_skipLevel++;
                if (curr.size() != 1)
                    skipExpression(tokPtr);
                else
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
668
                    evaluateConditionalFunction(curr.at(0).toKey(), tokPtr);
669
                m_skipLevel--;
670
#endif
671
672
            } else {
                skipExpression(tokPtr);
673
                traceMsg("skipped test function %s", curr.size() == 1 ? dbgStr(curr.at(0)) : "<invalid>");
674
675
676
677
678
            }
            or_op = !okey; // tentatively force next evaluation
            invert = false;
            curr.clear();
            continue;
679
680
681
682
683
684
685
686
687
688
689
        case TokReturn:
            m_returnValue = curr;
            curr.clear();
            ret = ReturnReturn;
            goto ctrlstm;
        case TokBreak:
            ret = ReturnBreak;
            goto ctrlstm;
        case TokNext:
            ret = ReturnNext;
          ctrlstm:
690
691
            if (!m_skipLevel && okey != or_op) {
                traceMsg("flow control statement '%s', aborting block", dbgReturn(ret));
692
                return ret;
693
694
            }
            traceMsg("skipped flow control statement '%s'", dbgReturn(ret));
695
696
            okey = false, or_op = true; // force next evaluation
            continue;
697
698
699
700
701
702
703
        default: {
                const ushort *oTokPtr = --tokPtr;
                evaluateExpression(tokPtr, &curr, false);
                if (tokPtr != oTokPtr)
                    continue;
            }
            Q_ASSERT_X(false, "visitProBlock", "unexpected item type");
704
            continue;
705
        }
706
707
        if (ret != ReturnTrue && ret != ReturnFalse) {
            traceMsg("aborting block, status: %s", dbgReturn(ret));
708
            return ret;
709
        }
710
    }
711
    traceMsg("leaving block, okey=%s", dbgBool(okey));
712
    return returnBool(okey);
713
714
715
716
}


void QMakeEvaluator::visitProFunctionDef(
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
717
        ushort tok, const ProKey &name, const ushort *tokPtr)
718
{
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
719
    QHash<ProKey, ProFunctionDef> *hash =
720
721
722
723
724
725
726
            (tok == TokTestDef
             ? &m_functionDefs.testFunctions
             : &m_functionDefs.replaceFunctions);
    hash->insert(name, ProFunctionDef(m_current.pro, tokPtr - m_current.pro->tokPtr()));
}

QMakeEvaluator::VisitReturn QMakeEvaluator::visitProLoop(
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
727
        const ProKey &_variable, const ushort *exprPtr, const ushort *tokPtr)
728
729
730
731
{
    VisitReturn ret = ReturnTrue;
    bool infinite = false;
    int index = 0;
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
732
    ProKey variable;
733
734
735
736
737
738
739
740
741
742
    ProStringList oldVarVal;
    ProString it_list = expandVariableReferences(exprPtr, 0, true).at(0);
    if (_variable.isEmpty()) {
        if (it_list != statics.strever) {
            evalError(fL1S("Invalid loop expression."));
            return ReturnFalse;
        }
        it_list = ProString(statics.strforever);
    } else {
        variable = map(_variable);
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
743
        oldVarVal = values(variable);
744
    }
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
745
    ProStringList list = values(it_list.toKey());
746
747
    if (list.isEmpty()) {
        if (it_list == statics.strforever) {
748
749
750
751
752
            if (m_cumulative) {
                // The termination conditions wouldn't be evaluated, so we must skip it.
                traceMsg("skipping forever loop in cumulative mode");
                return ReturnFalse;
            }
753
754
755
756
757
758
759
760
761
762
            infinite = true;
        } else {
            const QString &itl = it_list.toQString(m_tmp1);
            int dotdot = itl.indexOf(statics.strDotDot);
            if (dotdot != -1) {
                bool ok;
                int start = itl.left(dotdot).toInt(&ok);
                if (ok) {
                    int end = itl.mid(dotdot+2).toInt(&ok);
                    if (ok) {
763
764
765
766
767
768
                        if (m_cumulative && qAbs(end - start) > 100) {
                            // Such a loop is unlikely to contribute something useful to the
                            // file collection, and may cause considerable delay.
                            traceMsg("skipping excessive loop in cumulative mode");
                            return ReturnFalse;
                        }
769
770
                        if (start < end) {
                            for (int i = start; i <= end; i++)
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
771
                                list << ProString(QString::number(i));
772
773
                        } else {
                            for (int i = start; i >= end; i--)
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
774
                                list << ProString(QString::number(i));
775
776
777
778
779
780
781
                        }
                    }
                }
            }
        }
    }

782
783
784
785
786
    if (infinite)
        traceMsg("entering infinite loop for %s", dbgKey(variable));
    else
        traceMsg("entering loop for %s over %s", dbgKey(variable), dbgStrList(list));

787
788
789
    forever {
        if (infinite) {
            if (!variable.isEmpty())
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
790
                m_valuemapStack.top()[variable] = ProStringList(ProString(QString::number(index++)));
791
            if (index > 1000) {
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
792
                evalError(fL1S("Ran into infinite loop (> 1000 iterations)."));
793
794
                break;
            }
795
            traceMsg("loop iteration %d", index);
796
797
798
799
800
801
802
        } else {
            ProString val;
            do {
                if (index >= list.count())
                    goto do_break;
                val = list.at(index++);
            } while (val.isEmpty()); // stupid, but qmake is like that
803
            traceMsg("loop iteration %s", dbgStr(val));
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
            m_valuemapStack.top()[variable] = ProStringList(val);
        }

        ret = visitProBlock(tokPtr);
        switch (ret) {
        case ReturnTrue:
        case ReturnFalse:
            break;
        case ReturnNext:
            ret = ReturnTrue;
            break;
        case ReturnBreak:
            ret = ReturnTrue;
            goto do_break;
        default:
            goto do_break;
        }
    }
  do_break:

824
825
    traceMsg("done looping");

826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
    if (!variable.isEmpty())
        m_valuemapStack.top()[variable] = oldVarVal;
    return ret;
}

void QMakeEvaluator::visitProVariable(
        ushort tok, const ProStringList &curr, const ushort *&tokPtr)
{
    int sizeHint = *tokPtr++;

    if (curr.size() != 1) {
        skipExpression(tokPtr);
        if (!m_cumulative || !curr.isEmpty())
            evalError(fL1S("Left hand side of assignment must expand to exactly one word."));
        return;
    }
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
842
    const ProKey &varName = map(curr.first());
843
844
845
846
847
848
849

    if (tok == TokReplace) {      // ~=
        // DEFINES ~= s/a/b/?[gqi]

        const ProStringList &varVal = expandVariableReferences(tokPtr, sizeHint, true);
        const QString &val = varVal.at(0).toQString(m_tmp1);
        if (val.length() < 4 || val.at(0) != QLatin1Char('s')) {
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
850
            evalError(fL1S("The ~= operator can handle only the s/// function."));
851
852
853
854
855
            return;
        }
        QChar sep = val.at(1);
        QStringList func = val.split(sep);
        if (func.count() < 3 || func.count() > 4) {
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
856
            evalError(fL1S("The s/// function expects 3 or 4 arguments."));
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
            return;
        }

        bool global = false, quote = false, case_sense = false;
        if (func.count() == 4) {
            global = func[3].indexOf(QLatin1Char('g')) != -1;
            case_sense = func[3].indexOf(QLatin1Char('i')) == -1;
            quote = func[3].indexOf(QLatin1Char('q')) != -1;
        }
        QString pattern = func[1];
        QString replace = func[2];
        if (quote)
            pattern = QRegExp::escape(pattern);

        QRegExp regexp(pattern, case_sense ? Qt::CaseSensitive : Qt::CaseInsensitive);

873
874
875
        // We could make a union of modified and unmodified values,
        // but this will break just as much as it fixes, so leave it as is.
        replaceInList(&valuesRef(varName), regexp, replace, global, m_tmp2);
876
        debugMsg(2, "replaced %s with %s", dbgQStr(pattern), dbgQStr(replace));
877
878
879
880
881
    } else {
        ProStringList varVal = expandVariableReferences(tokPtr, sizeHint);
        switch (tok) {
        default: // whatever - cannot happen
        case TokAssign:          // =
882
            zipEmpty(&varVal);
883
            if (!m_cumulative) {
884
885
886
                // FIXME: add check+warning about accidental value removal.
                // This may be a bit too noisy, though.
                m_valuemapStack.top()[varName] = varVal;
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
            } else {
                if (!varVal.isEmpty()) {
                    // We are greedy for values. But avoid exponential growth.
                    ProStringList &v = valuesRef(varName);
                    if (v.isEmpty()) {
                        v = varVal;
                    } else {
                        ProStringList old = v;
                        v = varVal;
                        QSet<ProString> has;
                        has.reserve(v.size());
                        foreach (const ProString &s, v)
                            has.insert(s);
                        v.reserve(v.size() + old.size());
                        foreach (const ProString &s, old)
                            if (!has.contains(s))
                                v << s;
                    }
                }
            }
907
            debugMsg(2, "assigning");
908
909
            break;
        case TokAppendUnique:    // *=
910
            insertUnique(&valuesRef(varName), varVal);
911
            debugMsg(2, "appending unique");
912
913
            break;
        case TokAppend:          // +=
914
915
            zipEmpty(&varVal);
            valuesRef(varName) += varVal;
916
            debugMsg(2, "appending");
917
918
919
            break;
        case TokRemove:       // -=
            if (!m_cumulative) {
920
                removeEach(&valuesRef(varName), varVal);
921
922
923
            } else {
                // We are stingy with our values, too.
            }
924
            debugMsg(2, "removing");
925
926
927
            break;
        }
    }
928
    traceMsg("%s := %s", dbgKey(varName), dbgStrList(values(varName)));
929
930
931

    if (varName == statics.strTEMPLATE)
        setTemplate();
932
    else if (varName == statics.strQMAKE_PLATFORM)
933
        m_featureRoots = 0;
934
935
936
937
#ifdef PROEVALUATOR_FULL
    else if (varName == statics.strREQUIRES)
        checkRequirements(values(varName));
#endif
938
939
940
941
942
}

void QMakeEvaluator::setTemplate()
{
    ProStringList &values = valuesRef(statics.strTEMPLATE);
943
944
    if (!m_option->user_template.isEmpty()) {
        // Don't allow override
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
945
        values = ProStringList(ProString(m_option->user_template));
946
947
    } else {
        if (values.isEmpty())
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
948
            values.append(ProString("app"));
949
950
951
952
953
954
955
        else
            values.erase(values.begin() + 1, values.end());
    }
    if (!m_option->user_template_prefix.isEmpty()) {
        QString val = values.first().toQString(m_tmp1);
        if (!val.startsWith(m_option->user_template_prefix)) {
            val.prepend(m_option->user_template_prefix);
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
956
            values = ProStringList(ProString(val));
957
958
        }
    }
959
960
}

961
962
963
964
void QMakeEvaluator::loadDefaults()
{
    ProValueMap &vars = m_valuemapStack.top();

Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
965
966
967
    vars[ProKey("DIR_SEPARATOR")] << ProString(m_option->dir_sep);
    vars[ProKey("DIRLIST_SEPARATOR")] << ProString(m_option->dirlist_sep);
    vars[ProKey("_DATE_")] << ProString(QDateTime::currentDateTime().toString());
968
    if (!m_option->qmake_abslocation.isEmpty())
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
969
        vars[ProKey("QMAKE_QMAKE")] << ProString(m_option->qmake_abslocation);
970
#if defined(Q_OS_WIN32)
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
971
    vars[ProKey("QMAKE_HOST.os")] << ProString("Windows");
972
973
974
975

    DWORD name_length = 1024;
    wchar_t name[1024];
    if (GetComputerName(name, &name_length))
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
976
        vars[ProKey("QMAKE_HOST.name")] << ProString(QString::fromWCharArray(name));
977
978

    QSysInfo::WinVersion ver = QSysInfo::WindowsVersion;
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
979
    vars[ProKey("QMAKE_HOST.version")] << ProString(QString::number(ver));
980
981
    ProString verStr;
    switch (ver) {
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
982
983
984
985
986
987
988
989
990
    case QSysInfo::WV_Me: verStr = ProString("WinMe"); break;
    case QSysInfo::WV_95: verStr = ProString("Win95"); break;
    case QSysInfo::WV_98: verStr = ProString("Win98"); break;
    case QSysInfo::WV_NT: verStr = ProString("WinNT"); break;
    case QSysInfo::WV_2000: verStr = ProString("Win2000"); break;
    case QSysInfo::WV_2003: verStr = ProString("Win2003"); break;
    case QSysInfo::WV_XP: verStr = ProString("WinXP"); break;
    case QSysInfo::WV_VISTA: verStr = ProString("WinVista"); break;
    default: verStr = ProString("Unknown"); break;
991
    }
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
992
    vars[ProKey("QMAKE_HOST.version_string")] << verStr;
993
994
995
996
997
998
999

    SYSTEM_INFO info;
    GetSystemInfo(&info);
    ProString archStr;
    switch (info.wProcessorArchitecture) {
# ifdef PROCESSOR_ARCHITECTURE_AMD64
    case PROCESSOR_ARCHITECTURE_AMD64:
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
1000
        archStr = ProString("x86_64");
1001
1002
1003
        break;
# endif
    case PROCESSOR_ARCHITECTURE_INTEL:
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
1004
        archStr = ProString("x86");
1005
1006
1007
1008
1009
        break;
    case PROCESSOR_ARCHITECTURE_IA64:
# ifdef PROCESSOR_ARCHITECTURE_IA32_ON_WIN64
    case PROCESSOR_ARCHITECTURE_IA32_ON_WIN64:
# endif
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
1010
        archStr = ProString("IA64");
1011
1012
        break;
    default:
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
1013
        archStr = ProString("Unknown");
1014
1015
        break;
    }
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
1016
    vars[ProKey("QMAKE_HOST.arch")] << archStr;
1017
1018

# if defined(Q_CC_MSVC) // ### bogus condition, but nobody x-builds for msvc with a different qmake
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
    QLatin1Char backslash('\\');
    QString paths = m_option->getEnv(QLatin1String("PATH"));
    QString vcBin64 = m_option->getEnv(QLatin1String("VCINSTALLDIR"));
    if (!vcBin64.endsWith(backslash))
        vcBin64.append(backslash);
    vcBin64.append(QLatin1String("bin\\amd64"));
    QString vcBinX86_64 = m_option->getEnv(QLatin1String("VCINSTALLDIR"));
    if (!vcBinX86_64.endsWith(backslash))
        vcBinX86_64.append(backslash);
    vcBinX86_64.append(QLatin1String("bin\\x86_amd64"));
1029
1030
    if (paths.contains(vcBin64, Qt::CaseInsensitive)
            || paths.contains(vcBinX86_64, Qt::CaseInsensitive))
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
1031
        vars[ProKey("QMAKE_TARGET.arch")] << ProString("x86_64");
1032
    else
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
1033
        vars[ProKey("QMAKE_TARGET.arch")] << ProString("x86");
1034
# endif
1035
1036
#elif defined(Q_OS_UNIX)
    struct utsname name;
Chris Stylianou's avatar
Chris Stylianou committed
1037
    if (uname(&name) != -1) {
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
1038
1039
1040
1041
1042
        vars[ProKey("QMAKE_HOST.os")] << ProString(name.sysname);
        vars[ProKey("QMAKE_HOST.name")] << ProString(QString::fromLocal8Bit(name.nodename));
        vars[ProKey("QMAKE_HOST.version")] << ProString(name.release);
        vars[ProKey("QMAKE_HOST.version_string")] << ProString(name.version);
        vars[ProKey("QMAKE_HOST.arch")] << ProString(name.machine);
1043
1044
    }
#endif
1045
1046

    m_valuemapInited = true;
1047
1048
}

Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
1049
bool QMakeEvaluator::prepareProject(const QString &inDir)
1050
{
1051
    QString superdir;
1052
    if (m_option->do_cache) {
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
1053
        QString conffile;
1054
1055
1056
1057
        QString cachefile = m_option->cachefile;
        if (cachefile.isEmpty())  { //find it as it has not been specified
            if (m_outputDir.isEmpty())
                goto no_cache;
1058
            superdir = m_outputDir;
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
1059
1060
            forever {
                QString superfile = superdir + QLatin1String("/.qmake.super");
1061
                if (m_vfs->exists(superfile)) {
1062
                    m_superfile = QDir::cleanPath(superfile);
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
1063
1064
1065
1066
1067
1068
1069
1070
1071
                    break;
                }
                QFileInfo qdfi(superdir);
                if (qdfi.isRoot()) {
                    superdir.clear();
                    break;
                }
                superdir = qdfi.path();
            }
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
1072
            QString sdir = inDir;
1073
            QString dir = m_outputDir;
1074
            forever {
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
1075
                conffile = sdir + QLatin1String("/.qmake.conf");
1076
                if (!m_vfs->exists(conffile))
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
1077
                    conffile.clear();
1078
                cachefile = dir + QLatin1String("/.qmake.cache");
1079
                if (!m_vfs->exists(cachefile))
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
1080
1081
                    cachefile.clear();
                if (!conffile.isEmpty() || !cachefile.isEmpty()) {
1082
1083
                    if (dir != sdir)
                        m_sourceRoot = sdir;
1084
                    m_buildRoot = dir;
1085
1086
                    break;
                }
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
1087
1088
                if (dir == superdir)
                    goto no_cache;
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
1089
                QFileInfo qsdfi(sdir);
1090
                QFileInfo qdfi(dir);
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
1091
                if (qsdfi.isRoot() || qdfi.isRoot())
1092
                    goto no_cache;
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
1093
                sdir = qsdfi.path();
1094
                dir = qdfi.path();
1095
            }
1096
1097
        } else {
            m_buildRoot = QFileInfo(cachefile).path();
1098
        }
1099
1100
        m_conffile = QDir::cleanPath(conffile);
        m_cachefile = QDir::cleanPath(cachefile);
1101
    }
1102
  no_cache:
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124

    // Look for mkspecs/ in source and build. First to win determines the root.
    QString sdir = inDir;
    QString dir = m_outputDir;
    while (dir != m_buildRoot) {
        if ((dir != sdir && QFileInfo(sdir, QLatin1String("mkspecs")).isDir())
                || QFileInfo(dir, QLatin1String("mkspecs")).isDir()) {
            if (dir != sdir)
                m_sourceRoot = sdir;
            m_buildRoot = dir;
            break;
        }
        if (dir == superdir)
            break;
        QFileInfo qsdfi(sdir);
        QFileInfo qdfi(dir);
        if (qsdfi.isRoot() || qdfi.isRoot())
            break;
        sdir = qsdfi.path();
        dir = qdfi.path();
    }

1125
    return true;
1126
1127
}

1128
1129
bool QMakeEvaluator::loadSpecInternal()
{
1130
    if (evaluateFeatureFile(QLatin1String("spec_pre.prf")) != ReturnTrue)
1131
1132
        return false;
    QString spec = m_qmakespec + QLatin1String("/qmake.conf");
1133
    if (evaluateFile(spec, QMakeHandler::EvalConfigFile, LoadProOnly) != ReturnTrue) {
1134
1135
1136
        evalError(fL1S("Could not read qmake configuration file %1.").arg(spec));
        return false;
    }
1137
1138
1139
#ifndef QT_BUILD_QMAKE
    // Legacy support for Qt4 default specs
#  ifdef Q_OS_UNIX
1140
1141
1142
1143
1144
1145
    if (m_qmakespec.endsWith(QLatin1String("/default-host"))
        || m_qmakespec.endsWith(QLatin1String("/default"))) {
        QString rspec = QFileInfo(m_qmakespec).readLink();
        if (!rspec.isEmpty())
            m_qmakespec = QDir::cleanPath(QDir(m_qmakespec).absoluteFilePath(rspec));
    }
1146
#  else
1147
1148
1149
1150
    // We can't resolve symlinks as they do on Unix, so configure.exe puts
    // the source of the qmake.conf at the end of the default/qmake.conf in
    // the QMAKESPEC_ORIGINAL variable.
    const ProString &orig_spec = first(ProKey("QMAKESPEC_ORIGINAL"));
1151
1152
    if (!orig_spec.isEmpty())
        m_qmakespec = orig_spec.toQString();
1153
#  endif
1154
#endif
1155
1156
    valuesRef(ProKey("QMAKESPEC")) << ProString(m_qmakespec);
    m_qmakespecName = IoUtils::fileName(m_qmakespec).toString();
1157
    // This also ensures that m_featureRoots is valid.
1158
    if (evaluateFeatureFile(QLatin1String("spec_post.prf")) != ReturnTrue)
1159
1160
1161
1162
1163
1164
        return false;
    // The MinGW and x-build specs may change the separator; $$shell_{path,quote}() need it
    m_dirSep = first(ProKey("QMAKE_DIR_SEP"));
    return true;
}

1165
bool QMakeEvaluator::loadSpec()
1166
{
1167
1168
    QString qmakespec = m_option->expandEnvVars(
                m_hostBuild ? m_option->qmakespec : m_option->xqmakespec);
1169
1170

    {
1171
        QMakeEvaluator evaluator(m_option, m_parser, m_vfs, m_handler);
1172
1173
        evaluator.m_sourceRoot = m_sourceRoot;
        evaluator.m_buildRoot = m_buildRoot;
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
1174
        if (!m_superfile.isEmpty()) {
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
1175
            valuesRef(ProKey("_QMAKE_SUPER_CACHE_")) << ProString(m_superfile);
1176
1177
            if (evaluator.evaluateFile(
                    m_superfile, QMakeHandler::EvalConfigFile, LoadProOnly) != ReturnTrue)
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
1178
1179
                return false;
        }
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
1180
        if (!m_conffile.isEmpty()) {
Oswald Buddenhagen's avatar
Oswald Buddenhagen committed
1181
            valuesRef(ProKey("_QMAKE_CONF_")) << ProString(m_conffile);
1182