Changeset 561 for trunk/qmake/project.cpp
- Timestamp:
- Feb 11, 2010, 11:19:06 PM (15 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
-
Property svn:mergeinfo
set to (toggle deleted branches)
/branches/vendor/nokia/qt/4.6.1 merged eligible /branches/vendor/nokia/qt/current merged eligible /branches/vendor/trolltech/qt/current 3-149
-
Property svn:mergeinfo
set to (toggle deleted branches)
-
trunk/qmake/project.cpp
r405 r561 2 2 ** 3 3 ** 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) 5 6 ** 6 7 ** This file is part of the qmake application of the Qt Toolkit. … … 21 22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 22 23 ** 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. 27 27 ** 28 28 ** GNU General Public License Usage … … 34 34 ** met: http://www.gnu.org/copyleft/gpl.html. 35 35 ** 36 ** If you are unsure which license is appropriate for your use, please37 ** 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. 38 38 ** $QT_END_LICENSE$ 39 39 ** … … 44 44 #include "option.h" 45 45 #include "cachekeys.h" 46 47 #include "epocroot.h" 46 48 47 49 #include <qdatetime.h> … … 58 60 #include <sys/utsname.h> 59 61 #elif defined(Q_OS_WIN32) 60 #include < Windows.h>62 #include <windows.h> 61 63 #elif defined(Q_OS_OS2) 62 64 #include <qt_os2.h> … … 79 81 E_SPRINTF, E_JOIN, E_SPLIT, E_BASENAME, E_DIRNAME, E_SECTION, 80 82 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 }; 82 85 QMap<QString, ExpandFunc> qmake_expandFunctions() 83 86 { … … 110 113 qmake_expand_functions->insert("prompt", E_PROMPT); 111 114 qmake_expand_functions->insert("replace", E_REPLACE); 115 qmake_expand_functions->insert("size", E_SIZE); 112 116 } 113 117 return *qmake_expand_functions; … … 155 159 return *qmake_test_functions; 156 160 } 157 158 QT_END_NAMESPACE159 160 #ifdef QTSCRIPT_SUPPORT161 #include "qscriptvalue.h"162 #include "qscriptengine.h"163 #include "qscriptvalueiterator.h"164 165 QT_BEGIN_NAMESPACE166 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_NAMESPACE238 239 #endif240 241 QT_BEGIN_NAMESPACE242 161 243 162 struct parser_info { … … 591 510 } 592 511 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 593 575 /* 594 576 1) environment variable QMAKEFEATURES (as separated by colons) … … 617 599 break; 618 600 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 } 621 608 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 } 624 616 case Option::TARG_OS2_MODE: 625 617 concat << base_concat + QDir::separator() + "os2"; … … 628 620 concat << base_concat + QDir::separator() + "mac"; 629 621 concat << base_concat + QDir::separator() + "mac9"; 630 break;631 case Option::TARG_QNX6_MODE: //also a unix632 concat << base_concat + QDir::separator() + "qnx6";633 concat << base_concat + QDir::separator() + "unix";634 622 break; 635 623 } … … 1481 1469 return false; 1482 1470 } 1471 1472 init_symbian(base_vars); 1473 1483 1474 if(Option::mkfile::do_cache && !Option::mkfile::cachefile.isEmpty()) { 1484 1475 debug_msg(1, "QMAKECACHE file: reading %s", Option::mkfile::cachefile.toLatin1().constData()); … … 1527 1518 if(cmd & ReadProFile) { // parse project file 1528 1519 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; 1531 1522 if(!read(pfile, vars)) 1532 1523 return false; … … 1615 1606 return false; 1616 1607 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 1617 1620 //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 || 1619 1622 Option::target_mode == Option::TARG_UNIX_MODE) && x == "unix") 1620 return true;1623 return !isForSymbian(); 1621 1624 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(); 1625 1626 else if(Option::target_mode == Option::TARG_MAC9_MODE && x == "mac9") 1626 return true;1627 return !isForSymbian(); 1627 1628 else if((Option::target_mode == Option::TARG_MAC9_MODE || Option::target_mode == Option::TARG_MACX_MODE) && 1628 1629 x == "mac") 1629 return true;1630 return !isForSymbian(); 1630 1631 else if(Option::target_mode == Option::TARG_WIN_MODE && x == "win32") 1631 return true;1632 return !isForSymbian(); 1632 1633 else if(Option::target_mode == Option::TARG_OS2_MODE && x == "os2") 1633 1634 return true; 1634 1635 QRegExp re(x, Qt::CaseSensitive, QRegExp::Wildcard); 1635 static QString spec;1636 if(spec.isEmpty())1637 spec = QFileInfo(Option::mkfile::qmakespec).fileName();1638 1636 if((regex && re.exactMatch(spec)) || (!regex && spec == x)) 1639 1637 return true; … … 1723 1721 static QStringList *feature_roots = 0; 1724 1722 if(!feature_roots) { 1723 init_symbian(base_vars); 1725 1724 feature_roots = new QStringList(qmake_feature_paths(prop)); 1726 1725 qmakeAddCacheClear(qmakeDeleteCacheClear_QStringList, (void**)&feature_roots); … … 1808 1807 parser_info pi = parser; 1809 1808 if(format == JSFormat) { 1810 #ifdef QTSCRIPT_SUPPORT1811 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 #else1828 1809 warn_msg(WarnParser, "%s:%d: QtScript support disabled for %s.", 1829 1810 pi.file.toLatin1().constData(), pi.line_no, orig_file.toLatin1().constData()); 1830 #endif1831 1811 } else { 1832 1812 QStack<ScopeBlock> sc = scope_blocks; … … 2165 2145 QMakeProjectEnv env(place); 2166 2146 char buff[256]; 2167 FILE *proc = QT_POPEN(args[0].toLatin1(), "r");2168 2147 bool singleLine = true; 2169 2148 if(args.count() > 1) 2170 2149 singleLine = (args[1].toLower() == "true"); 2171 2150 QString output; 2151 FILE *proc = QT_POPEN(args[0].toLatin1(), "r"); 2172 2152 while(proc && !feof(proc)) { 2173 2153 int read_in = int(fread(buff, 1, 255, proc)); … … 2318 2298 } 2319 2299 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; } 2320 2310 default: { 2321 #ifdef QTSCRIPT_SUPPORT2322 {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 #endif2334 2311 fprintf(stderr, "%s:%d: Unknown replace function: %s\n", 2335 2312 parser.file.toLatin1().constData(), parser.line_no, … … 2413 2390 int lhs_int = lhs.toInt(&ok); 2414 2391 if(ok) { 2415 if(func == "greaterThan")2392 if(func_t == T_GREATERTHAN) 2416 2393 return lhs_int > rhs_int; 2417 2394 return lhs_int < rhs_int; … … 2708 2685 QString parseInto; 2709 2686 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) { 2712 2689 if(func_t == T_INCLUDE) { 2713 2690 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 } 2714 2696 } else { 2715 2697 QString sarg = args[1]; … … 2753 2735 warn_msg(WarnParser, "%s:%d: Duplicate of loaded feature %s", 2754 2736 parser.file.toLatin1().constData(), parser.line_no, file.toLatin1().constData()); 2755 } else if(stat == IncludeNoExist && include_statement) {2756 warn_msg(Warn Parser, "%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", 2757 2739 parser.file.toLatin1().constData(), parser.line_no, file.toLatin1().constData()); 2758 2740 return false; … … 2797 2779 return true; } 2798 2780 default: 2799 #ifdef QTSCRIPT_SUPPORT2800 {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 #endif2813 2781 fprintf(stderr, "%s:%d: Unknown test function: %s\n", parser.file.toLatin1().constData(), parser.line_no, 2814 2782 func.toLatin1().constData()); … … 3126 3094 } else if(type == "name") { 3127 3095 DWORD name_length = 1024; 3128 TCHARname[1024];3129 if (GetComputerName(name, &name_length))3130 ret = QString::from Utf16((ushort*)name, name_length);3096 wchar_t name[1024]; 3097 if (GetComputerName(name, &name_length)) 3098 ret = QString::fromWCharArray(name); 3131 3099 } else if(type == "version" || type == "version_string") { 3132 3100 QSysInfo::WinVersion ver = QSysInfo::WindowsVersion; … … 3225 3193 if (place[var].isEmpty()) 3226 3194 return values("DIR_SEPARATOR", place); 3195 } else if (var == QLatin1String("EPOCROOT")) { 3196 if (place[var].isEmpty()) 3197 place[var] = QStringList(epocRoot()); 3227 3198 } 3228 3199 //qDebug("REPLACE [%s]->[%s]", qPrintable(var), qPrintable(place[var].join("::")));
Note:
See TracChangeset
for help on using the changeset viewer.