diff options
Diffstat (limited to 'src/tools')
-rw-r--r-- | src/tools/androiddeployqt/main.cpp | 157 | ||||
-rw-r--r-- | src/tools/androidtestrunner/androidtestrunner.pro | 13 | ||||
-rw-r--r-- | src/tools/androidtestrunner/main.cpp | 490 | ||||
-rw-r--r-- | src/tools/bootstrap/bootstrap.pro | 16 | ||||
-rw-r--r-- | src/tools/moc/generator.cpp | 2 | ||||
-rw-r--r-- | src/tools/qfloat16-tables/gen_qfloat16_tables.cpp | 163 | ||||
-rw-r--r-- | src/tools/qfloat16-tables/qfloat16-tables.pro | 9 | ||||
-rw-r--r-- | src/tools/rcc/rcc.cpp | 5 | ||||
-rw-r--r-- | src/tools/rcc/rcc.h | 1 | ||||
-rw-r--r-- | src/tools/uic/cpp/cppwriteincludes.h | 4 | ||||
-rw-r--r-- | src/tools/uic/cpp/cppwriteinitialization.cpp | 14 | ||||
-rw-r--r-- | src/tools/uic/cpp/cppwriteinitialization.h | 16 | ||||
-rw-r--r-- | src/tools/uic/customwidgetsinfo.h | 2 | ||||
-rw-r--r-- | src/tools/uic/databaseinfo.cpp | 9 | ||||
-rw-r--r-- | src/tools/uic/driver.cpp | 2 | ||||
-rw-r--r-- | src/tools/uic/main.cpp | 2 | ||||
-rw-r--r-- | src/tools/uic/treewalker.h | 5 | ||||
-rw-r--r-- | src/tools/uic/uic.cpp | 8 |
18 files changed, 579 insertions, 339 deletions
diff --git a/src/tools/androiddeployqt/main.cpp b/src/tools/androiddeployqt/main.cpp index 65d95362f7..10bbd59bfb 100644 --- a/src/tools/androiddeployqt/main.cpp +++ b/src/tools/androiddeployqt/main.cpp @@ -118,7 +118,6 @@ struct Options , timing(false) , generateAssetsFileList(true) , build(true) - , gradle(false) , auxMode(false) , deploymentMechanism(Bundled) , releasePackage(false) @@ -150,7 +149,6 @@ struct Options bool timing; bool generateAssetsFileList; bool build; - bool gradle; bool auxMode; bool stripLibraries = true; ActionTimer timer; @@ -159,7 +157,6 @@ struct Options QString sdkPath; QString sdkBuildToolsVersion; QString ndkPath; - QString antTool; QString jdkPath; // Build paths @@ -212,6 +209,7 @@ struct Options bool sectionsOnly; bool protectedAuthenticationPath; bool jarSigner; + QString apkPath; // Gdbserver TriState gdbServer; @@ -369,13 +367,6 @@ Options parseOptions() options.helpRequested = true; } else if (argument.compare(QLatin1String("--verbose"), Qt::CaseInsensitive) == 0) { options.verbose = true; - } else if (argument.compare(QLatin1String("--gradle"), Qt::CaseInsensitive) == 0) { - options.gradle = true; - } else if (argument.compare(QLatin1String("--ant"), Qt::CaseInsensitive) == 0) { - if (i + 1 == arguments.size()) - options.helpRequested = true; - else - options.antTool = arguments.at(++i); } else if (argument.compare(QLatin1String("--deployment"), Qt::CaseInsensitive) == 0) { if (i + 1 == arguments.size()) { options.helpRequested = true; @@ -406,6 +397,11 @@ Options parseOptions() options.helpRequested = true; else options.jdkPath = arguments.at(++i); + } else if (argument.compare(QLatin1String("--apk"), Qt::CaseInsensitive) == 0) { + if (i + 1 == arguments.size()) + options.helpRequested = true; + else + options.apkPath = arguments.at(++i); } else if (argument.compare(QLatin1String("--sign"), Qt::CaseInsensitive) == 0) { if (i + 2 >= arguments.size()) { options.helpRequested = true; @@ -515,9 +511,6 @@ void printHelp() " --android-platform <platform>: Builds against the given android\n" " platform. By default, the highest available version will be\n" " used.\n" - " --gradle. Use gradle instead of ant to create and install the apk.\n" - " --ant <path/to/ant>: If unspecified, ant from the PATH will be\n" - " used.\n" " --release: Builds a package ready for release. By default, the\n" " package will be signed with a debug key.\n" " --sign <url/to/keystore> <alias>: Signs the package with the\n" @@ -557,6 +550,7 @@ void printHelp() " dependencies into the build directory and update the XML templates.\n" " The project will not be built or installed.\n" " --no-strip: Do not strip debug symbols from libraries.\n" + " --apk <path/where/to/copy/the/apk>: Path where to copy the built apk.\n" " --help: Displays this information.\n\n", qPrintable(QCoreApplication::arguments().at(0)) ); @@ -1024,16 +1018,13 @@ bool copyAndroidTemplate(const Options &options) if (options.verbose) fprintf(stdout, "Copying Android package template.\n"); - if (options.gradle && !copyGradleTemplate(options)) + if (!copyGradleTemplate(options)) return false; if (!copyAndroidTemplate(options, QLatin1String("/src/android/templates"))) return false; - if (options.gradle) - return true; - - return copyAndroidTemplate(options, QLatin1String("/src/android/java")); + return true; } bool copyAndroidSources(const Options &options) @@ -1285,36 +1276,6 @@ bool updateStringsXml(const Options &options) if (!updateFile(fileName, replacements)) return false; - if (options.gradle) - return true; - - // ant can't (easily) build multiple res folders, - // so we need to replace the "<!-- %%INSERT_STRINGS -->" placeholder - // from the main res folder - QFile stringsXml(fileName); - if (!stringsXml.open(QIODevice::ReadOnly)) { - fprintf(stderr, "Cannot open %s for reading.\n", qPrintable(fileName)); - return false; - } - - QXmlStreamReader reader(&stringsXml); - while (!reader.atEnd()) { - reader.readNext(); - if (reader.isStartElement() && - reader.name() == QLatin1String("string") && - reader.attributes().hasAttribute(QLatin1String("name")) && - reader.attributes().value(QLatin1String("name")) == QLatin1String("app_name")) { - return true; - } - } - - replacements.clear(); - replacements[QStringLiteral("<!-- %%INSERT_STRINGS -->")] = QString::fromLatin1("<string name=\"app_name\">%1</string>\n") - .arg(QFileInfo(options.applicationBinary).baseName().mid(sizeof("lib") - 1)); - - if (!updateFile(fileName, replacements)) - return false; - return true; } @@ -2220,64 +2181,6 @@ QString findInPath(const QString &fileName) return QString(); } -bool buildAntProject(const Options &options) -{ - if (options.verbose) - fprintf(stdout, "Building Android package using ant.\n"); - - QString antTool = options.antTool; - if (antTool.isEmpty()) { -#if defined(Q_OS_WIN32) - antTool = findInPath(QLatin1String("ant.bat")); -#else - antTool = findInPath(QLatin1String("ant")); -#endif - } - - if (antTool.isEmpty()) { - fprintf(stderr, "Cannot find ant in PATH. Please use --ant option to pass in the correct path.\n"); - return false; - } - - if (options.verbose) - fprintf(stdout, "Using ant: %s\n", qPrintable(antTool)); - - QString oldPath = QDir::currentPath(); - if (!QDir::setCurrent(options.outputDirectory)) { - fprintf(stderr, "Cannot current path to %s\n", qPrintable(options.outputDirectory)); - return false; - } - - QString ant = QString::fromLatin1("%1 %2").arg(shellQuote(antTool)).arg(options.releasePackage ? QLatin1String(" release") : QLatin1String(" debug")); - - FILE *antCommand = openProcess(ant); - if (antCommand == 0) { - fprintf(stderr, "Cannot run ant command: %s\n.", qPrintable(ant)); - return false; - } - - char buffer[512]; - while (fgets(buffer, sizeof(buffer), antCommand) != 0) { - fprintf(stdout, "%s", buffer); - fflush(stdout); - } - - int errorCode = pclose(antCommand); - if (errorCode != 0) { - fprintf(stderr, "Building the android package failed!\n"); - if (!options.verbose) - fprintf(stderr, " -- For more information, run this command with --verbose.\n"); - return false; - } - - if (!QDir::setCurrent(oldPath)) { - fprintf(stderr, "Cannot change back to old path: %s\n", qPrintable(oldPath)); - return false; - } - - return true; -} - typedef QMap<QByteArray, QByteArray> GradleProperties; static GradleProperties readGradleProperties(const QString &path) @@ -2335,7 +2238,7 @@ static bool mergeGradleProperties(const QString &path, GradleProperties properti return true; } -bool buildGradleProject(const Options &options) +bool buildAndroidProject(const Options &options) { GradleProperties localProperties; localProperties["sdk.dir"] = options.sdkPath.toLocal8Bit(); @@ -2403,12 +2306,6 @@ bool buildGradleProject(const Options &options) return true; } -bool buildAndroidProject(const Options &options) -{ - return options.gradle ? buildGradleProject(options) - : buildAntProject(options); -} - bool uninstallApk(const Options &options) { if (options.verbose) @@ -2445,15 +2342,11 @@ enum PackageType { QString apkPath(const Options &options, PackageType pt) { QString path(options.outputDirectory); - if (options.gradle) { - path += QLatin1String("/build/outputs/apk/"); - QString buildType(options.releasePackage ? QLatin1String("release/") : QLatin1String("debug/")); - if (QDir(path + buildType).exists()) - path += buildType; - path += QDir(options.outputDirectory).dirName() + QLatin1Char('-'); - } else { - path += QLatin1String("/bin/QtApp-"); - } + path += QLatin1String("/build/outputs/apk/"); + QString buildType(options.releasePackage ? QLatin1String("release/") : QLatin1String("debug/")); + if (QDir(path + buildType).exists()) + path += buildType; + path += QDir(options.outputDirectory).dirName() + QLatin1Char('-'); if (options.releasePackage) { path += QLatin1String("release-"); if (pt == UnsignedAPK) @@ -2503,6 +2396,14 @@ bool installApk(const Options &options) return true; } +bool copyPackage(const Options &options) +{ + fflush(stdout); + auto from = apkPath(options, options.keyStore.isEmpty() ? UnsignedAPK : SignedAPK); + QFile::remove(options.apkPath); + return QFile::copy(from, options.apkPath); +} + bool copyStdCpp(Options *options) { if (options->verbose) @@ -2873,7 +2774,8 @@ enum ErrorCode CannotSignPackage = 15, CannotInstallApk = 16, CannotGenerateAssetsFileList = 18, - CannotCopyAndroidExtraResources = 19 + CannotCopyAndroidExtraResources = 19, + CannotCopyApk = 20 }; int main(int argc, char *argv[]) @@ -2930,8 +2832,7 @@ int main(int argc, char *argv[]) } if (options.build) { - if (options.gradle) - cleanAndroidFiles(options); + cleanAndroidFiles(options); if (Q_UNLIKELY(options.timing)) fprintf(stdout, "[TIMING] %d ms: Cleaned Android file\n", options.timer.elapsed()); @@ -3005,9 +2906,6 @@ int main(int argc, char *argv[]) if (Q_UNLIKELY(options.timing)) fprintf(stdout, "[TIMING] %d ms: Updated files\n", options.timer.elapsed()); - if (!options.gradle && !createAndroidProject(options)) - return CannotCreateAndroidProject; - if (Q_UNLIKELY(options.timing)) fprintf(stdout, "[TIMING] %d ms: Created project\n", options.timer.elapsed()); @@ -3020,6 +2918,9 @@ int main(int argc, char *argv[]) if (!options.keyStore.isEmpty() && !signPackage(options)) return CannotSignPackage; + if (!options.apkPath.isEmpty() && !copyPackage(options)) + return CannotCopyApk; + if (Q_UNLIKELY(options.timing)) fprintf(stdout, "[TIMING] %d ms: Signed package\n", options.timer.elapsed()); } diff --git a/src/tools/androidtestrunner/androidtestrunner.pro b/src/tools/androidtestrunner/androidtestrunner.pro new file mode 100644 index 0000000000..641d3e0003 --- /dev/null +++ b/src/tools/androidtestrunner/androidtestrunner.pro @@ -0,0 +1,13 @@ +option(host_build) +CONFIG += console + +SOURCES += \ + main.cpp + +# Required for declarations of popen/pclose on Windows +windows: QMAKE_CXXFLAGS += -U__STRICT_ANSI__ + +DEFINES += QT_NO_CAST_FROM_ASCII QT_NO_CAST_TO_ASCII +DEFINES += QT_NO_FOREACH + +load(qt_app) diff --git a/src/tools/androidtestrunner/main.cpp b/src/tools/androidtestrunner/main.cpp new file mode 100644 index 0000000000..bb69b7b914 --- /dev/null +++ b/src/tools/androidtestrunner/main.cpp @@ -0,0 +1,490 @@ +/**************************************************************************** +** +** Copyright (C) 2019 BogDan Vatra <bogdan@kde.org> +** Copyright (C) 2016 The Qt Company Ltd. +** 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$ +** +****************************************************************************/ + +#include <QCoreApplication> +#include <QDir> +#include <QHash> +#include <QRegExp> +#include <QSystemSemaphore> +#include <QXmlStreamReader> + +#include <algorithm> +#include <chrono> +#include <functional> +#include <thread> + +#ifdef Q_CC_MSVC +#define popen _popen +#define QT_POPEN_READ "rb" +#define pclose _pclose +#else +#define QT_POPEN_READ "r" +#endif + +struct Options +{ + bool helpRequested = false; + bool verbose = false; + std::chrono::seconds timeout{300}; // 5minutes + QString androidDeployQtCommand; + QString buildPath; + QString adbCommand{QStringLiteral("adb")}; + QString makeCommand; + QString package; + QString activity; + QStringList testArgsList; + QHash<QString, QString> outFiles; + QString testArgs; + QString apkPath; + QHash<QString, std::function<bool(const QByteArray &)>> checkFiles = { + {QStringLiteral("txt"), [](const QByteArray &data) -> bool { + return data.indexOf("\nFAIL! : ") < 0; + }}, + {QStringLiteral("csv"), [](const QByteArray &/*data*/) -> bool { + // It seems csv is broken + return true; + }}, + {QStringLiteral("xml"), [](const QByteArray &data) -> bool { + QXmlStreamReader reader{data}; + while (!reader.atEnd()) { + reader.readNext(); + if (reader.isStartElement() && reader.name() == QStringLiteral("Incident") && + reader.attributes().value(QStringLiteral("type")).toString() == QStringLiteral("fail")) { + return false; + } + } + return true; + }}, + {QStringLiteral("lightxml"), [](const QByteArray &data) -> bool { + return data.indexOf("\n<Incident type=\"fail\" ") < 0; + }}, + {QStringLiteral("xunitxml"), [](const QByteArray &data) -> bool { + QXmlStreamReader reader{data}; + while (!reader.atEnd()) { + reader.readNext(); + if (reader.isStartElement() && reader.name() == QStringLiteral("testcase") && + reader.attributes().value(QStringLiteral("result")).toString() == QStringLiteral("fail")) { + return false; + } + } + return true; + }}, + {QStringLiteral("teamcity"), [](const QByteArray &data) -> bool { + return data.indexOf("' message='Failure! |[Loc: ") < 0; + }}, + {QStringLiteral("tap"), [](const QByteArray &data) -> bool { + return data.indexOf("\nnot ok ") < 0; + }}, + }; +}; + +static Options g_options; + +static bool execCommand(const QString &command, QByteArray *output = nullptr, bool verbose = false) +{ + if (verbose) + fprintf(stdout, "Execute %s\n", command.toUtf8().constData()); + FILE *process = popen(command.toUtf8().constData(), QT_POPEN_READ); + + if (!process) { + fprintf(stderr, "Cannot execute command %s", qPrintable(command)); + return false; + } + char buffer[512]; + while (fgets(buffer, sizeof(buffer), process)) { + if (output) + output->append(buffer); + if (verbose) + fprintf(stdout, "%s", buffer); + } + return pclose(process) == 0; +} + +// Copy-pasted from qmake/library/ioutil.cpp +inline static bool hasSpecialChars(const QString &arg, const uchar (&iqm)[16]) +{ + for (int x = arg.length() - 1; x >= 0; --x) { + ushort c = arg.unicode()[x].unicode(); + if ((c < sizeof(iqm) * 8) && (iqm[c / 8] & (1 << (c & 7)))) + return true; + } + return false; +} + +static QString shellQuoteUnix(const QString &arg) +{ + // Chars that should be quoted (TM). This includes: + static const uchar iqm[] = { + 0xff, 0xff, 0xff, 0xff, 0xdf, 0x07, 0x00, 0xd8, + 0x00, 0x00, 0x00, 0x38, 0x01, 0x00, 0x00, 0x78 + }; // 0-32 \'"$`<>|;&(){}*?#!~[] + + if (!arg.length()) + return QStringLiteral("\"\""); + + QString ret(arg); + if (hasSpecialChars(ret, iqm)) { + ret.replace(QLatin1Char('\''), QStringLiteral("'\\''")); + ret.prepend(QLatin1Char('\'')); + ret.append(QLatin1Char('\'')); + } + return ret; +} + +static QString shellQuoteWin(const QString &arg) +{ + // Chars that should be quoted (TM). This includes: + // - control chars & space + // - the shell meta chars "&()<>^| + // - the potential separators ,;= + static const uchar iqm[] = { + 0xff, 0xff, 0xff, 0xff, 0x45, 0x13, 0x00, 0x78, + 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x10 + }; + + if (!arg.length()) + return QStringLiteral("\"\""); + + QString ret(arg); + if (hasSpecialChars(ret, iqm)) { + // Quotes are escaped and their preceding backslashes are doubled. + // It's impossible to escape anything inside a quoted string on cmd + // level, so the outer quoting must be "suspended". + ret.replace(QRegExp(QStringLiteral("(\\\\*)\"")), QStringLiteral("\"\\1\\1\\^\"\"")); + // The argument must not end with a \ since this would be interpreted + // as escaping the quote -- rather put the \ behind the quote: e.g. + // rather use "foo"\ than "foo\" + int i = ret.length(); + while (i > 0 && ret.at(i - 1) == QLatin1Char('\\')) + --i; + ret.insert(i, QLatin1Char('"')); + ret.prepend(QLatin1Char('"')); + } + return ret; +} + +static QString shellQuote(const QString &arg) +{ + if (QDir::separator() == QLatin1Char('\\')) + return shellQuoteWin(arg); + else + return shellQuoteUnix(arg); +} + +static bool parseOptions() +{ + QStringList arguments = QCoreApplication::arguments(); + int i = 1; + for (; i < arguments.size(); ++i) { + const QString &argument = arguments.at(i); + if (argument.compare(QStringLiteral("--androiddeployqt"), Qt::CaseInsensitive) == 0) { + if (i + 1 == arguments.size()) + g_options.helpRequested = true; + else + g_options.androidDeployQtCommand = arguments.at(++i).trimmed(); + } else if (argument.compare(QStringLiteral("--adb"), Qt::CaseInsensitive) == 0) { + if (i + 1 == arguments.size()) + g_options.helpRequested = true; + else + g_options.adbCommand = arguments.at(++i); + } else if (argument.compare(QStringLiteral("--path"), Qt::CaseInsensitive) == 0) { + if (i + 1 == arguments.size()) + g_options.helpRequested = true; + else + g_options.buildPath = arguments.at(++i); + } else if (argument.compare(QStringLiteral("--make"), Qt::CaseInsensitive) == 0) { + if (i + 1 == arguments.size()) + g_options.helpRequested = true; + else + g_options.makeCommand = arguments.at(++i); + } else if (argument.compare(QStringLiteral("--apk"), Qt::CaseInsensitive) == 0) { + if (i + 1 == arguments.size()) + g_options.helpRequested = true; + else + g_options.apkPath = arguments.at(++i); + } else if (argument.compare(QStringLiteral("--activity"), Qt::CaseInsensitive) == 0) { + if (i + 1 == arguments.size()) + g_options.helpRequested = true; + else + g_options.activity = arguments.at(++i); + } else if (argument.compare(QStringLiteral("--timeout"), Qt::CaseInsensitive) == 0) { + if (i + 1 == arguments.size()) + g_options.helpRequested = true; + else + g_options.timeout = std::chrono::seconds{arguments.at(++i).toInt()}; + } else if (argument.compare(QStringLiteral("--help"), Qt::CaseInsensitive) == 0) { + g_options.helpRequested = true; + } else if (argument.compare(QStringLiteral("--verbose"), Qt::CaseInsensitive) == 0) { + g_options.verbose = true; + } else if (argument.compare(QStringLiteral("--"), Qt::CaseInsensitive) == 0) { + ++i; + break; + } else { + g_options.testArgsList << arguments.at(i); + } + } + for (;i < arguments.size(); ++i) + g_options.testArgsList << arguments.at(i); + + if (g_options.helpRequested || g_options.androidDeployQtCommand.isEmpty() || g_options.buildPath.isEmpty()) + return false; + + QString serial = qEnvironmentVariable("ANDROID_DEVICE_SERIAL"); + if (!serial.isEmpty()) + g_options.adbCommand += QStringLiteral(" -s %1").arg(serial); + return true; +} + +static void printHelp() +{// "012345678901234567890123456789012345678901234567890123456789012345678901" + fprintf(stderr, "Syntax: %s <options> -- [TESTARGS] \n" + "\n" + " Creates an Android package in a temp directory <destination> and\n" + " runs it on the default emulator/device or on the one specified by\n" + " \"ANDROID_DEVICE_SERIAL\" environment variable.\n\n" + " Mandatory arguments:\n" + " --androiddeployqt <androiddeployqt cmd>: The androiddeployqt:\n" + " path including its additional arguments.\n" + " --path <path>: The path where androiddeployqt will build the .apk.\n" + " Optional arguments:\n" + " --adb <adb cmd>: The Android ADB command. If missing the one from\n" + " $PATH will be used.\n" + " --activity <acitvity>: The Activity to run. If missing the first\n" + " activity from AndroidManifest.qml file will be used.\n" + " --timout <seconds>: Timeout to run the test.\n" + " Default is 5 minutes.\n" + " --make <make cmd>: make command, needed to install the qt library.\n" + " If make is missing make sure the --path is set.\n" + " --apk <apk path>: If the apk is specified and if exists, we'll skip\n" + " the package building.\n" + " -- arguments that will be passed to the test application.\n" + " --verbose: Prints out information during processing.\n" + " --help: Displays this information.\n\n", + qPrintable(QCoreApplication::arguments().at(0)) + ); +} + +static QString packageNameFromAndroidManifest(const QString &androidManifestPath) +{ + QFile androidManifestXml(androidManifestPath); + if (androidManifestXml.open(QIODevice::ReadOnly)) { + QXmlStreamReader reader(&androidManifestXml); + while (!reader.atEnd()) { + reader.readNext(); + if (reader.isStartElement() && reader.name() == QStringLiteral("manifest")) + return reader.attributes().value(QStringLiteral("package")).toString(); + } + } + return {}; +} + +static QString activityFromAndroidManifest(const QString &androidManifestPath) +{ + QFile androidManifestXml(androidManifestPath); + if (androidManifestXml.open(QIODevice::ReadOnly)) { + QXmlStreamReader reader(&androidManifestXml); + while (!reader.atEnd()) { + reader.readNext(); + if (reader.isStartElement() && reader.name() == QStringLiteral("activity")) + return reader.attributes().value(QStringLiteral("android:name")).toString(); + } + } + return {}; +} + +static void setOutputFile(QString file, QString format) +{ + if (file.isEmpty()) + file = QStringLiteral("-"); + if (format.isEmpty()) + format = QStringLiteral("txt"); + + g_options.outFiles[format] = file; +} + +static bool parseTestArgs() +{ + QRegExp newLoggingFormat{QStringLiteral("(.*),(txt|csv|xunitxml|xml|lightxml|teamcity|tap)")}; + QRegExp oldFormats{QStringLiteral("-(txt|csv|xunitxml|xml|lightxml|teamcity|tap)")}; + + QString file; + QString logType; + QString unhandledArgs; + for (int i = 0; i < g_options.testArgsList.size(); ++i) { + const QString &arg = g_options.testArgsList[i].trimmed(); + if (arg == QStringLiteral("-o")) { + if (i >= g_options.testArgsList.size() - 1) + return false; // missing file argument + + const auto &filePath = g_options.testArgsList[++i]; + if (!newLoggingFormat.exactMatch(filePath)) { + file = filePath; + } else { + const auto capturedTexts = newLoggingFormat.capturedTexts(); + setOutputFile(capturedTexts.at(1), capturedTexts.at(2)); + } + } else if (oldFormats.exactMatch(arg)) { + logType = oldFormats.capturedTexts().at(1); + } else { + unhandledArgs += QStringLiteral(" %1").arg(arg); + } + } + if (g_options.outFiles.isEmpty() || !file.isEmpty() || !logType.isEmpty()) + setOutputFile(file, logType); + + for (const auto &format : g_options.outFiles.keys()) + g_options.testArgs += QStringLiteral(" -o output.%1,%1").arg(format); + + g_options.testArgs += unhandledArgs; + g_options.testArgs = QStringLiteral("shell am start -e applicationArguments \"'%1'\" -n %2/%3").arg(shellQuote(g_options.testArgs.trimmed()), + g_options.package, + g_options.activity); + return true; +} + +static bool isRunning() { + QByteArray output; + if (!execCommand(QStringLiteral("%1 shell \"ps | grep ' %2'\"").arg(g_options.adbCommand, + shellQuote(g_options.package)), &output)) { + + return false; + } + return output.indexOf(" " + g_options.package.toUtf8()) > -1; +} + +static bool waitToFinish() +{ + using clock = std::chrono::system_clock; + auto start = clock::now(); + // wait to start + while (!isRunning()) { + std::this_thread::sleep_for(std::chrono::milliseconds(100)); + if ((clock::now() - start) > std::chrono::seconds{10}) + return false; + } + + // Wait to finish + while (isRunning()) { + std::this_thread::sleep_for(std::chrono::milliseconds(250)); + if ((clock::now() - start) > g_options.timeout) + return false; + } + return true; +} + + +static bool pullFiles() +{ + bool ret = true; + for (auto it = g_options.outFiles.constBegin(); it != g_options.outFiles.end(); ++it) { + QByteArray output; + if (!execCommand(QStringLiteral("%1 shell run-as %2 cat files/output.%3") + .arg(g_options.adbCommand, g_options.package, it.key()), &output)) { + return false; + } + auto checkerIt = g_options.checkFiles.find(it.key()); + ret &= checkerIt != g_options.checkFiles.end() && checkerIt.value()(output); + if (it.value() == QStringLiteral("-")){ + fprintf(stdout, "%s", output.constData()); + fflush(stdout); + } else { + QFile out{it.value()}; + if (!out.open(QIODevice::WriteOnly)) + return false; + out.write(output); + } + } + return ret; +} + +struct RunnerLocker +{ + RunnerLocker() + { + runner.acquire(); + } + ~RunnerLocker() + { + runner.release(); + } + QSystemSemaphore runner{QStringLiteral("androidtestrunner"), 1, QSystemSemaphore::Open}; +}; + +int main(int argc, char *argv[]) +{ + QCoreApplication a(argc, argv); + if (!parseOptions()) { + printHelp(); + return 1; + } + + RunnerLocker lock; // do not install or run packages while another test is running + if (!g_options.apkPath.isEmpty() && QFile::exists(g_options.apkPath)) { + if (!execCommand(QStringLiteral("%1 install -r %2") + .arg(g_options.adbCommand, g_options.apkPath), nullptr, g_options.verbose)) { + return 1; + } + } else { + if (!g_options.makeCommand.isEmpty()) { + // we need to run make INSTALL_ROOT=path install to install the application file(s) first + if (!execCommand(QStringLiteral("%1 INSTALL_ROOT=%2 install") + .arg(g_options.makeCommand, g_options.buildPath), nullptr, g_options.verbose)) { + return 1; + } + } + + // Run androiddeployqt + static auto verbose = g_options.verbose ? QStringLiteral("--verbose") : QStringLiteral(); + if (!execCommand(QStringLiteral("%1 %3 --reinstall --output %2 --apk %4").arg(g_options.androidDeployQtCommand, + g_options.buildPath, + verbose, + g_options.apkPath), nullptr, true)) { + return 1; + } + } + + QString manifest = g_options.buildPath + QStringLiteral("/AndroidManifest.xml"); + g_options.package = packageNameFromAndroidManifest(manifest); + if (g_options.activity.isEmpty()) + g_options.activity = activityFromAndroidManifest(manifest); + + // parseTestArgs depends on g_options.package + if (!parseTestArgs()) + return 1; + + // start the tests + bool res = execCommand(QStringLiteral("%1 %2").arg(g_options.adbCommand, g_options.testArgs), + nullptr, g_options.verbose) && waitToFinish(); + if (res) + res &= pullFiles(); + res &= execCommand(QStringLiteral("%1 uninstall %2").arg(g_options.adbCommand, g_options.package), + nullptr, g_options.verbose); + fflush(stdout); + return res ? 0 : 1; +} diff --git a/src/tools/bootstrap/bootstrap.pro b/src/tools/bootstrap/bootstrap.pro index 40c0702f0a..8598fc2721 100644 --- a/src/tools/bootstrap/bootstrap.pro +++ b/src/tools/bootstrap/bootstrap.pro @@ -60,6 +60,8 @@ SOURCES += \ ../../corelib/kernel/qmetatype.cpp \ ../../corelib/kernel/qvariant.cpp \ ../../corelib/kernel/qsystemerror.cpp \ + ../../corelib/kernel/qsharedmemory.cpp \ + ../../corelib/kernel/qsystemsemaphore.cpp \ ../../corelib/plugin/quuid.cpp \ ../../corelib/serialization/qdatastream.cpp \ ../../corelib/serialization/qjson.cpp \ @@ -103,6 +105,12 @@ SOURCES += \ ../../xml/sax/qxml.cpp unix:SOURCES += ../../corelib/kernel/qcore_unix.cpp \ + ../../corelib/kernel/qsharedmemory_posix.cpp \ + ../../corelib/kernel/qsharedmemory_systemv.cpp \ + ../../corelib/kernel/qsharedmemory_unix.cpp \ + ../../corelib/kernel/qsystemsemaphore_posix.cpp \ + ../../corelib/kernel/qsystemsemaphore_systemv.cpp \ + ../../corelib/kernel/qsystemsemaphore_unix.cpp \ ../../corelib/io/qfilesystemengine_unix.cpp \ ../../corelib/io/qfilesystemiterator_unix.cpp \ ../../corelib/io/qfsfileengine_unix.cpp @@ -112,12 +120,18 @@ win32:SOURCES += ../../corelib/global/qoperatingsystemversion_win.cpp \ ../../corelib/io/qfilesystemiterator_win.cpp \ ../../corelib/io/qfsfileengine_win.cpp \ ../../corelib/kernel/qcoreapplication_win.cpp \ + ../../corelib/kernel/qsharedmemory_win.cpp \ + ../../corelib/kernel/qsystemsemaphore_win.cpp \ ../../corelib/plugin/qsystemlibrary.cpp \ mac { SOURCES += \ ../../corelib/kernel/qcoreapplication_mac.cpp \ - ../../corelib/kernel/qcore_mac.cpp + ../../corelib/kernel/qcore_mac.cpp \ + ../../corelib/io/qfilesystemengine_unix.cpp \ + ../../corelib/io/qfilesystemiterator_unix.cpp \ + ../../corelib/io/qfsfileengine_unix.cpp + OBJECTIVE_SOURCES += \ ../../corelib/global/qoperatingsystemversion_darwin.mm \ ../../corelib/kernel/qcore_mac_objc.mm \ diff --git a/src/tools/moc/generator.cpp b/src/tools/moc/generator.cpp index ab7e400f47..41d0bbf2a1 100644 --- a/src/tools/moc/generator.cpp +++ b/src/tools/moc/generator.cpp @@ -1001,7 +1001,7 @@ void Generator::generateMetacall() needUser |= p.user.endsWith(')'); } - fprintf(out, "\n#ifndef QT_NO_PROPERTIES\n "); + fprintf(out, "\n#ifndef QT_NO_PROPERTIES\n "); if (needElse) fprintf(out, "else "); fprintf(out, diff --git a/src/tools/qfloat16-tables/gen_qfloat16_tables.cpp b/src/tools/qfloat16-tables/gen_qfloat16_tables.cpp deleted file mode 100644 index 17fc978039..0000000000 --- a/src/tools/qfloat16-tables/gen_qfloat16_tables.cpp +++ /dev/null @@ -1,163 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 by Southwest Research Institute (R) -** Contact: http://www.qt-project.org/legal -** -** This file is part of the QtCore module 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 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 Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** 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-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include <qfile.h> -#include <qdebug.h> - -quint32 convertmantissa(qint32 i) -{ - quint32 m = i << 13; // Zero pad mantissa bits - quint32 e = 0; // Zero exponent - - while (!(m & 0x00800000)) { // While not normalized - e -= 0x00800000; // Decrement exponent (1<<23) - m <<= 1; // Shift mantissa - } - m &= ~0x00800000; // Clear leading 1 bit - e += 0x38800000; // Adjust bias ((127-14)<<23) - return m | e; // Return combined number -} - -// we first build these tables up and then print them out as a separate step in order -// to more closely map the implementation given in the paper. -quint32 basetable[512]; -quint32 shifttable[512]; - -#define PRINTHEX(a) "0x" + QByteArray::number(a,16).toUpper() + "U,\n" - -qint32 main(qint32 argc, char **argv) -{ - if (argc < 2) { - qWarning() << "Must provide output filename as argument."; - return -1; - } - - QFile fid(QFile::decodeName(argv[1])); - if (!fid.open(QIODevice::WriteOnly | QIODevice::Text)) { - qWarning() << "Abort: Failed to open/create file" << fid.fileName(); - return -1; - } - quint32 i; - - fid.write("/* This file was generated by gen_qfloat16_tables.cpp */\n\n"); - fid.write("#include <QtCore/qfloat16.h>\n\n"); - - fid.write("QT_BEGIN_NAMESPACE\n\n"); - fid.write("#if !defined(__F16C__) && !defined(__ARM_FP16_FORMAT_IEEE)\n\n"); - - fid.write("const quint32 qfloat16::mantissatable[2048] = {\n"); - fid.write("0,\n"); - for (i = 1; i < 1024; i++) - fid.write(PRINTHEX(convertmantissa(i))); - for (i = 1024; i < 2048; i++) - fid.write(PRINTHEX(0x38000000U + ((i - 1024) << 13))); - fid.write("};\n\n"); - - fid.write("const quint32 qfloat16::exponenttable[64] = {\n"); - fid.write("0,\n"); - for (i = 1; i < 31; i++) - fid.write(PRINTHEX(i << 23)); - fid.write("0x47800000U,\n"); // 31 - fid.write("0x80000000U,\n"); // 32 - for (i = 33; i < 63; i++) - fid.write(PRINTHEX(0x80000000U + ((i - 32) << 23))); - fid.write("0xC7800000U,\n"); // 63 - fid.write("};\n\n"); - - fid.write("const quint32 qfloat16::offsettable[64] = {\n"); - fid.write("0,\n"); - for (i = 1; i < 32; i++) - fid.write("1024U,\n"); - fid.write("0,\n"); - for (i = 33; i < 64; i++) - fid.write("1024U,\n"); - fid.write("};\n\n"); - - qint32 e; - for (i = 0; i < 256; ++i) { - e = i - 127; - if (e < -24) { // Very small numbers map to zero - basetable[i | 0x000] = 0x0000; - basetable[i | 0x100] = 0x8000; - shifttable[i | 0x000] = 24; - shifttable[i | 0x100] = 24; - - } else if (e < -14) { // Small numbers map to denorms - basetable[i | 0x000] = (0x0400 >> (-e - 14)); - basetable[i | 0x100] = (0x0400 >> (-e - 14)) | 0x8000; - shifttable[i | 0x000] = -e - 1; - shifttable[i | 0x100] = -e - 1; - - } else if (e <= 15) { // Normal numbers just lose precision - basetable[i | 0x000] = ((e + 15) << 10); - basetable[i | 0x100] = ((e + 15) << 10) | 0x8000; - shifttable[i | 0x000] = 13; - shifttable[i | 0x100] = 13; - - } else if (e < 128) { // Large numbers map to Infinity - basetable[i | 0x000] = 0x7C00; - basetable[i | 0x100] = 0xFC00; - shifttable[i | 0x000] = 24; - shifttable[i | 0x100] = 24; - - } else { // Infinity and NaN's stay Infinity and NaN's - basetable[i | 0x000] = 0x7C00; - basetable[i | 0x100] = 0xFC00; - shifttable[i | 0x000] = 13; - shifttable[i | 0x100] = 13; - } - } - - fid.write("const quint32 qfloat16::basetable[512] = {\n"); - for (i = 0; i < 512; i++) - fid.write(PRINTHEX(basetable[i])); - - fid.write("};\n\n"); - - fid.write("const quint32 qfloat16::shifttable[512] = {\n"); - for (i = 0; i < 512; i++) - fid.write(PRINTHEX(shifttable[i])); - - fid.write("};\n\n"); - - fid.write("#endif // !__F16C__ && !__ARM_FP16_FORMAT_IEEE\n\n"); - fid.write("QT_END_NAMESPACE\n"); - fid.close(); - return 0; -} diff --git a/src/tools/qfloat16-tables/qfloat16-tables.pro b/src/tools/qfloat16-tables/qfloat16-tables.pro deleted file mode 100644 index a7d10ac197..0000000000 --- a/src/tools/qfloat16-tables/qfloat16-tables.pro +++ /dev/null @@ -1,9 +0,0 @@ -option(host_build) - -CONFIG += force_bootstrap -SOURCES += gen_qfloat16_tables.cpp - -load(qt_tool) - -lib.CONFIG = dummy_install -INSTALLS = lib diff --git a/src/tools/rcc/rcc.cpp b/src/tools/rcc/rcc.cpp index 08fb6fca5f..94f6911010 100644 --- a/src/tools/rcc/rcc.cpp +++ b/src/tools/rcc/rcc.cpp @@ -67,11 +67,8 @@ enum { # define CONSTANT_COMPRESSALGO_DEFAULT RCCResourceLibrary::CompressionAlgorithm::None #endif -#define writeString(s) write(s, sizeof(s)) - void RCCResourceLibrary::write(const char *str, int len) { - --len; // trailing \0 on string literals... int n = m_out.size(); m_out.resize(n + len); memcpy(m_out.data() + n, str, len); @@ -983,7 +980,7 @@ void RCCResourceLibrary::writeDecimal(int value) Q_ASSERT(m_format != RCCResourceLibrary::Binary); char buf[std::numeric_limits<int>::digits10 + 2]; int n = snprintf(buf, sizeof(buf), "%d", value); - write(buf, n + 1); // write() takes a size including terminating NUL + write(buf, n); } static const char hexDigits[] = "0123456789abcdef"; diff --git a/src/tools/rcc/rcc.h b/src/tools/rcc/rcc.h index b301355e4f..190c37a1f6 100644 --- a/src/tools/rcc/rcc.h +++ b/src/tools/rcc/rcc.h @@ -143,6 +143,7 @@ private: void writeChar(char c) { m_out.append(c); } void writeByteArray(const QByteArray &); void write(const char *, int len); + void writeString(const char *s) { write(s, static_cast<int>(strlen(s))); } #if QT_CONFIG(zstd) ZSTD_CCtx *m_zstdCCtx; diff --git a/src/tools/uic/cpp/cppwriteincludes.h b/src/tools/uic/cpp/cppwriteincludes.h index 79cbd41014..aadc6f54fc 100644 --- a/src/tools/uic/cpp/cppwriteincludes.h +++ b/src/tools/uic/cpp/cppwriteincludes.h @@ -82,7 +82,7 @@ private: void add(const QString &className, bool determineHeader = true, const QString &header = QString(), bool global = false); private: - typedef std::set<QString> OrderedSet; + using OrderedSet = std::set<QString>; void insertIncludeForClass(const QString &className, QString header = QString(), bool global = false); void insertInclude(const QString &header, bool global); void writeHeaders(const OrderedSet &headers, bool global); @@ -97,7 +97,7 @@ private: QSet<QString> m_knownClasses; - typedef QMap<QString, QString> StringMap; + using StringMap = QMap<QString, QString>; StringMap m_classToHeader; StringMap m_oldHeaderToNewHeader; diff --git a/src/tools/uic/cpp/cppwriteinitialization.cpp b/src/tools/uic/cpp/cppwriteinitialization.cpp index 440758cf41..85b9a9f60b 100644 --- a/src/tools/uic/cpp/cppwriteinitialization.cpp +++ b/src/tools/uic/cpp/cppwriteinitialization.cpp @@ -498,9 +498,7 @@ void WriteInitialization::acceptUI(DomUI *node) << language::startFunctionDefinition1("setupUi", parameterType, varName, m_option.indent); const QStringList connections = m_uic->databaseInfo()->connections(); - for (int i=0; i<connections.size(); ++i) { - QString connection = connections.at(i); - + for (const auto &connection : connections) { if (connection == QLatin1String("(default)")) continue; @@ -706,7 +704,7 @@ void WriteInitialization::acceptWidget(DomWidget *node) addWizardPage(varName, node, parentWidget); } else if (m_uic->customWidgetsInfo()->extends(parentClass, QLatin1String("QToolBox"))) { const DomProperty *plabel = attributes.value(QLatin1String("label")); - DomString *plabelString = plabel ? plabel->elementString() : 0; + DomString *plabelString = plabel ? plabel->elementString() : nullptr; QString icon; if (const DomProperty *picon = attributes.value(QLatin1String("icon"))) icon = QLatin1String(", ") + iconCall(picon); // Side effect: Writes icon definition @@ -729,7 +727,7 @@ void WriteInitialization::acceptWidget(DomWidget *node) } } else if (m_uic->customWidgetsInfo()->extends(parentClass, QLatin1String("QTabWidget"))) { const DomProperty *ptitle = attributes.value(QLatin1String("title")); - DomString *ptitleString = ptitle ? ptitle->elementString() : 0; + DomString *ptitleString = ptitle ? ptitle->elementString() : nullptr; QString icon; if (const DomProperty *picon = attributes.value(QLatin1String("icon"))) icon = QLatin1String(", ") + iconCall(picon); // Side effect: Writes icon definition @@ -844,7 +842,7 @@ void WriteInitialization::addButtonGroup(const DomWidget *buttonNode, const QStr const DomButtonGroup *group = m_driver->findButtonGroup(attributeName); // Legacy feature: Create missing groups on the fly as the UIC button group feature // was present before the actual Designer support (4.5) - const bool createGroupOnTheFly = group == 0; + const bool createGroupOnTheFly = group == nullptr; if (createGroupOnTheFly) { DomButtonGroup *newGroup = new DomButtonGroup; newGroup->setAttributeName(attributeName); @@ -900,8 +898,7 @@ void WriteInitialization::acceptLayout(DomLayout *node) if (m_layoutWidget) { bool left, top, right, bottom; left = top = right = bottom = false; - for (int i = 0; i < propList.size(); ++i) { - const DomProperty *p = propList.at(i); + for (const DomProperty *p : propList) { const QString propertyName = p->attributeName(); if (propertyName == QLatin1String("leftMargin") && p->kind() == DomProperty::Number) left = true; @@ -2619,7 +2616,6 @@ static void generateMultiDirectiveEnd(QTextStream &outputStream, const QSet<QStr WriteInitialization::Item::Item(const QString &itemClassName, const QString &indent, QTextStream &setupUiStream, QTextStream &retranslateUiStream, Driver *driver) : - m_parent(0), m_itemClassName(itemClassName), m_indent(indent), m_setupUiStream(setupUiStream), diff --git a/src/tools/uic/cpp/cppwriteinitialization.h b/src/tools/uic/cpp/cppwriteinitialization.h index 0ee001469c..3cd0efeaac 100644 --- a/src/tools/uic/cpp/cppwriteinitialization.h +++ b/src/tools/uic/cpp/cppwriteinitialization.h @@ -85,8 +85,8 @@ namespace CPP { struct WriteInitialization : public TreeWalker { - typedef QList<DomProperty*> DomPropertyList; - typedef QHash<QString, DomProperty*> DomPropertyMap; + using DomPropertyList = QList<DomProperty*>; + using DomPropertyMap = QHash<QString, DomProperty*>; WriteInitialization(Uic *uic); @@ -161,7 +161,7 @@ private: // special initialization // class Item { - Q_DISABLE_COPY(Item) + Q_DISABLE_COPY_MOVE(Item) public: Item(const QString &itemClassName, const QString &indent, QTextStream &setupUiStream, QTextStream &retranslateUiStream, Driver *driver); ~Item(); @@ -188,7 +188,7 @@ private: ItemData m_setupUiData; ItemData m_retranslateUiData; QList<Item *> m_children; - Item *m_parent; + Item *m_parent = nullptr; const QString m_itemClassName; const QString m_indent; @@ -259,13 +259,13 @@ private: QVector<Buddy> m_buddies; QSet<QString> m_buttonGroups; - typedef QHash<uint, QString> ColorBrushHash; + using ColorBrushHash = QHash<uint, QString>; ColorBrushHash m_colorBrushHash; // Map from font properties to font variable name for reuse // Map from size policy to variable for reuse - typedef QMap<FontHandle, QString> FontPropertiesNameMap; - typedef QMap<IconHandle, QString> IconPropertiesNameMap; - typedef QMap<SizePolicyHandle, QString> SizePolicyNameMap; + using FontPropertiesNameMap = QMap<FontHandle, QString>; + using IconPropertiesNameMap = QMap<IconHandle, QString>; + using SizePolicyNameMap = QMap<SizePolicyHandle, QString>; FontPropertiesNameMap m_fontPropertiesNameMap; IconPropertiesNameMap m_iconPropertiesNameMap; SizePolicyNameMap m_sizePolicyNameMap; diff --git a/src/tools/uic/customwidgetsinfo.h b/src/tools/uic/customwidgetsinfo.h index 8a10999027..a1b24ab042 100644 --- a/src/tools/uic/customwidgetsinfo.h +++ b/src/tools/uic/customwidgetsinfo.h @@ -62,7 +62,7 @@ public: bool isCustomWidgetContainer(const QString &className) const; private: - typedef QMap<QString, DomCustomWidget*> NameCustomWidgetMap; + using NameCustomWidgetMap = QMap<QString, DomCustomWidget*>; NameCustomWidgetMap m_customWidgets; }; diff --git a/src/tools/uic/databaseinfo.cpp b/src/tools/uic/databaseinfo.cpp index fa5d5f5df0..9b0d1614ab 100644 --- a/src/tools/uic/databaseinfo.cpp +++ b/src/tools/uic/databaseinfo.cpp @@ -33,9 +33,7 @@ QT_BEGIN_NAMESPACE -DatabaseInfo::DatabaseInfo() -{ -} +DatabaseInfo::DatabaseInfo() = default; void DatabaseInfo::acceptUI(DomUI *node) { @@ -59,10 +57,9 @@ void DatabaseInfo::acceptWidget(DomWidget *node) DomProperty *db = properties.value(QLatin1String("database")); if (db && db->elementStringList()) { QStringList info = db->elementStringList()->elementString(); - - QString connection = info.size() > 0 ? info.at(0) : QString(); - if (connection.isEmpty()) + if (info.isEmpty() || info.constFirst().isEmpty()) return; + const QString &connection = info.constFirst(); m_connections.append(connection); QString table = info.size() > 1 ? info.at(1) : QString(); diff --git a/src/tools/uic/driver.cpp b/src/tools/uic/driver.cpp index eb88032e59..8b9b4806e6 100644 --- a/src/tools/uic/driver.cpp +++ b/src/tools/uic/driver.cpp @@ -256,7 +256,7 @@ bool Driver::uic(const QString &fileName, DomUI *ui, QTextStream *out) QTextStream *oldOutput = m_output; - m_output = out != 0 ? out : &m_stdout; + m_output = out != nullptr ? out : &m_stdout; Uic tool(this); const bool result = tool.write(ui); diff --git a/src/tools/uic/main.cpp b/src/tools/uic/main.cpp index e689d477bd..5c30e4d239 100644 --- a/src/tools/uic/main.cpp +++ b/src/tools/uic/main.cpp @@ -130,7 +130,7 @@ int runUic(int argc, char *argv[]) return !driver.printDependencies(inputFile); } - QTextStream *out = 0; + QTextStream *out = nullptr; QFile f; if (!driver.option().outputFile.isEmpty()) { f.setFileName(driver.option().outputFile); diff --git a/src/tools/uic/treewalker.h b/src/tools/uic/treewalker.h index 7e8eda57d9..3777229517 100644 --- a/src/tools/uic/treewalker.h +++ b/src/tools/uic/treewalker.h @@ -77,6 +77,9 @@ class DomButtonGroup; struct TreeWalker { + Q_DISABLE_COPY_MOVE(TreeWalker) + + TreeWalker() = default; inline virtual ~TreeWalker() = default; virtual void acceptUI(DomUI *ui); @@ -101,7 +104,7 @@ struct TreeWalker virtual void acceptTime(DomTime *time); virtual void acceptDateTime(DomDateTime *dateTime); virtual void acceptProperty(DomProperty *property); - typedef QVector<DomWidget *> DomWidgets; + using DomWidgets = QVector<DomWidget *>; virtual void acceptIncludes(DomIncludes *includes); virtual void acceptInclude(DomInclude *incl); virtual void acceptAction(DomAction *action); diff --git a/src/tools/uic/uic.cpp b/src/tools/uic/uic.cpp index b95f1a784b..207356f28d 100644 --- a/src/tools/uic/uic.cpp +++ b/src/tools/uic/uic.cpp @@ -69,7 +69,7 @@ bool Uic::printDependencies() return false; } - DomUI *ui = 0; + DomUI *ui = nullptr; { QXmlStreamReader reader; reader.setDevice(&f); @@ -178,7 +178,7 @@ static double versionFromUiAttribute(QXmlStreamReader &reader) DomUI *Uic::parseUiFile(QXmlStreamReader &reader) { - DomUI *ui = 0; + DomUI *ui = nullptr; const QString uiElement = QLatin1String("ui"); while (!reader.atEnd()) { @@ -189,7 +189,7 @@ DomUI *Uic::parseUiFile(QXmlStreamReader &reader) if (version < 4.0) { const QString msg = QString::fromLatin1("uic: File generated with too old version of Qt Designer (%1)").arg(version); fprintf(stderr, "%s\n", qPrintable(msg)); - return 0; + return nullptr; } ui = new DomUI(); @@ -201,7 +201,7 @@ DomUI *Uic::parseUiFile(QXmlStreamReader &reader) } if (reader.hasError()) { delete ui; - ui = 0; + ui = nullptr; fprintf(stderr, "%s\n", qPrintable(QString::fromLatin1("uic: Error in line %1, column %2 : %3") .arg(reader.lineNumber()).arg(reader.columnNumber()) .arg(reader.errorString()))); |