diff options
Diffstat (limited to 'src/tools/rcc/main.cpp')
-rw-r--r-- | src/tools/rcc/main.cpp | 122 |
1 files changed, 53 insertions, 69 deletions
diff --git a/src/tools/rcc/main.cpp b/src/tools/rcc/main.cpp index 287be43f97..03709ccbd4 100644 --- a/src/tools/rcc/main.cpp +++ b/src/tools/rcc/main.cpp @@ -1,31 +1,6 @@ -/**************************************************************************** -** -** Copyright (C) 2018 The Qt Company Ltd. -** Copyright (C) 2018 Intel Corporation. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the tools applications of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** 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 The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2018 The Qt Company Ltd. +// Copyright (C) 2018 Intel Corporation. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 #include <rcc.h> @@ -49,6 +24,8 @@ QT_BEGIN_NAMESPACE +using namespace Qt::StringLiterals; + void dumpRecursive(const QDir &dir, QTextStream &out) { const QFileInfoList entries = dir.entryInfoList(QDir::Files | QDir::Dirs | QDir::NoDotAndDotDot @@ -57,9 +34,9 @@ void dumpRecursive(const QDir &dir, QTextStream &out) if (entry.isDir()) { dumpRecursive(entry.filePath(), out); } else { - out << QLatin1String("<file>") + out << "<file>"_L1 << entry.filePath() - << QLatin1String("</file>\n"); + << "</file>\n"_L1; } } } @@ -69,7 +46,7 @@ int createProject(const QString &outFileName) QDir currentDir = QDir::current(); QString currentDirName = currentDir.dirName(); if (currentDirName.isEmpty()) - currentDirName = QLatin1String("root"); + currentDirName = "root"_L1; QFile file; bool isOk = false; @@ -87,14 +64,14 @@ int createProject(const QString &outFileName) } QTextStream out(&file); - out << QLatin1String("<!DOCTYPE RCC><RCC version=\"1.0\">\n" - "<qresource>\n"); + out << "<!DOCTYPE RCC><RCC version=\"1.0\">\n" + "<qresource>\n"_L1; - // use "." as dir to get relative file pathes - dumpRecursive(QDir(QLatin1String(".")), out); + // use "." as dir to get relative file paths + dumpRecursive(QDir("."_L1), out); - out << QLatin1String("</qresource>\n" - "</RCC>\n"); + out << "</qresource>\n" + "</RCC>\n"_L1; return 0; } @@ -105,11 +82,11 @@ QString makefileEscape(const QString &filepath) // Always use forward slashes QString result = QDir::cleanPath(filepath); // Spaces are escaped with a backslash - result.replace(QLatin1Char(' '), QLatin1String("\\ ")); + result.replace(u' ', "\\ "_L1); // Pipes are escaped with a backslash - result.replace(QLatin1Char('|'), QLatin1String("\\|")); + result.replace(u'|', "\\|"_L1); // Dollars are escaped with a dollar - result.replace(QLatin1Char('$'), QLatin1String("$$")); + result.replace(u'$', "$$"_L1); return result; } @@ -118,16 +95,16 @@ void writeDepFile(QIODevice &iodev, const QStringList &depsList, const QString & { QTextStream out(&iodev); out << qPrintable(makefileEscape(targetName)); - out << QLatin1Char(':'); + out << QChar(u':'); // Write depfile for (int i = 0; i < depsList.size(); ++i) { - out << QLatin1Char(' '); + out << QChar(u' '); out << qPrintable(makefileEscape(depsList.at(i))); } - out << QLatin1Char('\n'); + out << QChar(u'\n'); } int runRcc(int argc, char *argv[]) @@ -139,7 +116,7 @@ int runRcc(int argc, char *argv[]) // If you use this code as an example for a translated app, make sure to translate the strings. QCommandLineParser parser; parser.setSingleDashWordOptionMode(QCommandLineParser::ParseAsLongOptions); - parser.setApplicationDescription(QLatin1String("Qt Resource Compiler version " QT_VERSION_STR)); + parser.setApplicationDescription("Qt Resource Compiler version " QT_VERSION_STR ""_L1); parser.addHelpOption(); parser.addVersionOption(); @@ -233,9 +210,9 @@ int runRcc(int argc, char *argv[]) bool ok = false; formatVersion = parser.value(formatVersionOption).toUInt(&ok); if (!ok) { - errorMsg = QLatin1String("Invalid format version specified"); + errorMsg = "Invalid format version specified"_L1; } else if (formatVersion < 1 || formatVersion > 3) { - errorMsg = QLatin1String("Unsupported format version specified"); + errorMsg = "Unsupported format version specified"_L1; } } @@ -244,19 +221,22 @@ int runRcc(int argc, char *argv[]) library.setInitName(parser.value(nameOption)); if (parser.isSet(rootOption)) { library.setResourceRoot(QDir::cleanPath(parser.value(rootOption))); - if (library.resourceRoot().isEmpty() - || library.resourceRoot().at(0) != QLatin1Char('/')) - errorMsg = QLatin1String("Root must start with a /"); + if (library.resourceRoot().isEmpty() || library.resourceRoot().at(0) != u'/') + errorMsg = "Root must start with a /"_L1; } if (parser.isSet(compressionAlgoOption)) library.setCompressionAlgorithm(RCCResourceLibrary::parseCompressionAlgorithm(parser.value(compressionAlgoOption), &errorMsg)); - if (formatVersion < 3 && library.compressionAlgorithm() == RCCResourceLibrary::CompressionAlgorithm::Zstd) - errorMsg = QLatin1String("Zstandard compression requires format version 3 or higher"); - if (parser.isSet(nocompressOption)) - library.setCompressionAlgorithm(RCCResourceLibrary::CompressionAlgorithm::None); if (parser.isSet(noZstdOption)) library.setNoZstd(true); + if (library.compressionAlgorithm() == RCCResourceLibrary::CompressionAlgorithm::Zstd) { + if (formatVersion < 3) + errorMsg = "Zstandard compression requires format version 3 or higher"_L1; + if (library.noZstd()) + errorMsg = "--compression-algo=zstd and --no-zstd both specified."_L1; + } + if (parser.isSet(nocompressOption)) + library.setCompressionAlgorithm(RCCResourceLibrary::CompressionAlgorithm::None); if (parser.isSet(compressOption) && errorMsg.isEmpty()) { int level = library.parseCompressionLevel(library.compressionAlgorithm(), parser.value(compressOption), &errorMsg); library.setCompressLevel(level); @@ -267,25 +247,25 @@ int runRcc(int argc, char *argv[]) library.setFormat(RCCResourceLibrary::Binary); if (parser.isSet(generatorOption)) { auto value = parser.value(generatorOption); - if (value == QLatin1String("cpp")) { + if (value == "cpp"_L1) { library.setFormat(RCCResourceLibrary::C_Code); - } else if (value == QLatin1String("python")) { + } else if (value == "python"_L1) { library.setFormat(RCCResourceLibrary::Python_Code); - } else if (value == QLatin1String("python2")) { // ### fixme Qt 7: remove + } else if (value == "python2"_L1) { // ### fixme Qt 7: remove qWarning("Format python2 is no longer supported, defaulting to python."); library.setFormat(RCCResourceLibrary::Python_Code); } else { - errorMsg = QLatin1String("Invalid generator: ") + value; + errorMsg = "Invalid generator: "_L1 + value; } } if (parser.isSet(passOption)) { - if (parser.value(passOption) == QLatin1String("1")) + if (parser.value(passOption) == "1"_L1) library.setFormat(RCCResourceLibrary::Pass1); - else if (parser.value(passOption) == QLatin1String("2")) + else if (parser.value(passOption) == "2"_L1) library.setFormat(RCCResourceLibrary::Pass2); else - errorMsg = QLatin1String("Pass number must be 1 or 2"); + errorMsg = "Pass number must be 1 or 2"_L1; } if (parser.isSet(namespaceOption)) library.setUseNameSpace(!library.useNameSpace()); @@ -298,7 +278,7 @@ int runRcc(int argc, char *argv[]) const QStringList filenamesIn = parser.positionalArguments(); for (const QString &file : filenamesIn) { - if (file == QLatin1String("-")) + if (file == "-"_L1) continue; else if (!QFile::exists(file)) { qWarning("%s: File does not exist '%s'", argv[0], qPrintable(file)); @@ -323,7 +303,8 @@ int runRcc(int argc, char *argv[]) return 1; } QFile errorDevice; - errorDevice.open(stderr, QIODevice::WriteOnly|QIODevice::Text); + if (!errorDevice.open(stderr, QIODevice::WriteOnly|QIODevice::Text)) + return 1; if (library.verbose()) errorDevice.write("Qt resource compiler\n"); @@ -350,7 +331,7 @@ int runRcc(int argc, char *argv[]) } - if (outFilename.isEmpty() || outFilename == QLatin1String("-")) { + if (outFilename.isEmpty() || outFilename == "-"_L1) { #ifdef Q_OS_WIN // Make sure fwrite to stdout doesn't do LF->CRLF if (library.format() == RCCResourceLibrary::Binary) @@ -361,7 +342,12 @@ int runRcc(int argc, char *argv[]) mode &= ~QIODevice::Text; #endif // Q_OS_WIN // using this overload close() only flushes. - out.open(stdout, mode); + if (!out.open(stdout, mode)) { + const QString msg = QString::fromLatin1("Unable to open standard output for writing: %1\n") + .arg(out.errorString()); + errorDevice.write(msg.toUtf8()); + return 1; + } } else { out.setFileName(outFilename); if (!out.open(mode)) { @@ -398,7 +384,7 @@ int runRcc(int argc, char *argv[]) QFile depout; depout.setFileName(depFilename); - if (outFilename.isEmpty() || outFilename == QLatin1String("-")) { + if (outFilename.isEmpty() || outFilename == "-"_L1) { const QString msg = QString::fromUtf8("Unable to write depfile when outputting to stdout!\n"); errorDevice.write(msg.toUtf8()); return 1; @@ -420,7 +406,7 @@ int runRcc(int argc, char *argv[]) temp.setFileName(tempFilename); if (!temp.open(QIODevice::ReadOnly)) { const QString msg = QString::fromUtf8("Unable to open temporary file %1 for reading: %2\n") - .arg(outFilename, out.errorString()); + .arg(tempFilename, out.errorString()); errorDevice.write(msg.toUtf8()); return 1; } @@ -441,9 +427,7 @@ int main(int argc, char *argv[]) // rcc uses a QHash to store files in the resource system. // we must force a certain hash order when testing or tst_rcc will fail, see QTBUG-25078 // similar requirements exist for reproducibly builds. - qSetGlobalQHashSeed(0); - if (qGlobalQHashSeed() != 0) - qWarning("Cannot force QHash seed"); + QHashSeed::setDeterministicGlobalSeed(); return QT_PREPEND_NAMESPACE(runRcc)(argc, argv); } |