From 2a290c70114ed841ed6f60a6997a596688fb6cc4 Mon Sep 17 00:00:00 2001
From: Oswald Buddenhagen <oswald.buddenhagen@digia.com>
Date: Mon, 19 Nov 2012 12:13:28 +0100
Subject: [PATCH] add support for TR_EXCLUDE

this is necessary for excluding 3rd party code, etc.

Change-Id: I2d32b6014741178bb8a62d29185241c90488754d
Reviewed-by: hjk <qthjk@ovi.com>
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@digia.com>
---
 src/linguist/lupdate/main.cpp                 | 17 +++++++
 .../testdata/good/parsecpp/excluded.cpp       | 45 +++++++++++++++++++
 .../testdata/good/parsecpp/project.pro        |  3 ++
 3 files changed, 65 insertions(+)
 create mode 100644 tests/auto/linguist/lupdate/testdata/good/parsecpp/excluded.cpp

diff --git a/src/linguist/lupdate/main.cpp b/src/linguist/lupdate/main.cpp
index afc0d48be..d3ca9ed6c 100644
--- a/src/linguist/lupdate/main.cpp
+++ b/src/linguist/lupdate/main.cpp
@@ -305,6 +305,23 @@ static QStringList getSources(const ProFileEvaluator &visitor, const QString &pr
     sourceFiles.removeDuplicates();
     sourceFiles.sort();
 
+    QStringList excludes;
+    foreach (QString ex, visitor.values(QLatin1String("TR_EXCLUDE"))) {
+        if (!QFileInfo(ex).isAbsolute())
+            ex = QDir(projectDir).absoluteFilePath(ex);
+        excludes << QDir::cleanPath(ex);
+    }
+    foreach (const QString &ex, excludes) {
+        // TODO: take advantage of the file list being sorted
+        QRegExp rx(ex, Qt::CaseSensitive, QRegExp::Wildcard);
+        for (QStringList::Iterator it = sourceFiles.begin(); it != sourceFiles.end(); ) {
+            if (rx.exactMatch(*it))
+                it = sourceFiles.erase(it);
+            else
+                ++it;
+        }
+    }
+
     return sourceFiles;
 }
 
diff --git a/tests/auto/linguist/lupdate/testdata/good/parsecpp/excluded.cpp b/tests/auto/linguist/lupdate/testdata/good/parsecpp/excluded.cpp
new file mode 100644
index 000000000..1f21ad4e0
--- /dev/null
+++ b/tests/auto/linguist/lupdate/testdata/good/parsecpp/excluded.cpp
@@ -0,0 +1,45 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 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$
+**
+****************************************************************************/
+
+int main(char **argv, int argc)
+{
+     QString fake = QApplication::tr("fake", "This message will not be collected");
+}
diff --git a/tests/auto/linguist/lupdate/testdata/good/parsecpp/project.pro b/tests/auto/linguist/lupdate/testdata/good/parsecpp/project.pro
index 37df00f40..d0dd914d4 100644
--- a/tests/auto/linguist/lupdate/testdata/good/parsecpp/project.pro
+++ b/tests/auto/linguist/lupdate/testdata/good/parsecpp/project.pro
@@ -1,5 +1,8 @@
 SOURCES += main.cpp
 SOURCES += finddialog.cpp
+SOURCES += excluded.cpp
+
+TR_EXCLUDE = $$PWD/excluded.*
 
 TRANSLATIONS = project.ts
 DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0
-- 
GitLab