From b62b87d6ae3ced4466c1a1b085b51cec757e24f5 Mon Sep 17 00:00:00 2001 From: Oswald Buddenhagen Date: Tue, 26 Jan 2010 21:00:05 +0100 Subject: sanitize lupdate's behavior regarding SUBDIRS projects previously, the semantics of nesting projects were pretty bizarre: the list of TS files grew ever as the subdirs were visited. the source files otoh were cleared for every project. this meant that some TS files were updated over and over again, each time with different data. this is obviously total nonsense, so there is no compatibilty to keep. so here come the new semantics: - each project is scanned separately. it has separate include paths and may override the inherited CODECFORSRC. - the messages from all sub-projects are merged - if a sub-project has a TRANSLATIONS entry, it is "detached" from its parent project, thus starting an own merged translator. it is also possible to name an empty set of TS files to simply exclude the sub-project. - CODECFORTR can be specified in each project with TRANSLATIONS - if TS files are specified on the command line, they override TRANSLATIONS from the top level project and stop processing of detached projects alltogether. if multiple top-level projects are specified, they are all merged. this is somewhat slower, as now includes are re-scanned per project, while previously all sources were simply accumulated and scanned as one project. this can be fixed retroactively if needed. --- tests/auto/linguist/lupdate/.gitignore | 5 +- .../testdata/good/recurse_full/expectedoutput.txt | 0 .../lupdate/testdata/good/recurse_full/lupdatecmd | 2 + .../testdata/good/recurse_full/project.ts.result | 20 ++ .../good/recurse_full/project_sub.ts.result | 13 + .../good/recurse_full_ts/expectedoutput.txt | 2 + .../testdata/good/recurse_full_ts/lupdatecmd | 3 + .../good/recurse_full_ts/project.ts.result | 20 ++ .../good/recurse_full_ts/project_sub.ts.before | 0 .../good/recurse_full_ts/project_sub.ts.result | 0 .../good/recurse_full_ts_join/expectedoutput.txt | 0 .../testdata/good/recurse_full_ts_join/lupdatecmd | 2 + .../good/recurse_full_ts_join/project.ts.result | 20 ++ .../testdata/good/recurse_part/expectedoutput.txt | 1 + .../lupdate/testdata/good/recurse_part/lupdatecmd | 2 + .../testdata/good/recurse_part/project.ts.before | 0 .../testdata/good/recurse_part/project.ts.result | 0 .../good/recurse_part/project_sub.ts.result | 13 + .../good/recurse_part_ts/expectedoutput.txt | 1 + .../testdata/good/recurse_part_ts/lupdatecmd | 3 + .../good/recurse_part_ts/project.ts.result | 20 ++ .../good/recurse_part_ts/project_sub.ts.before | 0 .../good/recurse_part_ts/project_sub.ts.result | 0 .../lupdate/testdata/good/reloutput/lupdatecmd | 1 - .../lupdate/testdata/subdirs_full/project.pro | 4 + .../lupdate/testdata/subdirs_full/subdir1/main.cpp | 46 ++++ .../testdata/subdirs_full/subdir1/subdir1.pro | 1 + .../testdata/subdirs_full/subdir2/subdir2.pro | 2 + .../testdata/subdirs_full/subdir2/subsub1/main.cpp | 46 ++++ .../subdirs_full/subdir2/subsub1/subsub1.pro | 1 + .../testdata/subdirs_full/subdir2/subsub2/main.cpp | 46 ++++ .../subdirs_full/subdir2/subsub2/subsub2.pro | 4 + .../lupdate/testdata/subdirs_part/project.pro | 2 + .../lupdate/testdata/subdirs_part/subdir1/main.cpp | 46 ++++ .../testdata/subdirs_part/subdir1/subdir1.pro | 1 + .../testdata/subdirs_part/subdir2/subdir2.pro | 2 + .../testdata/subdirs_part/subdir2/subsub1/main.cpp | 46 ++++ .../subdirs_part/subdir2/subsub1/subsub1.pro | 1 + .../testdata/subdirs_part/subdir2/subsub2/main.cpp | 46 ++++ .../subdirs_part/subdir2/subsub2/subsub2.pro | 4 + tools/linguist/lupdate/main.cpp | 264 +++++++++++++-------- 41 files changed, 592 insertions(+), 98 deletions(-) create mode 100644 tests/auto/linguist/lupdate/testdata/good/recurse_full/expectedoutput.txt create mode 100644 tests/auto/linguist/lupdate/testdata/good/recurse_full/lupdatecmd create mode 100644 tests/auto/linguist/lupdate/testdata/good/recurse_full/project.ts.result create mode 100644 tests/auto/linguist/lupdate/testdata/good/recurse_full/project_sub.ts.result create mode 100644 tests/auto/linguist/lupdate/testdata/good/recurse_full_ts/expectedoutput.txt create mode 100644 tests/auto/linguist/lupdate/testdata/good/recurse_full_ts/lupdatecmd create mode 100644 tests/auto/linguist/lupdate/testdata/good/recurse_full_ts/project.ts.result create mode 100644 tests/auto/linguist/lupdate/testdata/good/recurse_full_ts/project_sub.ts.before create mode 100644 tests/auto/linguist/lupdate/testdata/good/recurse_full_ts/project_sub.ts.result create mode 100644 tests/auto/linguist/lupdate/testdata/good/recurse_full_ts_join/expectedoutput.txt create mode 100644 tests/auto/linguist/lupdate/testdata/good/recurse_full_ts_join/lupdatecmd create mode 100644 tests/auto/linguist/lupdate/testdata/good/recurse_full_ts_join/project.ts.result create mode 100644 tests/auto/linguist/lupdate/testdata/good/recurse_part/expectedoutput.txt create mode 100644 tests/auto/linguist/lupdate/testdata/good/recurse_part/lupdatecmd create mode 100644 tests/auto/linguist/lupdate/testdata/good/recurse_part/project.ts.before create mode 100644 tests/auto/linguist/lupdate/testdata/good/recurse_part/project.ts.result create mode 100644 tests/auto/linguist/lupdate/testdata/good/recurse_part/project_sub.ts.result create mode 100644 tests/auto/linguist/lupdate/testdata/good/recurse_part_ts/expectedoutput.txt create mode 100644 tests/auto/linguist/lupdate/testdata/good/recurse_part_ts/lupdatecmd create mode 100644 tests/auto/linguist/lupdate/testdata/good/recurse_part_ts/project.ts.result create mode 100644 tests/auto/linguist/lupdate/testdata/good/recurse_part_ts/project_sub.ts.before create mode 100644 tests/auto/linguist/lupdate/testdata/good/recurse_part_ts/project_sub.ts.result create mode 100644 tests/auto/linguist/lupdate/testdata/subdirs_full/project.pro create mode 100644 tests/auto/linguist/lupdate/testdata/subdirs_full/subdir1/main.cpp create mode 100644 tests/auto/linguist/lupdate/testdata/subdirs_full/subdir1/subdir1.pro create mode 100644 tests/auto/linguist/lupdate/testdata/subdirs_full/subdir2/subdir2.pro create mode 100644 tests/auto/linguist/lupdate/testdata/subdirs_full/subdir2/subsub1/main.cpp create mode 100644 tests/auto/linguist/lupdate/testdata/subdirs_full/subdir2/subsub1/subsub1.pro create mode 100644 tests/auto/linguist/lupdate/testdata/subdirs_full/subdir2/subsub2/main.cpp create mode 100644 tests/auto/linguist/lupdate/testdata/subdirs_full/subdir2/subsub2/subsub2.pro create mode 100644 tests/auto/linguist/lupdate/testdata/subdirs_part/project.pro create mode 100644 tests/auto/linguist/lupdate/testdata/subdirs_part/subdir1/main.cpp create mode 100644 tests/auto/linguist/lupdate/testdata/subdirs_part/subdir1/subdir1.pro create mode 100644 tests/auto/linguist/lupdate/testdata/subdirs_part/subdir2/subdir2.pro create mode 100644 tests/auto/linguist/lupdate/testdata/subdirs_part/subdir2/subsub1/main.cpp create mode 100644 tests/auto/linguist/lupdate/testdata/subdirs_part/subdir2/subsub1/subsub1.pro create mode 100644 tests/auto/linguist/lupdate/testdata/subdirs_part/subdir2/subsub2/main.cpp create mode 100644 tests/auto/linguist/lupdate/testdata/subdirs_part/subdir2/subsub2/subsub2.pro diff --git a/tests/auto/linguist/lupdate/.gitignore b/tests/auto/linguist/lupdate/.gitignore index 3572c82..a11e8d1 100644 --- a/tests/auto/linguist/lupdate/.gitignore +++ b/tests/auto/linguist/lupdate/.gitignore @@ -1,3 +1,4 @@ tst_lupdate -testdata/good/*/project.ts -testdata/good/*/*/project.ts +testdata/*/*.ts +testdata/*/*/*.ts +testdata/*/*/*/*.ts diff --git a/tests/auto/linguist/lupdate/testdata/good/recurse_full/expectedoutput.txt b/tests/auto/linguist/lupdate/testdata/good/recurse_full/expectedoutput.txt new file mode 100644 index 0000000..e69de29 diff --git a/tests/auto/linguist/lupdate/testdata/good/recurse_full/lupdatecmd b/tests/auto/linguist/lupdate/testdata/good/recurse_full/lupdatecmd new file mode 100644 index 0000000..40987e2 --- /dev/null +++ b/tests/auto/linguist/lupdate/testdata/good/recurse_full/lupdatecmd @@ -0,0 +1,2 @@ +TRANSLATION: project.ts project_sub.ts +cd ../../subdirs_full diff --git a/tests/auto/linguist/lupdate/testdata/good/recurse_full/project.ts.result b/tests/auto/linguist/lupdate/testdata/good/recurse_full/project.ts.result new file mode 100644 index 0000000..7d9a6f4 --- /dev/null +++ b/tests/auto/linguist/lupdate/testdata/good/recurse_full/project.ts.result @@ -0,0 +1,20 @@ + + + + + subdir1 + + + minimal test + + + + + subsub1 + + + minimal test + + + + diff --git a/tests/auto/linguist/lupdate/testdata/good/recurse_full/project_sub.ts.result b/tests/auto/linguist/lupdate/testdata/good/recurse_full/project_sub.ts.result new file mode 100644 index 0000000..cddb963 --- /dev/null +++ b/tests/auto/linguist/lupdate/testdata/good/recurse_full/project_sub.ts.result @@ -0,0 +1,13 @@ + + + +ISO-8859-2 + + subsub2 + + + minimal test + + + + diff --git a/tests/auto/linguist/lupdate/testdata/good/recurse_full_ts/expectedoutput.txt b/tests/auto/linguist/lupdate/testdata/good/recurse_full_ts/expectedoutput.txt new file mode 100644 index 0000000..fd7a158 --- /dev/null +++ b/tests/auto/linguist/lupdate/testdata/good/recurse_full_ts/expectedoutput.txt @@ -0,0 +1,2 @@ +lupdate warning: TS files from command line will override TRANSLATIONS in project\.pro\. +lupdate warning: TS files from command line prevent recursing into .*/subdir2/subsub2/subsub2\.pro\. diff --git a/tests/auto/linguist/lupdate/testdata/good/recurse_full_ts/lupdatecmd b/tests/auto/linguist/lupdate/testdata/good/recurse_full_ts/lupdatecmd new file mode 100644 index 0000000..33296c3 --- /dev/null +++ b/tests/auto/linguist/lupdate/testdata/good/recurse_full_ts/lupdatecmd @@ -0,0 +1,3 @@ +TRANSLATION: project.ts project_sub.ts +cd ../../subdirs_full +lupdate project.pro -ts project.ts diff --git a/tests/auto/linguist/lupdate/testdata/good/recurse_full_ts/project.ts.result b/tests/auto/linguist/lupdate/testdata/good/recurse_full_ts/project.ts.result new file mode 100644 index 0000000..7d9a6f4 --- /dev/null +++ b/tests/auto/linguist/lupdate/testdata/good/recurse_full_ts/project.ts.result @@ -0,0 +1,20 @@ + + + + + subdir1 + + + minimal test + + + + + subsub1 + + + minimal test + + + + diff --git a/tests/auto/linguist/lupdate/testdata/good/recurse_full_ts/project_sub.ts.before b/tests/auto/linguist/lupdate/testdata/good/recurse_full_ts/project_sub.ts.before new file mode 100644 index 0000000..e69de29 diff --git a/tests/auto/linguist/lupdate/testdata/good/recurse_full_ts/project_sub.ts.result b/tests/auto/linguist/lupdate/testdata/good/recurse_full_ts/project_sub.ts.result new file mode 100644 index 0000000..e69de29 diff --git a/tests/auto/linguist/lupdate/testdata/good/recurse_full_ts_join/expectedoutput.txt b/tests/auto/linguist/lupdate/testdata/good/recurse_full_ts_join/expectedoutput.txt new file mode 100644 index 0000000..e69de29 diff --git a/tests/auto/linguist/lupdate/testdata/good/recurse_full_ts_join/lupdatecmd b/tests/auto/linguist/lupdate/testdata/good/recurse_full_ts_join/lupdatecmd new file mode 100644 index 0000000..628acc0 --- /dev/null +++ b/tests/auto/linguist/lupdate/testdata/good/recurse_full_ts_join/lupdatecmd @@ -0,0 +1,2 @@ +cd ../../subdirs_full +lupdate subdir1/subdir1.pro subdir2/subsub1/subsub1.pro -ts project.ts diff --git a/tests/auto/linguist/lupdate/testdata/good/recurse_full_ts_join/project.ts.result b/tests/auto/linguist/lupdate/testdata/good/recurse_full_ts_join/project.ts.result new file mode 100644 index 0000000..7d9a6f4 --- /dev/null +++ b/tests/auto/linguist/lupdate/testdata/good/recurse_full_ts_join/project.ts.result @@ -0,0 +1,20 @@ + + + + + subdir1 + + + minimal test + + + + + subsub1 + + + minimal test + + + + diff --git a/tests/auto/linguist/lupdate/testdata/good/recurse_part/expectedoutput.txt b/tests/auto/linguist/lupdate/testdata/good/recurse_part/expectedoutput.txt new file mode 100644 index 0000000..808db18 --- /dev/null +++ b/tests/auto/linguist/lupdate/testdata/good/recurse_part/expectedoutput.txt @@ -0,0 +1 @@ +lupdate warning: no TS files specified\. Only diagnostics will be produced for 'project\.pro'\. diff --git a/tests/auto/linguist/lupdate/testdata/good/recurse_part/lupdatecmd b/tests/auto/linguist/lupdate/testdata/good/recurse_part/lupdatecmd new file mode 100644 index 0000000..3e15bc7 --- /dev/null +++ b/tests/auto/linguist/lupdate/testdata/good/recurse_part/lupdatecmd @@ -0,0 +1,2 @@ +TRANSLATION: project.ts project_sub.ts +cd ../../subdirs_part diff --git a/tests/auto/linguist/lupdate/testdata/good/recurse_part/project.ts.before b/tests/auto/linguist/lupdate/testdata/good/recurse_part/project.ts.before new file mode 100644 index 0000000..e69de29 diff --git a/tests/auto/linguist/lupdate/testdata/good/recurse_part/project.ts.result b/tests/auto/linguist/lupdate/testdata/good/recurse_part/project.ts.result new file mode 100644 index 0000000..e69de29 diff --git a/tests/auto/linguist/lupdate/testdata/good/recurse_part/project_sub.ts.result b/tests/auto/linguist/lupdate/testdata/good/recurse_part/project_sub.ts.result new file mode 100644 index 0000000..cddb963 --- /dev/null +++ b/tests/auto/linguist/lupdate/testdata/good/recurse_part/project_sub.ts.result @@ -0,0 +1,13 @@ + + + +ISO-8859-2 + + subsub2 + + + minimal test + + + + diff --git a/tests/auto/linguist/lupdate/testdata/good/recurse_part_ts/expectedoutput.txt b/tests/auto/linguist/lupdate/testdata/good/recurse_part_ts/expectedoutput.txt new file mode 100644 index 0000000..b904390 --- /dev/null +++ b/tests/auto/linguist/lupdate/testdata/good/recurse_part_ts/expectedoutput.txt @@ -0,0 +1 @@ +lupdate warning: TS files from command line prevent recursing into .*/subdir2/subsub2/subsub2\.pro\. diff --git a/tests/auto/linguist/lupdate/testdata/good/recurse_part_ts/lupdatecmd b/tests/auto/linguist/lupdate/testdata/good/recurse_part_ts/lupdatecmd new file mode 100644 index 0000000..41bfcec --- /dev/null +++ b/tests/auto/linguist/lupdate/testdata/good/recurse_part_ts/lupdatecmd @@ -0,0 +1,3 @@ +TRANSLATION: project.ts project_sub.ts +cd ../../subdirs_part +lupdate project.pro -ts project.ts diff --git a/tests/auto/linguist/lupdate/testdata/good/recurse_part_ts/project.ts.result b/tests/auto/linguist/lupdate/testdata/good/recurse_part_ts/project.ts.result new file mode 100644 index 0000000..7d9a6f4 --- /dev/null +++ b/tests/auto/linguist/lupdate/testdata/good/recurse_part_ts/project.ts.result @@ -0,0 +1,20 @@ + + + + + subdir1 + + + minimal test + + + + + subsub1 + + + minimal test + + + + diff --git a/tests/auto/linguist/lupdate/testdata/good/recurse_part_ts/project_sub.ts.before b/tests/auto/linguist/lupdate/testdata/good/recurse_part_ts/project_sub.ts.before new file mode 100644 index 0000000..e69de29 diff --git a/tests/auto/linguist/lupdate/testdata/good/recurse_part_ts/project_sub.ts.result b/tests/auto/linguist/lupdate/testdata/good/recurse_part_ts/project_sub.ts.result new file mode 100644 index 0000000..e69de29 diff --git a/tests/auto/linguist/lupdate/testdata/good/reloutput/lupdatecmd b/tests/auto/linguist/lupdate/testdata/good/reloutput/lupdatecmd index da6103f..90f609b 100644 --- a/tests/auto/linguist/lupdate/testdata/good/reloutput/lupdatecmd +++ b/tests/auto/linguist/lupdate/testdata/good/reloutput/lupdatecmd @@ -1,2 +1 @@ TRANSLATION: translations/project.ts -lupdate project.pro -ts translations/project.ts diff --git a/tests/auto/linguist/lupdate/testdata/subdirs_full/project.pro b/tests/auto/linguist/lupdate/testdata/subdirs_full/project.pro new file mode 100644 index 0000000..1f744a7 --- /dev/null +++ b/tests/auto/linguist/lupdate/testdata/subdirs_full/project.pro @@ -0,0 +1,4 @@ +TEMPLATE = subdirs +SUBDIRS = subdir1 subdir2/subdir2.pro + +TRANSLATIONS = project.ts diff --git a/tests/auto/linguist/lupdate/testdata/subdirs_full/subdir1/main.cpp b/tests/auto/linguist/lupdate/testdata/subdirs_full/subdir1/main.cpp new file mode 100644 index 0000000..0f1dc70 --- /dev/null +++ b/tests/auto/linguist/lupdate/testdata/subdirs_full/subdir1/main.cpp @@ -0,0 +1,46 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** 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, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + + +QString foo() +{ + QCoreApplication::translate("subdir1","minimal test"); +} diff --git a/tests/auto/linguist/lupdate/testdata/subdirs_full/subdir1/subdir1.pro b/tests/auto/linguist/lupdate/testdata/subdirs_full/subdir1/subdir1.pro new file mode 100644 index 0000000..28dcadc --- /dev/null +++ b/tests/auto/linguist/lupdate/testdata/subdirs_full/subdir1/subdir1.pro @@ -0,0 +1 @@ +SOURCES += main.cpp diff --git a/tests/auto/linguist/lupdate/testdata/subdirs_full/subdir2/subdir2.pro b/tests/auto/linguist/lupdate/testdata/subdirs_full/subdir2/subdir2.pro new file mode 100644 index 0000000..f8d03df --- /dev/null +++ b/tests/auto/linguist/lupdate/testdata/subdirs_full/subdir2/subdir2.pro @@ -0,0 +1,2 @@ +TEMPLATE = subdirs +SUBDIRS = subsub1 subsub2 diff --git a/tests/auto/linguist/lupdate/testdata/subdirs_full/subdir2/subsub1/main.cpp b/tests/auto/linguist/lupdate/testdata/subdirs_full/subdir2/subsub1/main.cpp new file mode 100644 index 0000000..8c82c80 --- /dev/null +++ b/tests/auto/linguist/lupdate/testdata/subdirs_full/subdir2/subsub1/main.cpp @@ -0,0 +1,46 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** 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, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + + +QString foo() +{ + QCoreApplication::translate("subsub1","minimal test"); +} diff --git a/tests/auto/linguist/lupdate/testdata/subdirs_full/subdir2/subsub1/subsub1.pro b/tests/auto/linguist/lupdate/testdata/subdirs_full/subdir2/subsub1/subsub1.pro new file mode 100644 index 0000000..28dcadc --- /dev/null +++ b/tests/auto/linguist/lupdate/testdata/subdirs_full/subdir2/subsub1/subsub1.pro @@ -0,0 +1 @@ +SOURCES += main.cpp diff --git a/tests/auto/linguist/lupdate/testdata/subdirs_full/subdir2/subsub2/main.cpp b/tests/auto/linguist/lupdate/testdata/subdirs_full/subdir2/subsub2/main.cpp new file mode 100644 index 0000000..ff85936 --- /dev/null +++ b/tests/auto/linguist/lupdate/testdata/subdirs_full/subdir2/subsub2/main.cpp @@ -0,0 +1,46 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** 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, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + + +QString foo() +{ + QCoreApplication::translate("subsub2","minimal test"); +} diff --git a/tests/auto/linguist/lupdate/testdata/subdirs_full/subdir2/subsub2/subsub2.pro b/tests/auto/linguist/lupdate/testdata/subdirs_full/subdir2/subsub2/subsub2.pro new file mode 100644 index 0000000..3499222 --- /dev/null +++ b/tests/auto/linguist/lupdate/testdata/subdirs_full/subdir2/subsub2/subsub2.pro @@ -0,0 +1,4 @@ +SOURCES += main.cpp + +TRANSLATIONS = ../../project_sub.ts +CODECFORTR = ISO-8859-2 diff --git a/tests/auto/linguist/lupdate/testdata/subdirs_part/project.pro b/tests/auto/linguist/lupdate/testdata/subdirs_part/project.pro new file mode 100644 index 0000000..d803c37 --- /dev/null +++ b/tests/auto/linguist/lupdate/testdata/subdirs_part/project.pro @@ -0,0 +1,2 @@ +TEMPLATE = subdirs +SUBDIRS = subdir1 subdir2/subdir2.pro diff --git a/tests/auto/linguist/lupdate/testdata/subdirs_part/subdir1/main.cpp b/tests/auto/linguist/lupdate/testdata/subdirs_part/subdir1/main.cpp new file mode 100644 index 0000000..0f1dc70 --- /dev/null +++ b/tests/auto/linguist/lupdate/testdata/subdirs_part/subdir1/main.cpp @@ -0,0 +1,46 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** 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, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + + +QString foo() +{ + QCoreApplication::translate("subdir1","minimal test"); +} diff --git a/tests/auto/linguist/lupdate/testdata/subdirs_part/subdir1/subdir1.pro b/tests/auto/linguist/lupdate/testdata/subdirs_part/subdir1/subdir1.pro new file mode 100644 index 0000000..28dcadc --- /dev/null +++ b/tests/auto/linguist/lupdate/testdata/subdirs_part/subdir1/subdir1.pro @@ -0,0 +1 @@ +SOURCES += main.cpp diff --git a/tests/auto/linguist/lupdate/testdata/subdirs_part/subdir2/subdir2.pro b/tests/auto/linguist/lupdate/testdata/subdirs_part/subdir2/subdir2.pro new file mode 100644 index 0000000..f8d03df --- /dev/null +++ b/tests/auto/linguist/lupdate/testdata/subdirs_part/subdir2/subdir2.pro @@ -0,0 +1,2 @@ +TEMPLATE = subdirs +SUBDIRS = subsub1 subsub2 diff --git a/tests/auto/linguist/lupdate/testdata/subdirs_part/subdir2/subsub1/main.cpp b/tests/auto/linguist/lupdate/testdata/subdirs_part/subdir2/subsub1/main.cpp new file mode 100644 index 0000000..8c82c80 --- /dev/null +++ b/tests/auto/linguist/lupdate/testdata/subdirs_part/subdir2/subsub1/main.cpp @@ -0,0 +1,46 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** 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, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + + +QString foo() +{ + QCoreApplication::translate("subsub1","minimal test"); +} diff --git a/tests/auto/linguist/lupdate/testdata/subdirs_part/subdir2/subsub1/subsub1.pro b/tests/auto/linguist/lupdate/testdata/subdirs_part/subdir2/subsub1/subsub1.pro new file mode 100644 index 0000000..28dcadc --- /dev/null +++ b/tests/auto/linguist/lupdate/testdata/subdirs_part/subdir2/subsub1/subsub1.pro @@ -0,0 +1 @@ +SOURCES += main.cpp diff --git a/tests/auto/linguist/lupdate/testdata/subdirs_part/subdir2/subsub2/main.cpp b/tests/auto/linguist/lupdate/testdata/subdirs_part/subdir2/subsub2/main.cpp new file mode 100644 index 0000000..ff85936 --- /dev/null +++ b/tests/auto/linguist/lupdate/testdata/subdirs_part/subdir2/subsub2/main.cpp @@ -0,0 +1,46 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** 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, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + + +QString foo() +{ + QCoreApplication::translate("subsub2","minimal test"); +} diff --git a/tests/auto/linguist/lupdate/testdata/subdirs_part/subdir2/subsub2/subsub2.pro b/tests/auto/linguist/lupdate/testdata/subdirs_part/subdir2/subsub2/subsub2.pro new file mode 100644 index 0000000..3499222 --- /dev/null +++ b/tests/auto/linguist/lupdate/testdata/subdirs_part/subdir2/subsub2/subsub2.pro @@ -0,0 +1,4 @@ +SOURCES += main.cpp + +TRANSLATIONS = ../../project_sub.ts +CODECFORTR = ISO-8859-2 diff --git a/tools/linguist/lupdate/main.cpp b/tools/linguist/lupdate/main.cpp index 44717bf..6d91aa3 100644 --- a/tools/linguist/lupdate/main.cpp +++ b/tools/linguist/lupdate/main.cpp @@ -117,14 +117,17 @@ static void printUsage() " -disable-heuristic {sametext|similartext|number}\n" " Disable the named merge heuristic. Can be specified multiple times.\n" " -pro \n" - " Name of a .pro file. Useful for files with .pro\n" - " file syntax but different file suffix\n" + " Name of a .pro file. Useful for files with .pro file syntax but\n" + " different file suffix. Projects are recursed into and merged.\n" " -source-language [_]\n" " Specify the language of the source strings for new files.\n" " Defaults to POSIX if not specified.\n" " -target-language [_]\n" " Specify the language of the translations for new files.\n" " Guessed from the file name if not specified.\n" + " -ts ...\n" + " Specify the output file(s). This will override the TRANSLATIONS\n" + " and nullify the CODECFORTR from possibly specified project files.\n" " -version\n" " Display the version of lupdate and exit.\n" ).arg(m_defaultExtensions)); @@ -249,16 +252,151 @@ static QStringList getSources(const ProFileEvaluator &visitor, const QString &pr return sourceFiles; } +static void processSources(Translator &fetchedTor, + const QStringList &sourceFiles, ConversionData &cd) +{ + QStringList sourceFilesCpp; + for (QStringList::const_iterator it = sourceFiles.begin(); it != sourceFiles.end(); ++it) { + if (it->endsWith(QLatin1String(".java"), Qt::CaseInsensitive)) + loadJava(fetchedTor, *it, cd); + else if (it->endsWith(QLatin1String(".ui"), Qt::CaseInsensitive) + || it->endsWith(QLatin1String(".jui"), Qt::CaseInsensitive)) + loadUI(fetchedTor, *it, cd); + else if (it->endsWith(QLatin1String(".js"), Qt::CaseInsensitive) + || it->endsWith(QLatin1String(".qs"), Qt::CaseInsensitive)) + loadQScript(fetchedTor, *it, cd); + else + sourceFilesCpp << *it; + } + loadCPP(fetchedTor, sourceFilesCpp, cd); + if (!cd.error().isEmpty()) + printOut(cd.error()); +} + +static void processProjects( + bool topLevel, bool nestComplain, const QStringList &proFiles, + UpdateOptions options, const QByteArray &codecForSource, + const QString &targetLanguage, const QString &sourceLanguage, + Translator *parentTor, bool *fail); + +static void processProject( + bool nestComplain, const QFileInfo &pfi, ProFileEvaluator &visitor, + UpdateOptions options, const QByteArray &_codecForSource, + const QString &targetLanguage, const QString &sourceLanguage, + Translator *fetchedTor, bool *fail) +{ + QByteArray codecForSource = _codecForSource; + QStringList tmp = visitor.values(QLatin1String("CODECFORSRC")); + if (!tmp.isEmpty()) { + codecForSource = tmp.last().toLatin1(); + if (!QTextCodec::codecForName(codecForSource)) { + qWarning("lupdate warning: Codec for source '%s' is invalid. " + "Falling back to codec for tr().", codecForSource.constData()); + codecForSource.clear(); + } + } + if (visitor.templateType() == ProFileEvaluator::TT_Subdirs) { + QStringList subProFiles; + QDir proDir(pfi.absoluteDir()); + foreach (const QString &subdir, visitor.values(QLatin1String("SUBDIRS"))) { + QString subPro = QDir::cleanPath(proDir.absoluteFilePath(subdir)); + QFileInfo subInfo(subPro); + if (subInfo.isDir()) + subProFiles << (subPro + QLatin1Char('/') + + subInfo.fileName() + QLatin1String(".pro")); + else + subProFiles << subPro; + } + processProjects(false, nestComplain, subProFiles, options, codecForSource, + targetLanguage, sourceLanguage, fetchedTor, fail); + } else { + ConversionData cd; + cd.m_noUiLines = options & NoUiLines; + cd.m_codecForSource = codecForSource; + cd.m_includePath = visitor.values(QLatin1String("INCLUDEPATH")); + QStringList sourceFiles = getSources(visitor, pfi.absolutePath()); + QSet projectRoots; + projectRoots.insert(QDir::cleanPath(pfi.absolutePath()) + QLatin1Char('/')); + cd.m_projectRoots = projectRoots; + processSources(*fetchedTor, sourceFiles, cd); + } +} + +static void processProjects( + bool topLevel, bool nestComplain, const QStringList &proFiles, + UpdateOptions options, const QByteArray &codecForSource, + const QString &targetLanguage, const QString &sourceLanguage, + Translator *parentTor, bool *fail) +{ + foreach (const QString &proFile, proFiles) { + ProFileEvaluator visitor; + visitor.setVerbose(options & Verbose); + + QFileInfo pfi(proFile); + ProFile pro(pfi.absoluteFilePath()); + if (!visitor.queryProFile(&pro) || !visitor.accept(&pro)) { + if (topLevel) + *fail = true; + continue; + } + + if (visitor.contains(QLatin1String("TRANSLATIONS"))) { + if (parentTor) { + if (topLevel) { + std::cerr << "lupdate warning: TS files from command line " + "will override TRANSLATIONS in " << qPrintable(proFile) << ".\n"; + goto noTrans; + } else if (nestComplain) { + std::cerr << "lupdate warning: TS files from command line " + "prevent recursing into " << qPrintable(proFile) << ".\n"; + continue; + } + } + QStringList tsFiles; + QDir proDir(pfi.absolutePath()); + foreach (const QString &tsFile, visitor.values(QLatin1String("TRANSLATIONS"))) + tsFiles << QFileInfo(proDir, tsFile).filePath(); + if (tsFiles.isEmpty()) { + // This might mean either a buggy PRO file or an intentional detach - + // we can't know without seeing the actual RHS of the assignment ... + // Just assume correctness and be silent. + continue; + } + Translator tor; + QByteArray codecForTr; + QStringList tmp = visitor.values(QLatin1String("CODEC")) + + visitor.values(QLatin1String("DEFAULTCODEC")) + + visitor.values(QLatin1String("CODECFORTR")); + if (!tmp.isEmpty()) { + codecForTr = tmp.last().toLatin1(); + tor.setCodecName(codecForTr); + } + processProject(false, pfi, visitor, options, codecForSource, + targetLanguage, sourceLanguage, &tor, fail); + updateTsFiles(tor, tsFiles, codecForTr, sourceLanguage, targetLanguage, options, fail); + continue; + } + noTrans: + if (!parentTor) { + if (topLevel) + std::cerr << "lupdate warning: no TS files specified. Only diagnostics " + "will be produced for '" << qPrintable(proFile) << "'.\n"; + Translator tor; + processProject(nestComplain, pfi, visitor, options, codecForSource, + targetLanguage, sourceLanguage, &tor, fail); + } else { + processProject(nestComplain, pfi, visitor, options, codecForSource, + targetLanguage, sourceLanguage, parentTor, fail); + } + } +} + int main(int argc, char **argv) { QCoreApplication app(argc, argv); m_defaultExtensions = QLatin1String("ui,c,c++,cc,cpp,cxx,ch,h,h++,hh,hpp,hxx"); QStringList args = app.arguments(); - QString defaultContext; // This was QLatin1String("@default") before. - Translator fetchedTor; - QByteArray codecForTr; - QByteArray codecForSource; QStringList tsFileNames; QStringList proFiles; QMultiHash allCSources; @@ -402,9 +540,6 @@ int main(int argc, char **argv) return 1; } - codecForTr.clear(); - codecForSource.clear(); - if (metTsFlag) { bool found = false; foreach (const Translator::FileFormat &fmt, Translator::registeredFileFormats()) { @@ -477,106 +612,45 @@ int main(int argc, char **argv) } } // for args - if (!proFiles.isEmpty() && !sourceFiles.isEmpty()) { - qWarning("lupdate error: Both project and source files specified.\n"); - return 1; - } if (numFiles == 0) { printUsage(); return 1; } - foreach (const QString &proFile, proFiles) - projectRoots.insert(QDir::cleanPath(QFileInfo(proFile).absolutePath()) + QLatin1Char('/')); + if (!targetLanguage.isEmpty() && tsFileNames.count() != 1) + std::cerr << "lupdate warning: -target-language usually only " + "makes sense with exactly one TS file.\n"; - bool firstPass = true; bool fail = false; - while (firstPass || !proFiles.isEmpty()) { + if (proFiles.isEmpty()) { + if (tsFileNames.isEmpty()) + std::cerr << "lupdate warning: no TS files specified. " + "Only diagnostics will be produced.\n"; + + Translator fetchedTor; ConversionData cd; - cd.m_defaultContext = defaultContext; cd.m_noUiLines = options & NoUiLines; cd.m_projectRoots = projectRoots; cd.m_includePath = includePath; cd.m_allCSources = allCSources; - - QStringList tsFiles = tsFileNames; - if (proFiles.count() > 0) { - QFileInfo pfi(proFiles.takeFirst()); - - ProFileEvaluator visitor; - visitor.setVerbose(options & Verbose); - - ProFile pro(pfi.absoluteFilePath()); - if (!visitor.queryProFile(&pro)) - return 2; - if (!visitor.accept(&pro)) - return 2; - - if (visitor.templateType() == ProFileEvaluator::TT_Subdirs) { - QDir proDir(pfi.absoluteDir()); - foreach (const QString &subdir, visitor.values(QLatin1String("SUBDIRS"))) { - QString subPro = QDir::cleanPath(proDir.absoluteFilePath(subdir)); - QFileInfo subInfo(subPro); - if (subInfo.isDir()) - proFiles << (subPro + QLatin1Char('/') - + subInfo.fileName() + QLatin1String(".pro")); - else - proFiles << subPro; - } - continue; - } - - cd.m_includePath += visitor.values(QLatin1String("INCLUDEPATH")); - - sourceFiles = getSources(visitor, pfi.absolutePath()); - - QStringList tmp = visitor.values(QLatin1String("CODEC")) - + visitor.values(QLatin1String("DEFAULTCODEC")) - + visitor.values(QLatin1String("CODECFORTR")); - if (!tmp.isEmpty()) { - codecForTr = tmp.last().toLatin1(); - fetchedTor.setCodecName(codecForTr); - cd.m_outputCodec = codecForTr; - } - tmp = visitor.values(QLatin1String("CODECFORSRC")); - if (!tmp.isEmpty()) { - codecForSource = tmp.last().toLatin1(); - if (!QTextCodec::codecForName(codecForSource)) - qWarning("lupdate warning: Codec for source '%s' is invalid. Falling back to codec for tr().", - codecForSource.constData()); - else - cd.m_codecForSource = codecForSource; - } - - QDir proDir(pfi.absolutePath()); - foreach (const QString &tsFile, visitor.values(QLatin1String("TRANSLATIONS"))) - tsFiles << QFileInfo(proDir, tsFile).filePath(); + processSources(fetchedTor, sourceFiles, cd); + updateTsFiles(fetchedTor, tsFileNames, QByteArray(), + sourceLanguage, targetLanguage, options, &fail); + } else { + if (!sourceFiles.isEmpty() || !includePath.isEmpty()) { + qWarning("lupdate error: Both project and source files / include paths specified.\n"); + return 1; } - - QStringList sourceFilesCpp; - for (QStringList::iterator it = sourceFiles.begin(); it != sourceFiles.end(); ++it) { - if (it->endsWith(QLatin1String(".java"), Qt::CaseInsensitive)) - loadJava(fetchedTor, *it, cd); - else if (it->endsWith(QLatin1String(".ui"), Qt::CaseInsensitive) - || it->endsWith(QLatin1String(".jui"), Qt::CaseInsensitive)) - loadUI(fetchedTor, *it, cd); - else if (it->endsWith(QLatin1String(".js"), Qt::CaseInsensitive) - || it->endsWith(QLatin1String(".qs"), Qt::CaseInsensitive)) - loadQScript(fetchedTor, *it, cd); - else - sourceFilesCpp << *it; + if (!tsFileNames.isEmpty()) { + Translator fetchedTor; + processProjects(true, true, proFiles, options, QByteArray(), + targetLanguage, sourceLanguage, &fetchedTor, &fail); + updateTsFiles(fetchedTor, tsFileNames, QByteArray(), + sourceLanguage, targetLanguage, options, &fail); + } else { + processProjects(true, false, proFiles, options, QByteArray(), + targetLanguage, sourceLanguage, 0, &fail); } - loadCPP(fetchedTor, sourceFilesCpp, cd); - if (!cd.error().isEmpty()) - printOut(cd.error()); - - tsFiles.removeDuplicates(); - - if (!tsFiles.isEmpty()) - updateTsFiles(fetchedTor, tsFiles, codecForTr, sourceLanguage, targetLanguage, options, &fail); - - firstPass = false; } - return fail ? 1 : 0; } -- cgit v0.12