diff options
Diffstat (limited to 'src/linguist/shared/qmakeevaluator.cpp')
-rw-r--r-- | src/linguist/shared/qmakeevaluator.cpp | 126 |
1 files changed, 71 insertions, 55 deletions
diff --git a/src/linguist/shared/qmakeevaluator.cpp b/src/linguist/shared/qmakeevaluator.cpp index 404974cc6..33befc0f8 100644 --- a/src/linguist/shared/qmakeevaluator.cpp +++ b/src/linguist/shared/qmakeevaluator.cpp @@ -40,10 +40,10 @@ ****************************************************************************/ #include "qmakeevaluator.h" +#include "qmakeevaluator_p.h" #include "qmakeglobals.h" #include "qmakeparser.h" -#include "qmakeevaluator_p.h" #include "ioutils.h" #include <qbytearray.h> @@ -1130,10 +1130,10 @@ bool QMakeEvaluator::prepareProject(const QString &inDir) bool QMakeEvaluator::loadSpecInternal() { - if (!evaluateFeatureFile(QLatin1String("spec_pre.prf"))) + if (evaluateFeatureFile(QLatin1String("spec_pre.prf")) != ReturnTrue) return false; QString spec = m_qmakespec + QLatin1String("/qmake.conf"); - if (!evaluateFile(spec, QMakeHandler::EvalConfigFile, LoadProOnly)) { + if (evaluateFile(spec, QMakeHandler::EvalConfigFile, LoadProOnly) != ReturnTrue) { evalError(fL1S("Could not read qmake configuration file %1.").arg(spec)); return false; } @@ -1157,7 +1157,7 @@ bool QMakeEvaluator::loadSpecInternal() #endif valuesRef(ProKey("QMAKESPEC")) << ProString(m_qmakespec); m_qmakespecName = IoUtils::fileName(m_qmakespec).toString(); - if (!evaluateFeatureFile(QLatin1String("spec_post.prf"))) + if (evaluateFeatureFile(QLatin1String("spec_post.prf")) != ReturnTrue) return false; // The MinGW and x-build specs may change the separator; $$shell_{path,quote}() need it m_dirSep = first(ProKey("QMAKE_DIR_SEP")); @@ -1173,17 +1173,20 @@ bool QMakeEvaluator::loadSpec() QMakeEvaluator evaluator(m_option, m_parser, m_handler); if (!m_superfile.isEmpty()) { valuesRef(ProKey("_QMAKE_SUPER_CACHE_")) << ProString(m_superfile); - if (!evaluator.evaluateFile(m_superfile, QMakeHandler::EvalConfigFile, LoadProOnly)) + if (evaluator.evaluateFile( + m_superfile, QMakeHandler::EvalConfigFile, LoadProOnly) != ReturnTrue) return false; } if (!m_conffile.isEmpty()) { valuesRef(ProKey("_QMAKE_CONF_")) << ProString(m_conffile); - if (!evaluator.evaluateFile(m_conffile, QMakeHandler::EvalConfigFile, LoadProOnly)) + if (evaluator.evaluateFile( + m_conffile, QMakeHandler::EvalConfigFile, LoadProOnly) != ReturnTrue) return false; } if (!m_cachefile.isEmpty()) { valuesRef(ProKey("_QMAKE_CACHE_")) << ProString(m_cachefile); - if (!evaluator.evaluateFile(m_cachefile, QMakeHandler::EvalConfigFile, LoadProOnly)) + if (evaluator.evaluateFile( + m_cachefile, QMakeHandler::EvalConfigFile, LoadProOnly) != ReturnTrue) return false; } if (qmakespec.isEmpty()) { @@ -1219,17 +1222,17 @@ bool QMakeEvaluator::loadSpec() m_qmakespec = QDir::cleanPath(qmakespec); if (!m_superfile.isEmpty() - && !evaluateFile(m_superfile, QMakeHandler::EvalConfigFile, LoadProOnly)) { + && evaluateFile(m_superfile, QMakeHandler::EvalConfigFile, LoadProOnly) != ReturnTrue) { return false; } if (!loadSpecInternal()) return false; if (!m_conffile.isEmpty() - && !evaluateFile(m_conffile, QMakeHandler::EvalConfigFile, LoadProOnly)) { + && evaluateFile(m_conffile, QMakeHandler::EvalConfigFile, LoadProOnly) != ReturnTrue) { return false; } if (!m_cachefile.isEmpty() - && !evaluateFile(m_cachefile, QMakeHandler::EvalConfigFile, LoadProOnly)) { + && evaluateFile(m_cachefile, QMakeHandler::EvalConfigFile, LoadProOnly) != ReturnTrue) { return false; } return true; @@ -1239,10 +1242,11 @@ void QMakeEvaluator::setupProject() { setTemplate(); ProValueMap &vars = m_valuemapStack.top(); - vars[ProKey("TARGET")] << ProString(QFileInfo(currentFileName()).baseName()); - vars[ProKey("_PRO_FILE_")] << ProString(currentFileName()); - vars[ProKey("_PRO_FILE_PWD_")] << ProString(currentDirectory()); - vars[ProKey("OUT_PWD")] << ProString(m_outputDir); + ProFile *proFile = currentProFile(); + vars[ProKey("TARGET")] << ProString(QFileInfo(currentFileName()).baseName()).setSource(proFile); + vars[ProKey("_PRO_FILE_")] << ProString(currentFileName()).setSource(proFile); + vars[ProKey("_PRO_FILE_PWD_")] << ProString(currentDirectory()).setSource(proFile); + vars[ProKey("OUT_PWD")] << ProString(m_outputDir).setSource(proFile); } void QMakeEvaluator::evaluateCommand(const QString &cmds, const QString &where) @@ -1259,7 +1263,7 @@ void QMakeEvaluator::evaluateCommand(const QString &cmds, const QString &where) } } -void QMakeEvaluator::evaluateConfigFeatures() +QMakeEvaluator::VisitReturn QMakeEvaluator::evaluateConfigFeatures() { QSet<QString> processed; forever { @@ -1270,7 +1274,10 @@ void QMakeEvaluator::evaluateConfigFeatures() if (!processed.contains(config)) { config.detach(); processed.insert(config); - if (evaluateFeatureFile(config, true)) { + VisitReturn vr = evaluateFeatureFile(config, true); + if (vr == ReturnError) + return vr; + if (vr == ReturnTrue) { finished = false; break; } @@ -1279,6 +1286,7 @@ void QMakeEvaluator::evaluateConfigFeatures() if (finished) break; } + return ReturnTrue; } QMakeEvaluator::VisitReturn QMakeEvaluator::visitProFile( @@ -1349,11 +1357,11 @@ QMakeEvaluator::VisitReturn QMakeEvaluator::visitProFile( loadDefaults(); } -#ifdef QT_BUILD_QMAKE for (ProValueMap::ConstIterator it = m_extraVars.constBegin(); it != m_extraVars.constEnd(); ++it) m_valuemapStack.first().insert(it.key(), it.value()); -#endif + + VisitReturn vr; m_handler->aboutToEval(currentProFile(), pro, type); m_profileStack.push(pro); @@ -1361,41 +1369,43 @@ QMakeEvaluator::VisitReturn QMakeEvaluator::visitProFile( if (flags & LoadPreFiles) { setupProject(); - evaluateFeatureFile(QLatin1String("default_pre.prf")); + if ((vr = evaluateFeatureFile(QLatin1String("default_pre.prf"))) == ReturnError) + goto failed; evaluateCommand(m_option->precmds, fL1S("(command line)")); -#ifdef QT_BUILD_QMAKE // After user configs, to override them if (!m_extraConfigs.isEmpty()) - evaluateCommand("CONFIG += " + m_extraConfigs.join(' '), fL1S("(extra configs)")); -#endif + evaluateCommand(fL1S("CONFIG += ") + m_extraConfigs.join(QLatin1Char(' ')), fL1S("(extra configs)")); } debugMsg(1, "visiting file %s", qPrintable(pro->fileName())); - visitProBlock(pro, pro->tokPtr()); + if ((vr = visitProBlock(pro, pro->tokPtr())) == ReturnError) + goto failed; debugMsg(1, "done visiting file %s", qPrintable(pro->fileName())); if (flags & LoadPostFiles) { evaluateCommand(m_option->postcmds, fL1S("(command line -after)")); -#ifdef QT_BUILD_QMAKE // Again, to ensure the project does not mess with us. // Specifically, do not allow a project to override debug/release within a // debug_and_release build pass - it's too late for that at this point anyway. if (!m_extraConfigs.isEmpty()) - evaluateCommand("CONFIG += " + m_extraConfigs.join(' '), fL1S("(extra configs)")); -#endif + evaluateCommand(fL1S("CONFIG += ") + m_extraConfigs.join(QLatin1Char(' ')), fL1S("(extra configs)")); - evaluateFeatureFile(QLatin1String("default_post.prf")); + if ((vr = evaluateFeatureFile(QLatin1String("default_post.prf"))) == ReturnError) + goto failed; - evaluateConfigFeatures(); + if ((vr = evaluateConfigFeatures()) == ReturnError) + goto failed; } + vr = ReturnTrue; + failed: m_profileStack.pop(); valuesRef(ProKey("PWD")) = ProStringList(ProString(currentDirectory())); m_handler->doneWithEval(currentProFile()); - return ReturnTrue; + return vr; } @@ -1602,14 +1612,14 @@ QList<ProStringList> QMakeEvaluator::prepareFunctionArgs(const ushort *&tokPtr) } ProStringList QMakeEvaluator::evaluateFunction( - const ProFunctionDef &func, const QList<ProStringList> &argumentsList, bool *ok) + const ProFunctionDef &func, const QList<ProStringList> &argumentsList, VisitReturn *ok) { - bool oki; + VisitReturn vr; ProStringList ret; if (m_valuemapStack.count() >= 100) { evalError(fL1S("Ran into infinite recursion (depth > 100).")); - oki = false; + vr = ReturnFalse; } else { m_valuemapStack.push(ProValueMap()); m_locationStack.push(m_current); @@ -1620,8 +1630,9 @@ ProStringList QMakeEvaluator::evaluateFunction( m_valuemapStack.top()[ProKey(QString::number(i+1))] = argumentsList[i]; } m_valuemapStack.top()[statics.strARGS] = args; - VisitReturn vr = visitProBlock(func.pro(), func.tokPtr()); - oki = (vr != ReturnFalse && vr != ReturnError); // True || Return + vr = visitProBlock(func.pro(), func.tokPtr()); + if (vr == ReturnReturn) + vr = ReturnTrue; ret = m_returnValue; m_returnValue.clear(); @@ -1629,8 +1640,8 @@ ProStringList QMakeEvaluator::evaluateFunction( m_valuemapStack.pop(); } if (ok) - *ok = oki; - if (oki) + *ok = vr; + if (vr == ReturnTrue) return ret; return ProStringList(); } @@ -1639,14 +1650,15 @@ QMakeEvaluator::VisitReturn QMakeEvaluator::evaluateBoolFunction( const ProFunctionDef &func, const QList<ProStringList> &argumentsList, const ProString &function) { - bool ok; - ProStringList ret = evaluateFunction(func, argumentsList, &ok); - if (ok) { + VisitReturn vr; + ProStringList ret = evaluateFunction(func, argumentsList, &vr); + if (vr == ReturnTrue) { if (ret.isEmpty()) return ReturnTrue; if (ret.at(0) != statics.strfalse) { if (ret.at(0) == statics.strtrue) return ReturnTrue; + bool ok; int val = ret.at(0).toQString(m_tmp1).toInt(&ok); if (ok) { if (val) @@ -1657,8 +1669,9 @@ QMakeEvaluator::VisitReturn QMakeEvaluator::evaluateBoolFunction( .arg(ret.join(QLatin1String(" :: ")))); } } + return ReturnFalse; } - return ReturnFalse; + return vr; } QMakeEvaluator::VisitReturn QMakeEvaluator::evaluateConditionalFunction( @@ -1791,16 +1804,16 @@ ProString QMakeEvaluator::first(const ProKey &variableName) const return ProString(); } -bool QMakeEvaluator::evaluateFile( +QMakeEvaluator::VisitReturn QMakeEvaluator::evaluateFile( const QString &fileName, QMakeHandler::EvalFileType type, LoadFlags flags) { if (ProFile *pro = m_parser->parsedProFile(fileName, true)) { m_locationStack.push(m_current); - bool ok = (visitProFile(pro, type, flags) == ReturnTrue); + VisitReturn ok = visitProFile(pro, type, flags); m_current = m_locationStack.pop(); pro->deref(); #ifdef PROEVALUATOR_FULL - if (ok) { + if (ok == ReturnTrue) { ProStringList &iif = m_valuemapStack.first()[ProKey("QMAKE_INTERNAL_INCLUDED_FILES")]; ProString ifn(fileName); if (!iif.contains(ifn)) @@ -1811,27 +1824,28 @@ bool QMakeEvaluator::evaluateFile( } else { if (!(flags & LoadSilent) && !IoUtils::exists(fileName)) evalError(fL1S("WARNING: Include file %1 not found").arg(fileName)); - return false; + return ReturnFalse; } } -bool QMakeEvaluator::evaluateFileChecked( +QMakeEvaluator::VisitReturn QMakeEvaluator::evaluateFileChecked( const QString &fileName, QMakeHandler::EvalFileType type, LoadFlags flags) { if (fileName.isEmpty()) - return false; + return ReturnFalse; QMakeEvaluator *ref = this; do { foreach (const ProFile *pf, ref->m_profileStack) if (pf->fileName() == fileName) { evalError(fL1S("Circular inclusion of %1.").arg(fileName)); - return false; + return ReturnFalse; } } while ((ref = ref->m_caller)); return evaluateFile(fileName, type, flags); } -bool QMakeEvaluator::evaluateFeatureFile(const QString &fileName, bool silent) +QMakeEvaluator::VisitReturn QMakeEvaluator::evaluateFeatureFile( + const QString &fileName, bool silent) { QString fn = fileName; if (!fn.endsWith(QLatin1String(".prf"))) @@ -1862,7 +1876,7 @@ bool QMakeEvaluator::evaluateFeatureFile(const QString &fileName, bool silent) #endif if (!silent) evalError(fL1S("Cannot find feature %1").arg(fileName)); - return false; + return ReturnFalse; cool: ProStringList &already = valuesRef(ProKey("QMAKE_INTERNAL_INCLUDED_FEATURES")); @@ -1870,7 +1884,7 @@ bool QMakeEvaluator::evaluateFeatureFile(const QString &fileName, bool silent) if (already.contains(afn)) { if (!silent) languageWarning(fL1S("Feature %1 already included").arg(fileName)); - return true; + return ReturnTrue; } already.append(afn); @@ -1880,7 +1894,7 @@ bool QMakeEvaluator::evaluateFeatureFile(const QString &fileName, bool silent) #endif // The path is fully normalized already. - bool ok = evaluateFile(fn, QMakeHandler::EvalFeatureFile, LoadProOnly); + VisitReturn ok = evaluateFile(fn, QMakeHandler::EvalFeatureFile, LoadProOnly); #ifdef PROEVALUATOR_CUMULATIVE m_cumulative = cumulative; @@ -1888,14 +1902,16 @@ bool QMakeEvaluator::evaluateFeatureFile(const QString &fileName, bool silent) return ok; } -bool QMakeEvaluator::evaluateFileInto(const QString &fileName, ProValueMap *values, LoadFlags flags) +QMakeEvaluator::VisitReturn QMakeEvaluator::evaluateFileInto( + const QString &fileName, ProValueMap *values, LoadFlags flags) { QMakeEvaluator visitor(m_option, m_parser, m_handler); visitor.m_caller = this; visitor.m_outputDir = m_outputDir; visitor.m_featureRoots = m_featureRoots; - if (!visitor.evaluateFileChecked(fileName, QMakeHandler::EvalAuxFile, flags)) - return false; + VisitReturn ret = visitor.evaluateFileChecked(fileName, QMakeHandler::EvalAuxFile, flags); + if (ret != ReturnTrue) + return ret; *values = visitor.m_valuemapStack.top(); #ifdef PROEVALUATOR_FULL ProKey qiif("QMAKE_INTERNAL_INCLUDED_FILES"); @@ -1904,7 +1920,7 @@ bool QMakeEvaluator::evaluateFileInto(const QString &fileName, ProValueMap *valu if (!iif.contains(ifn)) iif << ifn; #endif - return true; + return ReturnTrue; } void QMakeEvaluator::message(int type, const QString &msg) const |