make TR_EXCLUDE work for SUBDIRS
authorOswald Buddenhagen <oswald.buddenhagen@digia.com>
Tue, 25 Jun 2013 15:44:35 +0000 (17:44 +0200)
committerThe Qt Project <gerrit-noreply@qt-project.org>
Wed, 7 Aug 2013 15:04:02 +0000 (17:04 +0200)
this is needed for excluding subprojects we have no direct control over,
e.g., git submodules.

note that unlike TR_EXCLUDE for files, this matches SUBDIRS entries, not
actual project file names. wildcards also work, though.

Change-Id: I1d0a0410a28af4a60f045ee5bbac34540c14f0bd
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@digia.com>
Reviewed-by: hjk <hjk121@nokiamail.com>
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@digia.com>
src/linguist/lupdate/main.cpp
tests/auto/linguist/lupdate/testdata/good/proparsingsubs/excluded/excluded.pro [new file with mode: 0644]
tests/auto/linguist/lupdate/testdata/good/proparsingsubs/excluded/main.cpp [new file with mode: 0644]
tests/auto/linguist/lupdate/testdata/good/proparsingsubs/project.pro

index 7229c9c..6af50f9 100644 (file)
@@ -312,6 +312,19 @@ static QStringList getSources(const ProFileEvaluator &visitor, const QString &pr
     return sourceFiles;
 }
 
+static void excludeProjects(const ProFileEvaluator &visitor, QStringList *subProjects)
+{
+    foreach (const QString &ex, visitor.values(QLatin1String("TR_EXCLUDE"))) {
+        QRegExp rx(ex, Qt::CaseSensitive, QRegExp::Wildcard);
+        for (QStringList::Iterator it = subProjects->begin(); it != subProjects->end(); ) {
+            if (rx.exactMatch(*it))
+                it = subProjects->erase(it);
+            else
+                ++it;
+        }
+    }
+}
+
 static void processSources(Translator &fetchedTor,
                            const QStringList &sourceFiles, ConversionData &cd)
 {
@@ -380,9 +393,11 @@ static void processProject(
     }
     QString proPath = QFileInfo(proFile).path();
     if (visitor.templateType() == ProFileEvaluator::TT_Subdirs) {
+        QStringList subProjects = visitor.values(QLatin1String("SUBDIRS"));
+        excludeProjects(visitor, &subProjects);
         QStringList subProFiles;
         QDir proDir(proPath);
-        foreach (const QString &subdir, visitor.values(QLatin1String("SUBDIRS"))) {
+        foreach (const QString &subdir, subProjects) {
             QString realdir = visitor.value(subdir + QLatin1String(".subdir"));
             if (realdir.isEmpty())
                 realdir = visitor.value(subdir + QLatin1String(".file"));
diff --git a/tests/auto/linguist/lupdate/testdata/good/proparsingsubs/excluded/excluded.pro b/tests/auto/linguist/lupdate/testdata/good/proparsingsubs/excluded/excluded.pro
new file mode 100644 (file)
index 0000000..28dcadc
--- /dev/null
@@ -0,0 +1 @@
+SOURCES += main.cpp
diff --git a/tests/auto/linguist/lupdate/testdata/good/proparsingsubs/excluded/main.cpp b/tests/auto/linguist/lupdate/testdata/good/proparsingsubs/excluded/main.cpp
new file mode 100644 (file)
index 0000000..cc99f9d
--- /dev/null
@@ -0,0 +1,50 @@
+/****************************************************************************
+**
+** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia.  For licensing terms and
+** conditions see http://qt.digia.com/licensing.  For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file.  Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights.  These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file.  Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+// IMPORTANT!!!! If you want to add testdata to this file,
+// always add it to the end in order to not change the linenumbers of translations!!!
+
+
+void func1() {
+    QString fake = QApplication::tr("fake", "This message will not be collected");
+}
+
+