From c466dd7b9c7ae40617b20f06048799342c66974a Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Mon, 13 Jan 2014 13:38:01 +0100 Subject: [PATCH] windeployqt: Use standard streams. Change-Id: I9c91cb6fef0bfee5c3ab018ae04353022c8e7f33 Reviewed-by: Andrew Knight --- src/windeployqt/main.cpp | 73 ++++++++++++++++++++++++----------------------- src/windeployqt/utils.cpp | 24 +++++++--------- src/windeployqt/utils.h | 20 +++++++++---- 3 files changed, 64 insertions(+), 53 deletions(-) diff --git a/src/windeployqt/main.cpp b/src/windeployqt/main.cpp index dbee326..917f0ff 100644 --- a/src/windeployqt/main.cpp +++ b/src/windeployqt/main.cpp @@ -52,7 +52,7 @@ #include #include -#include +#include QT_BEGIN_NAMESPACE @@ -644,8 +644,8 @@ static bool deployTranslations(const QString &sourcePath, unsigned usedQtModules prefixes.push_back(qmFile); } if (prefixes.isEmpty()) { - fprintf(stderr, "Warning: Could not find any translations in %s (developer build?)\n.", - qPrintable(QDir::toNativeSeparators(sourcePath))); + std::wcerr << "Warning: Could not find any translations in " + << QDir::toNativeSeparators(sourcePath) << " (developer build?)\n."; return true; } // Run lconvert to concatenate all files into a single named "qt_.qm" in the application folder @@ -660,7 +660,7 @@ static bool deployTranslations(const QString &sourcePath, unsigned usedQtModules foreach (const QString &qmFile, sourceDir.entryList(translationNameFilters(usedQtModules, prefix))) arguments.append(qmFile); if (optVerboseLevel) - std::printf("Creating %s...\n", qPrintable(targetFile)); + std::wcout << "Creating " << targetFile << "...\n"; unsigned long exitCode; if (!(flags & SkipUpdateFile) && (!runProcess(binary, arguments, sourcePath, &exitCode, 0, 0, errorMessage) || exitCode)) { @@ -719,7 +719,7 @@ static DeployResult deploy(const Options &options, const int version = qtVersion(qmakeVariables); if (optVerboseLevel > 1) - std::printf("Qt binaries in %s\n", qPrintable(QDir::toNativeSeparators(qtBinDir))); + std::wcout << "Qt binaries in " << QDir::toNativeSeparators(qtBinDir) << '\n'; QStringList dependentQtLibs; bool isDebug; @@ -737,11 +737,12 @@ static DeployResult deploy(const Options &options, || (options.additionalLibraries & QtQmlModule)); if (optVerboseLevel) { - std::printf("%s: %ubit, %s executable", qPrintable(QDir::toNativeSeparators(options.binary)), - wordSize, isDebug ? "debug" : "release"); + std::wcout << QDir::toNativeSeparators(options.binary) + << wordSize << "bit, " << (isDebug ? "debug" : "release") + << QDir::toNativeSeparators(options.binary) << " executable"; if (usesQml2) - std::fputs("[QML]", stdout); - std::fputc('\n', stdout); + std::wcout << "[QML]"; + std::wcout << '\n'; } if (dependentQtLibs.isEmpty()) { @@ -763,7 +764,7 @@ static DeployResult deploy(const Options &options, if (index >= 0) { const QString icuVersion = icuLibs.front().mid(index, numberExpression.matchedLength()); if (optVerboseLevel > 1) - std::printf("Adding ICU version %s\n", qPrintable(icuVersion)); + std::wcout << "Adding ICU version " << icuVersion << '\n'; icuLibs.push_back(QStringLiteral("icudt") + icuVersion + QLatin1String(windowsSharedLibrarySuffix)); } foreach (const QString &icuLib, icuLibs) { @@ -789,7 +790,7 @@ static DeployResult deploy(const Options &options, } foreach (const QString &qmlDirectory, qmlDirectories) { if (optVerboseLevel >= 1) - std::printf("Scanning %s:\n", qPrintable(QDir::toNativeSeparators(qmlDirectory))); + std::wcout << "Scanning " << QDir::toNativeSeparators(qmlDirectory) << ":\n"; const QmlImportScanResult scanResult = runQmlImportScanner(qmlDirectory, qmakeVariables.value(QStringLiteral("QT_INSTALL_QML")), options.platform, isDebug, errorMessage); if (!scanResult.ok) return result; @@ -800,13 +801,15 @@ static DeployResult deploy(const Options &options, return result; } if (optVerboseLevel >= 1) { - std::fputs("QML imports:\n", stdout); - foreach (const QmlImportScanResult::Module &mod, qmlScanResult.modules) - std::printf(" '%s' %s\n", qPrintable(mod.name), qPrintable(QDir::toNativeSeparators(mod.sourcePath))); + std::wcout << "QML imports:\n"; + foreach (const QmlImportScanResult::Module &mod, qmlScanResult.modules) { + std::wcout << " '" << mod.name << "' " + << QDir::toNativeSeparators(mod.sourcePath) << '\n'; + } if (optVerboseLevel >= 2) { - std::fputs("QML plugins:\n", stdout); - foreach (const QString &p, qmlScanResult.plugins) - std::printf(" %s\n", qPrintable(QDir::toNativeSeparators(p))); + std::wcout << "QML plugins:\n"; + foreach (const QString &p, qmlScanResult.plugins) + std::wcout << " " << QDir::toNativeSeparators(p) << '\n'; } } } @@ -831,16 +834,15 @@ static DeployResult deploy(const Options &options, deployedQtLibraries.push_back(libraryPath(libraryLocation, qtModuleEntries[i].libraryName, options.platform, isDebug)); if (optVerboseLevel >= 1) { - std::printf("Direct dependencies: %s\nAll dependencies : %s\nTo be deployed : %s\n", - formatQtModules(result.directlyUsedQtLibraries).constData(), - formatQtModules(result.usedQtLibraries).constData(), - formatQtModules(result.deployedQtLibraries).constData()); + std::wcout << "Direct dependencies: " << formatQtModules(result.directlyUsedQtLibraries).constData() + << "\nAll dependencies : " << formatQtModules(result.usedQtLibraries).constData() + << "\nTo be deployed : " << formatQtModules(result.deployedQtLibraries).constData() << '\n'; } const QStringList plugins = findQtPlugins(result.deployedQtLibraries, qmakeVariables.value(QStringLiteral("QT_INSTALL_PLUGINS")), isDebug, options.platform, &platformPlugin); if (optVerboseLevel > 1) - std::printf("Plugins: %s\n", qPrintable(plugins.join(QLatin1Char(',')))); + std::wcout << "Plugins: " << plugins.join(QLatin1Char(',')) << '\n'; if ((result.deployedQtLibraries & QtGuiModule) && platformPlugin.isEmpty()) { *errorMessage =QStringLiteral("Unable to find the platform plugin."); @@ -863,7 +865,7 @@ static DeployResult deploy(const Options &options, if (options.systemD3dCompiler && options.platform != WinPhoneArm && options.platform != WinPhoneIntel) { const QString d3dCompiler = findD3dCompiler(options.platform, wordSize); if (d3dCompiler.isEmpty()) { - std::fprintf(stderr, "Warning: Cannot find any version of the d3dcompiler DLL.\n"); + std::wcerr << "Warning: Cannot find any version of the d3dcompiler DLL.\n"; } else { deployedQtLibraries.push_back(d3dCompiler); } @@ -897,9 +899,9 @@ static DeployResult deploy(const Options &options, const QString targetDirName = plugin.section(slash, -2, -2); if (!dir.exists(targetDirName)) { if (optVerboseLevel) - std::printf("Creating directory %s.\n", qPrintable(targetDirName)); + std::wcout << "Creating directory " << targetDirName << ".\n"; if (!(options.updateFileFlags & SkipUpdateFile) && !dir.mkdir(targetDirName)) { - std::fprintf(stderr, "Cannot create %s.\n", qPrintable(targetDirName)); + std::wcerr << "Cannot create " << targetDirName << ".\n"; *errorMessage = QStringLiteral("Cannot create ") + targetDirName + QLatin1Char('.'); return result; } @@ -920,8 +922,9 @@ static DeployResult deploy(const Options &options, foreach (const QmlImportScanResult::Module &module, qmlScanResult.modules) { const QString installPath = module.installPath(options.directory); if (optVerboseLevel > 1) - std::printf("Installing: '%s' from %s to %s\n", - qPrintable(module.name), qPrintable(module.sourcePath), qPrintable(QDir::toNativeSeparators(installPath))); + std::wcout << "Installing: '" << module.name + << "' from " << module.sourcePath << " to " + << QDir::toNativeSeparators(installPath) << '\n'; if (installPath != options.directory && !createDirectory(installPath, errorMessage)) return result; if (!updateFile(module.sourcePath, qmlFileEntryFunction, installPath, options.updateFileFlags, options.json, errorMessage)) @@ -984,7 +987,7 @@ int main(int argc, char **argv) QString errorMessage; const int result = parseArguments(QCoreApplication::arguments(), &parser, &options, &errorMessage); if (result & CommandLineParseError) - std::fprintf(stderr, "%s\n\n", qPrintable(errorMessage)); + std::wcerr << errorMessage << "\n\n"; if (result & CommandLineParseHelpRequested) std::fputs(qPrintable(helpText(parser)), stdout); if (result & CommandLineParseError) @@ -994,23 +997,23 @@ int main(int argc, char **argv) } if (qmakeVariables.isEmpty() || xSpec.isEmpty() || !qmakeVariables.contains(QStringLiteral("QT_INSTALL_BINS"))) { - std::fprintf(stderr, "Unable to query qmake: %s\n", qPrintable(errorMessage)); + std::wcerr << "Unable to query qmake: " << errorMessage << '\n'; return 1; } if (options.platform == UnknownPlatform) { - std::fprintf(stderr, "Unsupported platform %s\n", qPrintable(xSpec)); + std::wcerr << "Unsupported platform " << xSpec << '\n'; return 1; } // Create directories if (!createDirectory(options.directory, &errorMessage)) { - std::fprintf(stderr, "%s\n", qPrintable(errorMessage)); + std::wcerr << errorMessage << '\n'; return 1; } if (!options.libraryDirectory.isEmpty() && options.libraryDirectory != options.directory && !createDirectory(options.libraryDirectory, &errorMessage)) { - std::fprintf(stderr, "%s\n", qPrintable(errorMessage)); + std::wcerr << errorMessage << '\n'; return 1; } @@ -1020,7 +1023,7 @@ int main(int argc, char **argv) const DeployResult result = deploy(options, qmakeVariables, &errorMessage); if (!result) { - std::fprintf(stderr, "%s\n", qPrintable(errorMessage)); + std::wcerr << errorMessage << '\n'; return 1; } @@ -1029,9 +1032,9 @@ int main(int argc, char **argv) || ((result.deployedQtLibraries & QtWebKitModule) && (result.directlyUsedQtLibraries & QtQuickModule)))) { if (optVerboseLevel) - std::printf("Deploying: %s...\n", webProcessC); + std::wcout << "Deploying: " << webProcessC << "...\n"; if (!deployWebKit2(qmakeVariables, options, &errorMessage)) { - std::fprintf(stderr, "%s\n", qPrintable(errorMessage)); + std::wcerr << errorMessage << '\n'; return 1; } } diff --git a/src/windeployqt/utils.cpp b/src/windeployqt/utils.cpp index 68c78d7..12163a9 100644 --- a/src/windeployqt/utils.cpp +++ b/src/windeployqt/utils.cpp @@ -63,8 +63,6 @@ # include #endif // !Q_OS_WIN -#include - QT_BEGIN_NAMESPACE int optVerboseLevel = 1; @@ -106,7 +104,7 @@ bool createDirectory(const QString &directory, QString *errorMessage) return false; } if (optVerboseLevel) - std::printf("Creating %s...\n", qPrintable(QDir::toNativeSeparators(directory))); + std::wcout << "Creating " << QDir::toNativeSeparators(directory) << "...\n"; QDir dir; if (!dir.mkpath(directory)) { *errorMessage = QString::fromLatin1("Could not create directory %1."). @@ -135,8 +133,8 @@ QStringList findSharedLibraries(const QDir &directory, Platform platform, bool d if (readPeExecutable(dllPath, &errorMessage, 0, 0, &debugDll)) { matches = debugDll == debug; } else { - std::fprintf(stderr, "Warning: Unable to read %s: %s", - qPrintable(QDir::toNativeSeparators(dllPath)), qPrintable(errorMessage)); + std::wcerr << "Warning: Unable to read " << QDir::toNativeSeparators(dllPath) + << ": " << errorMessage; } } // Windows if (matches) @@ -281,7 +279,7 @@ bool runProcess(const QString &binary, const QStringList &args, foreach (const QString &a, args) appendToCommandLine(a, &commandLine); if (optVerboseLevel > 1) - std::printf("Running: %s\n", qPrintable(commandLine)); + std::wcout << "Running: " << commandLine << '\n'; QScopedArrayPointer commandLineW(new wchar_t[commandLine.size() + 1]); commandLine.toWCharArray(commandLineW.data()); @@ -395,7 +393,7 @@ bool runProcess(const QString &binary, const QStringList &args, } if (!workingDirectory.isEmpty() && !QDir::setCurrent(workingDirectory)) { - std::fprintf(stderr, "Failed to change working directory to %s.\n", qPrintable(workingDirectory)); + std::wcerr << "Failed to change working directory to " << workingDirectory << ".\n"; ::_exit(-1); } @@ -515,7 +513,7 @@ bool updateFile(const QString &sourceFileName, const QStringList &nameFilters, const QFileInfo sourceFileInfo(sourceFileName); const QString targetFileName = targetDirectory + QLatin1Char('/') + sourceFileInfo.fileName(); if (optVerboseLevel > 1) - std::printf("Checking %s, %s\n", qPrintable(sourceFileName), qPrintable(targetFileName)); + std::wcout << "Checking " << sourceFileName << ", " << targetFileName<< '\n'; if (!sourceFileInfo.exists()) { *errorMessage = QString::fromLatin1("%1 does not exist.").arg(QDir::toNativeSeparators(sourceFileName)); @@ -540,7 +538,7 @@ bool updateFile(const QString &sourceFileName, const QStringList &nameFilters, } else { // exists. QDir d(targetDirectory); if (optVerboseLevel) - std::printf("Creating %s.\n", qPrintable( QDir::toNativeSeparators(targetFileName))); + std::wcout << "Creating " << QDir::toNativeSeparators(targetFileName) << ".\n"; if (!(flags & SkipUpdateFile) && !d.mkdir(sourceFileInfo.fileName())) { *errorMessage = QString::fromLatin1("Cannot create directory %1 under %2.") .arg(sourceFileInfo.fileName(), QDir::toNativeSeparators(targetDirectory)); @@ -560,7 +558,7 @@ bool updateFile(const QString &sourceFileName, const QStringList &nameFilters, if (!(flags & ForceUpdateFile) && targetFileInfo.lastModified() >= sourceFileInfo.lastModified()) { if (optVerboseLevel) - std::printf("%s is up to date.\n", qPrintable(sourceFileInfo.fileName())); + std::wcout << sourceFileInfo.fileName() << " is up to date.\n"; if (json) json->addFile(sourceFileName, targetDirectory); return true; @@ -574,7 +572,7 @@ bool updateFile(const QString &sourceFileName, const QStringList &nameFilters, } // target exists QFile file(sourceFileName); if (optVerboseLevel) - std::printf("Updating %s.\n", qPrintable(sourceFileInfo.fileName())); + std::wcout << "Updating " << sourceFileInfo.fileName() << ".\n"; if (!(flags & SkipUpdateFile) && !file.copy(targetFileName)) { *errorMessage = QString::fromLatin1("Cannot copy %1 to %2: %3") .arg(QDir::toNativeSeparators(sourceFileName), @@ -778,8 +776,8 @@ bool readPeExecutable(const QString &peExecutableFileName, QString *errorMessage *isDebugIn = debug; result = true; if (optVerboseLevel > 1) - std::printf("%s: %s %u bit, debug: %d\n", __FUNCTION__, - qPrintable(peExecutableFileName), wordSize, debug); + std::wcout << __FUNCTION__ << ": " << peExecutableFileName + << ' ' << wordSize << " bit, debug: " << debug << '\n'; } while (false); if (fileMemory) diff --git a/src/windeployqt/utils.h b/src/windeployqt/utils.h index b9aa99d..02391e7 100644 --- a/src/windeployqt/utils.h +++ b/src/windeployqt/utils.h @@ -51,7 +51,7 @@ #include #include -#include +#include QT_BEGIN_NAMESPACE @@ -80,6 +80,16 @@ enum ListOption { ListMapping }; +inline std::wostream &operator<<(std::wostream &str, const QString &s) +{ +#ifdef Q_OS_WIN + str << reinterpret_cast(s.utf16()); +#else + str << s.toStdWString(); +#endif + return str; +} + // Container class for JSON output class JsonOutput { @@ -202,7 +212,7 @@ bool updateFile(const QString &sourceFileName, const QFileInfo sourceFileInfo(sourceFileName); const QString targetFileName = targetDirectory + QLatin1Char('/') + sourceFileInfo.fileName(); if (optVerboseLevel > 1) - std::printf("Checking %s, %s\n", qPrintable(sourceFileName), qPrintable(targetFileName)); + std::wcout << "Checking " << sourceFileName << ", " << targetFileName << '\n'; if (!sourceFileInfo.exists()) { *errorMessage = QString::fromLatin1("%1 does not exist.").arg(QDir::toNativeSeparators(sourceFileName)); @@ -253,7 +263,7 @@ bool updateFile(const QString &sourceFileName, } else { // exists. QDir d(targetDirectory); if (optVerboseLevel) - std::printf("Creating %s.\n", qPrintable(targetFileName)); + std::wcout << "Creating " << targetFileName << ".\n"; if (!(flags & SkipUpdateFile) && !d.mkdir(sourceFileInfo.fileName())) { *errorMessage = QString::fromLatin1("Cannot create directory %1 under %2.") .arg(sourceFileInfo.fileName(), QDir::toNativeSeparators(targetDirectory)); @@ -274,7 +284,7 @@ bool updateFile(const QString &sourceFileName, if (!(flags & ForceUpdateFile) && targetFileInfo.lastModified() >= sourceFileInfo.lastModified()) { if (optVerboseLevel) - std::printf("%s is up to date.\n", qPrintable(sourceFileInfo.fileName())); + std::wcout << sourceFileInfo.fileName() << " is up to date.\n"; if (json) json->addFile(sourceFileName, targetDirectory); return true; @@ -288,7 +298,7 @@ bool updateFile(const QString &sourceFileName, } // target exists QFile file(sourceFileName); if (optVerboseLevel) - std::printf("Updating %s.\n", qPrintable(sourceFileInfo.fileName())); + std::wcout << "Updating " << sourceFileInfo.fileName() << ".\n"; if (!(flags & SkipUpdateFile) && !file.copy(targetFileName)) { *errorMessage = QString::fromLatin1("Cannot copy %1 to %2: %3") .arg(QDir::toNativeSeparators(sourceFileName), -- 2.7.4