Ignore:
Timestamp:
Feb 11, 2010, 11:19:06 PM (15 years ago)
Author:
Dmitry A. Kuminov
Message:

trunk: Merged in qt 4.6.1 sources.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/qmake/project.cpp

    r405 r561  
    22**
    33** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
    4 ** Contact: Qt Software Information (qt-info@nokia.com)
     4** All rights reserved.
     5** Contact: Nokia Corporation (qt-info@nokia.com)
    56**
    67** This file is part of the qmake application of the Qt Toolkit.
     
    2122** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
    2223**
    23 ** In addition, as a special exception, Nokia gives you certain
    24 ** additional rights. These rights are described in the Nokia Qt LGPL
    25 ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
    26 ** package.
     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.
    2727**
    2828** GNU General Public License Usage
     
    3434** met: http://www.gnu.org/copyleft/gpl.html.
    3535**
    36 ** If you are unsure which license is appropriate for your use, please
    37 ** contact the sales department at qt-sales@nokia.com.
     36** If you have questions regarding the use of this file, please contact
     37** Nokia at qt-info@nokia.com.
    3838** $QT_END_LICENSE$
    3939**
     
    4444#include "option.h"
    4545#include "cachekeys.h"
     46
     47#include "epocroot.h"
    4648
    4749#include <qdatetime.h>
     
    5860#include <sys/utsname.h>
    5961#elif defined(Q_OS_WIN32)
    60 #include <Windows.h>
     62#include <windows.h>
    6163#elif defined(Q_OS_OS2)
    6264#include <qt_os2.h>
     
    7981                  E_SPRINTF, E_JOIN, E_SPLIT, E_BASENAME, E_DIRNAME, E_SECTION,
    8082                  E_FIND, E_SYSTEM, E_UNIQUE, E_QUOTE, E_ESCAPE_EXPAND,
    81                   E_UPPER, E_LOWER, E_FILES, E_PROMPT, E_RE_ESCAPE, E_REPLACE };
     83                  E_UPPER, E_LOWER, E_FILES, E_PROMPT, E_RE_ESCAPE, E_REPLACE,
     84                  E_SIZE };
    8285QMap<QString, ExpandFunc> qmake_expandFunctions()
    8386{
     
    110113        qmake_expand_functions->insert("prompt", E_PROMPT);
    111114        qmake_expand_functions->insert("replace", E_REPLACE);
     115        qmake_expand_functions->insert("size", E_SIZE);
    112116    }
    113117    return *qmake_expand_functions;
     
    155159    return *qmake_test_functions;
    156160}
    157 
    158 QT_END_NAMESPACE
    159 
    160 #ifdef QTSCRIPT_SUPPORT
    161 #include "qscriptvalue.h"
    162 #include "qscriptengine.h"
    163 #include "qscriptvalueiterator.h"
    164 
    165 QT_BEGIN_NAMESPACE
    166 
    167 static QScriptValue qscript_projectWrapper(QScriptEngine *eng, QMakeProject *project,
    168                                     const QMap<QString, QStringList> &place);
    169 
    170 static bool qscript_createQMakeProjectMap(QMap<QString, QStringList> &vars, QScriptValue js)
    171 {
    172     QScriptValueIterator it(js);
    173     while(it.hasNext()) {
    174         it.next();
    175         vars[it.name()] = qscriptvalue_cast<QStringList>(it.value());
    176     }
    177     return true;
    178 }
    179 
    180 static QScriptValue qscript_call_testfunction(QScriptContext *context, QScriptEngine *engine)
    181 {
    182     QMakeProject *self = qscriptvalue_cast<QMakeProject*>(context->callee().property("qmakeProject"));
    183     QString func = context->callee().property("functionName").toString();
    184     QStringList args;
    185     for(int i = 0; i < context->argumentCount(); ++i)
    186         args += context->argument(i).toString();
    187     QMap<QString, QStringList> place = self->variables();
    188     qscript_createQMakeProjectMap(place, engine->globalObject().property("qmake"));
    189     QScriptValue ret(engine, self->doProjectTest(func, args, place));
    190     engine->globalObject().setProperty("qmake", qscript_projectWrapper(engine, self, place));
    191     return ret;
    192 }
    193 
    194 static QScriptValue qscript_call_expandfunction(QScriptContext *context, QScriptEngine *engine)
    195 {
    196     QMakeProject *self = qscriptvalue_cast<QMakeProject*>(context->callee().property("qmakeProject"));
    197     QString func = context->callee().property("functionName").toString();
    198     QStringList args;
    199     for(int i = 0; i < context->argumentCount(); ++i)
    200         args += context->argument(i).toString();
    201     QMap<QString, QStringList> place = self->variables();
    202     qscript_createQMakeProjectMap(place, engine->globalObject().property("qmake"));
    203     QScriptValue ret = qScriptValueFromValue(engine, self->doProjectExpand(func, args, place));
    204     engine->globalObject().setProperty("qmake", qscript_projectWrapper(engine, self, place));
    205     return ret;
    206 }
    207 
    208 static QScriptValue qscript_projectWrapper(QScriptEngine *eng, QMakeProject *project,
    209                                            const QMap<QString, QStringList> &place)
    210 {
    211     QScriptValue ret = eng->newObject();
    212     {
    213         QStringList testFuncs = qmake_testFunctions().keys() + project->userTestFunctions();
    214         for(int i = 0; i < testFuncs.size(); ++i) {
    215             QString funcName = testFuncs.at(i);
    216             QScriptValue fun = eng->newFunction(qscript_call_testfunction);
    217             fun.setProperty("qmakeProject", eng->newVariant(qVariantFromValue(project)));
    218             fun.setProperty("functionName", QScriptValue(eng, funcName));
    219             eng->globalObject().setProperty(funcName, fun);
    220         }
    221     }
    222     {
    223         QStringList testFuncs = qmake_expandFunctions().keys() + project->userExpandFunctions();
    224         for(int i = 0; i < testFuncs.size(); ++i) {
    225             QString funcName = testFuncs.at(i);
    226             QScriptValue fun = eng->newFunction(qscript_call_expandfunction);
    227             fun.setProperty("qmakeProject", eng->newVariant(qVariantFromValue(project)));
    228             fun.setProperty("functionName", QScriptValue(eng, funcName));
    229             eng->globalObject().setProperty(funcName, fun);
    230         }
    231     }
    232     for(QMap<QString, QStringList>::ConstIterator it = place.begin(); it != place.end(); ++it)
    233         ret.setProperty(it.key(), qScriptValueFromValue(eng, it.value()));
    234     return ret;
    235 }
    236 
    237 QT_END_NAMESPACE
    238 
    239 #endif
    240 
    241 QT_BEGIN_NAMESPACE
    242161
    243162struct parser_info {
     
    591510}
    592511
     512enum isForSymbian_enum {
     513    isForSymbian_NOT_SET = -1,
     514    isForSymbian_FALSE = 0,
     515    isForSymbian_ABLD = 1,
     516    isForSymbian_SBSV2 = 2,
     517};
     518
     519static 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.
     524static 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
     555bool 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
     565bool 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
    593575/*
    594576   1) environment variable QMAKEFEATURES (as separated by colons)
     
    617599            break;
    618600        case Option::TARG_UNIX_MODE:
    619             concat << base_concat + QDir::separator() + "unix";
    620             break;
     601            {
     602                if (isForSymbian())
     603                    concat << base_concat + QDir::separator() + "symbian";
     604                else
     605                    concat << base_concat + QDir::separator() + "unix";
     606                break;
     607            }
    621608        case Option::TARG_WIN_MODE:
    622             concat << base_concat + QDir::separator() + "win32";
    623             break;
     609            {
     610                if (isForSymbian())
     611                    concat << base_concat + QDir::separator() + "symbian";
     612                else
     613                    concat << base_concat + QDir::separator() + "win32";
     614                break;
     615            }
    624616        case Option::TARG_OS2_MODE:
    625617            concat << base_concat + QDir::separator() + "os2";
     
    628620            concat << base_concat + QDir::separator() + "mac";
    629621            concat << base_concat + QDir::separator() + "mac9";
    630             break;
    631         case Option::TARG_QNX6_MODE: //also a unix
    632             concat << base_concat + QDir::separator() + "qnx6";
    633             concat << base_concat + QDir::separator() + "unix";
    634622            break;
    635623        }
     
    14811469                return false;
    14821470            }
     1471
     1472            init_symbian(base_vars);
     1473
    14831474            if(Option::mkfile::do_cache && !Option::mkfile::cachefile.isEmpty()) {
    14841475                debug_msg(1, "QMAKECACHE file: reading %s", Option::mkfile::cachefile.toLatin1().constData());
     
    15271518    if(cmd & ReadProFile) { // parse project file
    15281519        debug_msg(1, "Project file: reading %s", pfile.toLatin1().constData());
    1529         if(pfile != "-" && !QFile::exists(pfile) && !pfile.endsWith(".pro"))
    1530             pfile += ".pro";
     1520        if(pfile != "-" && !QFile::exists(pfile) && !pfile.endsWith(Option::pro_ext))
     1521            pfile += Option::pro_ext;
    15311522        if(!read(pfile, vars))
    15321523            return false;
     
    16151606        return false;
    16161607
     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
    16171620    //mkspecs
    1618     if((Option::target_mode == Option::TARG_MACX_MODE || Option::target_mode == Option::TARG_QNX6_MODE ||
     1621    if((Option::target_mode == Option::TARG_MACX_MODE ||
    16191622        Option::target_mode == Option::TARG_UNIX_MODE) && x == "unix")
    1620         return true;
     1623        return !isForSymbian();
    16211624    else if(Option::target_mode == Option::TARG_MACX_MODE && x == "macx")
    1622         return true;
    1623     else if(Option::target_mode == Option::TARG_QNX6_MODE && x == "qnx6")
    1624         return true;
     1625        return !isForSymbian();
    16251626    else if(Option::target_mode == Option::TARG_MAC9_MODE && x == "mac9")
    1626         return true;
     1627        return !isForSymbian();
    16271628    else if((Option::target_mode == Option::TARG_MAC9_MODE || Option::target_mode == Option::TARG_MACX_MODE) &&
    16281629            x == "mac")
    1629         return true;
     1630        return !isForSymbian();
    16301631    else if(Option::target_mode == Option::TARG_WIN_MODE && x == "win32")
    1631         return true;
     1632        return !isForSymbian();
    16321633    else if(Option::target_mode == Option::TARG_OS2_MODE && x == "os2")
    16331634        return true;
    16341635    QRegExp re(x, Qt::CaseSensitive, QRegExp::Wildcard);
    1635     static QString spec;
    1636     if(spec.isEmpty())
    1637         spec = QFileInfo(Option::mkfile::qmakespec).fileName();
    16381636    if((regex && re.exactMatch(spec)) || (!regex && spec == x))
    16391637        return true;
     
    17231721            static QStringList *feature_roots = 0;
    17241722            if(!feature_roots) {
     1723                init_symbian(base_vars);
    17251724                feature_roots = new QStringList(qmake_feature_paths(prop));
    17261725                qmakeAddCacheClear(qmakeDeleteCacheClear_QStringList, (void**)&feature_roots);
     
    18081807    parser_info pi = parser;
    18091808    if(format == JSFormat) {
    1810 #ifdef QTSCRIPT_SUPPORT
    1811         eng.globalObject().setProperty("qmake", qscript_projectWrapper(&eng, this, place));
    1812         QFile f(file);
    1813         if (f.open(QFile::ReadOnly)) {
    1814             QString code = f.readAll();
    1815             QScriptValue r = eng.evaluate(code);
    1816             if(eng.hasUncaughtException()) {
    1817                 const int lineNo = eng.uncaughtExceptionLineNumber();
    1818                 fprintf(stderr, "%s:%d: %s\n", file.toLatin1().constData(), lineNo,
    1819                         r.toString().toLatin1().constData());
    1820             } else {
    1821                 parsed = true;
    1822                 QScriptValue variables = eng.globalObject().property("qmake");
    1823                 if (variables.isValid() && variables.isObject())
    1824                     qscript_createQMakeProjectMap(place, variables);
    1825             }
    1826         }
    1827 #else
    18281809        warn_msg(WarnParser, "%s:%d: QtScript support disabled for %s.",
    18291810                 pi.file.toLatin1().constData(), pi.line_no, orig_file.toLatin1().constData());
    1830 #endif
    18311811    } else {
    18321812        QStack<ScopeBlock> sc = scope_blocks;
     
    21652145            QMakeProjectEnv env(place);
    21662146            char buff[256];
    2167             FILE *proc = QT_POPEN(args[0].toLatin1(), "r");
    21682147            bool singleLine = true;
    21692148            if(args.count() > 1)
    21702149                singleLine = (args[1].toLower() == "true");
    21712150            QString output;
     2151            FILE *proc = QT_POPEN(args[0].toLatin1(), "r");
    21722152            while(proc && !feof(proc)) {
    21732153                int read_in = int(fread(buff, 1, 255, proc));
     
    23182298        }
    23192299        break; }
     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; }
    23202310    default: {
    2321 #ifdef QTSCRIPT_SUPPORT
    2322         {
    2323             QScriptValue jsFunc = eng.globalObject().property(func);
    2324             if(jsFunc.isFunction()) {
    2325                 QScriptValueList jsArgs;
    2326                 for(int i = 0; i < args.size(); ++i)
    2327                     jsArgs += QScriptValue(&eng, args.at(i));
    2328                 QScriptValue jsRet = jsFunc.call(eng.globalObject(), jsArgs);
    2329                 ret = qscriptvalue_cast<QStringList>(jsRet);
    2330                 break;
    2331             }
    2332         }
    2333 #endif
    23342311        fprintf(stderr, "%s:%d: Unknown replace function: %s\n",
    23352312                parser.file.toLatin1().constData(), parser.line_no,
     
    24132390            int lhs_int = lhs.toInt(&ok);
    24142391            if(ok) {
    2415                 if(func == "greaterThan")
     2392                if(func_t == T_GREATERTHAN)
    24162393                    return lhs_int > rhs_int;
    24172394                return lhs_int < rhs_int;
     
    27082685        QString parseInto;
    27092686        const bool include_statement = (func_t == T_INCLUDE);
    2710         bool ignore_error = include_statement;
    2711         if(args.count() == 2) {
     2687        bool ignore_error = false;
     2688        if(args.count() >= 2) {
    27122689            if(func_t == T_INCLUDE) {
    27132690                parseInto = args[1];
     2691                if (args.count() == 3){
     2692                    QString sarg = args[2];
     2693                    if (sarg.toLower() == "true" || sarg.toInt())
     2694                        ignore_error = true;
     2695                }
    27142696            } else {
    27152697                QString sarg = args[1];
     
    27532735            warn_msg(WarnParser, "%s:%d: Duplicate of loaded feature %s",
    27542736                     parser.file.toLatin1().constData(), parser.line_no, file.toLatin1().constData());
    2755         } else if(stat == IncludeNoExist && include_statement) {
    2756             warn_msg(WarnParser, "%s:%d: Unable to find file for inclusion %s",
     2737        } else if(stat == IncludeNoExist && !ignore_error) {
     2738            warn_msg(WarnAll, "%s:%d: Unable to find file for inclusion %s",
    27572739                     parser.file.toLatin1().constData(), parser.line_no, file.toLatin1().constData());
    27582740            return false;
     
    27972779        return true; }
    27982780    default:
    2799 #ifdef QTSCRIPT_SUPPORT
    2800         {
    2801             QScriptValue jsFunc = eng.globalObject().property(func);
    2802             if(jsFunc.isFunction()) {
    2803                 QScriptValueList jsArgs;
    2804                 for(int i = 0; i < args.size(); ++i)
    2805                     jsArgs += QScriptValue(&eng, args.at(i));
    2806                 QScriptValue jsRet = jsFunc.call(eng.globalObject(), jsArgs);
    2807                 if(eng.hasUncaughtException())
    2808                     return false;
    2809                 return qscriptvalue_cast<bool>(jsRet);
    2810             }
    2811         }
    2812 #endif
    28132781        fprintf(stderr, "%s:%d: Unknown test function: %s\n", parser.file.toLatin1().constData(), parser.line_no,
    28142782                func.toLatin1().constData());
     
    31263094        } else if(type == "name") {
    31273095            DWORD name_length = 1024;
    3128             TCHAR name[1024];
    3129             if(GetComputerName(name, &name_length))
    3130                 ret = QString::fromUtf16((ushort*)name, name_length);
     3096            wchar_t name[1024];
     3097            if (GetComputerName(name, &name_length))
     3098                ret = QString::fromWCharArray(name);
    31313099        } else if(type == "version" || type == "version_string") {
    31323100            QSysInfo::WinVersion ver = QSysInfo::WindowsVersion;
     
    32253193        if (place[var].isEmpty())
    32263194            return values("DIR_SEPARATOR", place);
     3195    } else if (var == QLatin1String("EPOCROOT")) {
     3196        if (place[var].isEmpty())
     3197            place[var] = QStringList(epocRoot());
    32273198    }
    32283199    //qDebug("REPLACE [%s]->[%s]", qPrintable(var), qPrintable(place[var].join("::")));
Note: See TracChangeset for help on using the changeset viewer.