fix error() not propagating through if()

if() would simply "downgrade" a fatal error to a false condition, which
is certainly not expected.

Change-Id: Ie9c54f2bddf588856498bf795007b341b7c9363a
Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
This commit is contained in:
Oswald Buddenhagen 2016-06-29 15:40:17 +02:00
parent 07d3cbbe84
commit b27d4835c2
5 changed files with 15 additions and 8 deletions

View File

@ -1221,8 +1221,8 @@ QMakeEvaluator::VisitReturn QMakeEvaluator::evaluateBuiltinConditional(
evalError(fL1S("if(condition) requires one argument."));
return ReturnFalse;
}
return returnBool(evaluateConditional(args.at(0).toQString(),
m_current.pro->fileName(), m_current.line));
return evaluateConditional(args.at(0).toQString(),
m_current.pro->fileName(), m_current.line);
}
case T_CONFIG: {
if (args.count() < 1 || args.count() > 2) {

View File

@ -1758,13 +1758,14 @@ ProStringList QMakeEvaluator::evaluateExpandFunction(
return ProStringList();
}
bool QMakeEvaluator::evaluateConditional(const QString &cond, const QString &where, int line)
QMakeEvaluator::VisitReturn QMakeEvaluator::evaluateConditional(
const QString &cond, const QString &where, int line)
{
bool ret = false;
VisitReturn ret = ReturnFalse;
ProFile *pro = m_parser->parsedProBlock(cond, where, line, QMakeParser::TestGrammar);
if (pro->isOk()) {
m_locationStack.push(m_current);
ret = visitProBlock(pro, pro->tokPtr()) == ReturnTrue;
ret = visitProBlock(pro, pro->tokPtr());
m_current = m_locationStack.pop();
}
pro->deref();
@ -1776,7 +1777,7 @@ void QMakeEvaluator::checkRequirements(const ProStringList &deps)
{
ProStringList &failed = valuesRef(ProKey("QMAKE_FAILED_REQUIREMENTS"));
foreach (const ProString &dep, deps)
if (!evaluateConditional(dep.toQString(), m_current.pro->fileName(), m_current.line))
if (evaluateConditional(dep.toQString(), m_current.pro->fileName(), m_current.line) != ReturnTrue)
failed << dep;
}
#endif

View File

@ -220,7 +220,7 @@ public:
ProStringList evaluateBuiltinExpand(int func_t, const ProKey &function, const ProStringList &args);
VisitReturn evaluateBuiltinConditional(int func_t, const ProKey &function, const ProStringList &args);
bool evaluateConditional(const QString &cond, const QString &where, int line = -1);
VisitReturn evaluateConditional(const QString &cond, const QString &where, int line = -1);
#ifdef PROEVALUATOR_FULL
void checkRequirements(const ProStringList &deps);
#endif

View File

@ -60,7 +60,7 @@ public:
ProString expand(const QString &v, const QString &file, int line);
QStringList expand(const ProKey &func, const QList<ProStringList> &args);
bool test(const QString &v, const QString &file, int line)
{ m_current.clear(); return evaluateConditional(v, file, line); }
{ m_current.clear(); return evaluateConditional(v, file, line) == ReturnTrue; }
bool test(const ProKey &func, const QList<ProStringList> &args);
bool isSet(const ProKey &v) const { return m_valuemapStack.first().contains(v); }

View File

@ -2103,6 +2103,12 @@ void tst_qmakelib::addTestFunctions(const QString &qindir)
<< "Project ERROR: World, you FAIL!"
<< false;
QTest::newRow("if(error())")
<< "if(error(\\'World, you FAIL!\\')): OK = 1\nOKE = 1"
<< "OK = UNDEF\nOKE = UNDEF"
<< "Project ERROR: World, you FAIL!"
<< false;
QTest::newRow("system()")
<< "system('"
#ifdef Q_OS_WIN