add $$shadowed() function

follow suit with qmake ...

Change-Id: Ic97576eaf74dfd58e8d8cd2f8034dac3963b92c4
Reviewed-by: Daniel Teske <daniel.teske@nokia.com>
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@nokia.com>
This commit is contained in:
Oswald Buddenhagen
2012-07-25 19:10:07 +02:00
parent b475ae43de
commit 187751f967
5 changed files with 43 additions and 1 deletions

View File

@@ -945,6 +945,7 @@ QtSupport::ProFileReader *Qt4Project::createProFileReader(Qt4ProFileNode *qt4Pro
m_qmakeGlobals->qmake_abslocation = QDir::cleanPath(qtVersion->qmakeCommand().toString());
m_qmakeGlobals->setProperties(qtVersion->versionInfo());
}
m_qmakeGlobals->setDirectories(m_rootProjectNode->sourceDir(), m_rootProjectNode->buildDir());
m_qmakeGlobals->sysroot = systemRoot;
Utils::Environment::const_iterator eit = env.constBegin(), eend = env.constEnd();

View File

@@ -76,7 +76,8 @@ enum ExpandFunc {
E_SPRINTF, E_FORMAT_NUMBER, E_JOIN, E_SPLIT, E_BASENAME, E_DIRNAME, E_SECTION,
E_FIND, E_SYSTEM, E_UNIQUE, E_REVERSE, E_QUOTE, E_ESCAPE_EXPAND,
E_UPPER, E_LOWER, E_FILES, E_PROMPT, E_RE_ESCAPE, E_VAL_ESCAPE,
E_REPLACE, E_SORT_DEPENDS, E_RESOLVE_DEPENDS, E_ENUMERATE_VARS
E_REPLACE, E_SORT_DEPENDS, E_RESOLVE_DEPENDS, E_ENUMERATE_VARS,
E_SHADOWED
};
enum TestFunc {
@@ -123,6 +124,7 @@ void QMakeEvaluator::initFunctionStatics()
{ "sort_depends", E_SORT_DEPENDS },
{ "resolve_depends", E_RESOLVE_DEPENDS },
{ "enumerate_vars", E_ENUMERATE_VARS },
{ "shadowed", E_SHADOWED },
};
for (unsigned i = 0; i < sizeof(expandInits)/sizeof(expandInits[0]); ++i)
statics.expands.insert(ProString(expandInits[i].name), expandInits[i].func);
@@ -819,6 +821,21 @@ ProStringList QMakeEvaluator::evaluateExpandFunction(
foreach (const ProString &key, keys)
ret << key;
break; }
case E_SHADOWED:
if (args.count() != 1) {
evalError(fL1S("shadowed(path) requires one argument."));
} else {
QString val = resolvePath(args.at(0).toQString(m_tmp1));
if (m_option->source_root.isEmpty()) {
ret += ProString(val, NoHash);
} else if (val.startsWith(m_option->source_root)
&& (val.length() == m_option->source_root.length()
|| val.at(m_option->source_root.length()) == QLatin1Char('/'))) {
ret += ProString(m_option->build_root + val.mid(m_option->source_root.length()),
NoHash).setSource(args.at(0));
}
}
break;
case E_INVALID:
evalError(fL1S("'%1' is not a recognized replace function.")
.arg(func.toQString(m_tmp1)));

View File

@@ -148,6 +148,26 @@ void QMakeGlobals::setCommandLineArguments(const QStringList &args)
postcmds = _postcmds.join(fL1S("\n"));
}
void QMakeGlobals::setDirectories(const QString &input_dir, const QString &output_dir)
{
if (input_dir != output_dir && !output_dir.isEmpty()) {
QString srcpath = input_dir;
if (!srcpath.endsWith(QLatin1Char('/')))
srcpath += QLatin1Char('/');
QString dstpath = output_dir;
if (!dstpath.endsWith(QLatin1Char('/')))
dstpath += QLatin1Char('/');
int srcLen = srcpath.length();
int dstLen = dstpath.length();
int lastSl = -1;
while (++lastSl, srcpath.at(--srcLen) == dstpath.at(--dstLen))
if (srcpath.at(srcLen) == QLatin1Char('/'))
lastSl = 0;
source_root = srcpath.left(srcLen + lastSl);
build_root = dstpath.left(dstLen + lastSl);
}
}
QString QMakeGlobals::getEnv(const QString &var) const
{
#ifndef QT_BOOTSTRAPPED

View File

@@ -99,6 +99,7 @@ public:
// -nocache, -cache, -spec, QMAKESPEC
// -set persistent value
void setCommandLineArguments(const QStringList &args);
void setDirectories(const QString &input_dir, const QString &output_dir);
#ifdef PROEVALUATOR_INIT_PROPS
bool initProperties();
#else
@@ -112,6 +113,8 @@ private:
QString getEnv(const QString &) const;
QStringList getPathListEnv(const QString &var) const;
QString source_root, build_root;
QString precmds, postcmds;
QHash<ProString, ProString> properties;

View File

@@ -168,6 +168,7 @@ int main(int argc, char **argv)
QString file = infi.absoluteFilePath();
QString in_pwd = infi.absolutePath();
QString out_pwd = (args.count() > 2) ? QFileInfo(args[2]).absoluteFilePath() : in_pwd;
option.setDirectories(in_pwd, out_pwd);
return evaluate(file, in_pwd, out_pwd, cumulative, &option, &parser, level);
}