qmake: centralize resolution of file name arguments to qmake functions

Change-Id: Id867e4653b0ec506332174ae67c9ee21e722c1e3
Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
This commit is contained in:
Oswald Buddenhagen 2017-08-14 11:58:21 +02:00
parent 811d8b82b5
commit d68016c739
2 changed files with 23 additions and 17 deletions

View File

@ -579,6 +579,20 @@ void QMakeEvaluator::populateDeps(
} }
} }
QString QMakeEvaluator::filePathArg0(const ProStringList &args)
{
QString fn = resolvePath(args.at(0).toQString(m_tmp1));
fn.detach();
return fn;
}
QString QMakeEvaluator::filePathEnvArg0(const ProStringList &args)
{
QString fn = resolvePath(m_option->expandEnvVars(args.at(0).toQString(m_tmp1)));
fn.detach();
return fn;
}
QMakeEvaluator::VisitReturn QMakeEvaluator::evaluateBuiltinExpand( QMakeEvaluator::VisitReturn QMakeEvaluator::evaluateBuiltinExpand(
const QMakeBuiltin &adef, const ProKey &func, const ProStringList &args, ProStringList &ret) const QMakeBuiltin &adef, const ProKey &func, const ProStringList &args, ProStringList &ret)
{ {
@ -815,9 +829,6 @@ QMakeEvaluator::VisitReturn QMakeEvaluator::evaluateBuiltinExpand(
ret.append(ProString(QString::number(args.at(0).size()))); ret.append(ProString(QString::number(args.at(0).size())));
break; break;
case E_CAT: { case E_CAT: {
QString fn = resolvePath(m_option->expandEnvVars(args.at(0).toQString(m_tmp1)));
fn.detach();
bool blob = false; bool blob = false;
bool lines = false; bool lines = false;
bool singleLine = true; bool singleLine = true;
@ -829,7 +840,7 @@ QMakeEvaluator::VisitReturn QMakeEvaluator::evaluateBuiltinExpand(
else if (!args.at(1).compare(QLatin1String("lines"), Qt::CaseInsensitive)) else if (!args.at(1).compare(QLatin1String("lines"), Qt::CaseInsensitive))
lines = true; lines = true;
} }
QString fn = filePathEnvArg0(args);
QFile qfile(fn); QFile qfile(fn);
if (qfile.open(QIODevice::ReadOnly)) { if (qfile.open(QIODevice::ReadOnly)) {
QTextStream stream(&qfile); QTextStream stream(&qfile);
@ -852,8 +863,7 @@ QMakeEvaluator::VisitReturn QMakeEvaluator::evaluateBuiltinExpand(
} }
case E_FROMFILE: { case E_FROMFILE: {
ProValueMap vars; ProValueMap vars;
QString fn = resolvePath(m_option->expandEnvVars(args.at(0).toQString(m_tmp1))); QString fn = filePathEnvArg0(args);
fn.detach();
if (evaluateFileInto(fn, &vars, LoadProOnly) == ReturnTrue) if (evaluateFileInto(fn, &vars, LoadProOnly) == ReturnTrue)
ret = vars.value(map(args.at(1))); ret = vars.value(map(args.at(1)));
break; break;
@ -1301,8 +1311,7 @@ QMakeEvaluator::VisitReturn QMakeEvaluator::evaluateBuiltinConditional(
} }
case T_INFILE: { case T_INFILE: {
ProValueMap vars; ProValueMap vars;
QString fn = resolvePath(m_option->expandEnvVars(args.at(0).toQString(m_tmp1))); QString fn = filePathEnvArg0(args);
fn.detach();
VisitReturn ok = evaluateFileInto(fn, &vars, LoadProOnly); VisitReturn ok = evaluateFileInto(fn, &vars, LoadProOnly);
if (ok != ReturnTrue) if (ok != ReturnTrue)
return ok; return ok;
@ -1488,8 +1497,7 @@ QMakeEvaluator::VisitReturn QMakeEvaluator::evaluateBuiltinConditional(
if (args.count() >= 3 && isTrue(args.at(2))) if (args.count() >= 3 && isTrue(args.at(2)))
flags = LoadSilent; flags = LoadSilent;
} }
QString fn = resolvePath(m_option->expandEnvVars(args.at(0).toQString(m_tmp1))); QString fn = filePathEnvArg0(args);
fn.detach();
VisitReturn ok; VisitReturn ok;
if (parseInto.isEmpty()) { if (parseInto.isEmpty()) {
ok = evaluateFileChecked(fn, QMakeHandler::EvalIncludeFile, LoadProOnly | flags); ok = evaluateFileChecked(fn, QMakeHandler::EvalIncludeFile, LoadProOnly | flags);
@ -1583,8 +1591,7 @@ QMakeEvaluator::VisitReturn QMakeEvaluator::evaluateBuiltinConditional(
return returnBool(values(map(args.at(0))).isEmpty()); return returnBool(values(map(args.at(0))).isEmpty());
} }
case T_EXISTS: { case T_EXISTS: {
const QString &file = resolvePath(m_option->expandEnvVars(args.at(0).toQString(m_tmp1))); QString file = filePathEnvArg0(args);
// Don't use VFS here: // Don't use VFS here:
// - it supports neither listing nor even directories // - it supports neither listing nor even directories
// - it's unlikely that somebody would test for files they created themselves // - it's unlikely that somebody would test for files they created themselves
@ -1592,7 +1599,6 @@ QMakeEvaluator::VisitReturn QMakeEvaluator::evaluateBuiltinConditional(
return ReturnTrue; return ReturnTrue;
int slsh = file.lastIndexOf(QLatin1Char('/')); int slsh = file.lastIndexOf(QLatin1Char('/'));
QString fn = file.mid(slsh+1); QString fn = file.mid(slsh+1);
fn.detach();
if (fn.contains(QLatin1Char('*')) || fn.contains(QLatin1Char('?'))) { if (fn.contains(QLatin1Char('*')) || fn.contains(QLatin1Char('?'))) {
QString dirstr = file.left(slsh+1); QString dirstr = file.left(slsh+1);
dirstr.detach(); dirstr.detach();
@ -1604,8 +1610,7 @@ QMakeEvaluator::VisitReturn QMakeEvaluator::evaluateBuiltinConditional(
} }
case T_MKPATH: { case T_MKPATH: {
#ifdef PROEVALUATOR_FULL #ifdef PROEVALUATOR_FULL
QString fn = resolvePath(args.at(0).toQString(m_tmp1)); QString fn = filePathArg0(args);
fn.detach();
if (!QDir::current().mkpath(fn)) { if (!QDir::current().mkpath(fn)) {
evalError(fL1S("Cannot create directory %1.").arg(QDir::toNativeSeparators(fn))); evalError(fL1S("Cannot create directory %1.").arg(QDir::toNativeSeparators(fn)));
return ReturnFalse; return ReturnFalse;
@ -1635,8 +1640,7 @@ QMakeEvaluator::VisitReturn QMakeEvaluator::evaluateBuiltinConditional(
} }
} }
} }
QString path = resolvePath(args.at(0).toQString(m_tmp1)); QString path = filePathArg0(args);
path.detach(); // make sure to not leak m_tmp1 into the map of written files.
return writeFile(QString(), path, mode, flags, contents); return writeFile(QString(), path, mode, flags, contents);
} }
case T_TOUCH: { case T_TOUCH: {

View File

@ -188,6 +188,8 @@ public:
int currentFileId() const; int currentFileId() const;
QString resolvePath(const QString &fileName) const QString resolvePath(const QString &fileName) const
{ return QMakeInternal::IoUtils::resolvePath(currentDirectory(), fileName); } { return QMakeInternal::IoUtils::resolvePath(currentDirectory(), fileName); }
QString filePathArg0(const ProStringList &args);
QString filePathEnvArg0(const ProStringList &args);
VisitReturn evaluateFile(const QString &fileName, QMakeHandler::EvalFileType type, VisitReturn evaluateFile(const QString &fileName, QMakeHandler::EvalFileType type,
LoadFlags flags); LoadFlags flags);