fix somewhat common edge case in $$shadowed()
authorOswald Buddenhagen <oswald.buddenhagen@nokia.com>
Sun, 24 Jun 2012 15:22:23 +0000 (17:22 +0200)
committerQt by Nokia <qt-info@nokia.com>
Tue, 26 Jun 2012 06:14:17 +0000 (08:14 +0200)
if source and build dir are direct children of the common root and we
are shadowing the top-level source dir, there is of course no trailing
slash to match.

Change-Id: I8a34a6a72d16cb21d77d056e037235af9b32a008
Reviewed-by: Davide Pesavento <davidepesa@gmail.com>
Reviewed-by: Andreas Hartmetz <ahartmetz@gmail.com>
Reviewed-by: Joerg Bornemann <joerg.bornemann@nokia.com>
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@nokia.com>
qmake/option.cpp
qmake/project.cpp
tests/auto/tools/qmake/testdata/functions/functions.pro

index 6eeddfd..714aebe 100644 (file)
@@ -604,10 +604,10 @@ void Option::prepareProject(const QString &pfile)
             dstpath += QLatin1Char('/');
         int srcLen = srcpath.length();
         int dstLen = dstpath.length();
-        int lastSl = 0;
+        int lastSl = -1;
         while (++lastSl, srcpath.at(--srcLen) == dstpath.at(--dstLen))
             if (srcpath.at(srcLen) == QLatin1Char('/'))
-                lastSl = 1;
+                lastSl = 0;
         mkfile::source_root = srcpath.left(srcLen + lastSl);
         mkfile::build_root = dstpath.left(dstLen + lastSl);
     } else {
index 6e79f7a..360c095 100644 (file)
@@ -2685,10 +2685,13 @@ QMakeProject::doProjectExpand(QString func, QList<QStringList> args_list,
         break;
     case E_SHADOWED: {
         QString val = QDir::cleanPath(QFileInfo(args.at(0)).absoluteFilePath());
-        if (Option::mkfile::source_root.isEmpty())
+        if (Option::mkfile::source_root.isEmpty()) {
             ret += val;
-        else if (val.startsWith(Option::mkfile::source_root))
+        } else if (val.startsWith(Option::mkfile::source_root)
+                   && (val.length() == Option::mkfile::source_root.length()
+                       || val.at(Option::mkfile::source_root.length()) == QLatin1Char('/'))) {
             ret += Option::mkfile::build_root + val.mid(Option::mkfile::source_root.length());
+        }
         break; }
     case E_ABSOLUTE_PATH:
         if (args.count() > 2)
index 9ec2ffe..daab1fd 100644 (file)
@@ -113,6 +113,7 @@ out = "easy \"less easy\" sca\$\${LITERAL_HASH}ry crazy\$\$escape_expand(\\\\t\\
 testReplace($$val_escape(in), $$out, "val_escape")
 
 testReplace($$shadowed($$PWD/something), $$OUT_PWD/something, "shadowed")
+testReplace($$shadowed($$PWD), $$OUT_PWD, "shadowed (take 2)")
 
 #format_number
 spc = " "