From 8a245c9fc2b4cb1a228d300f9dfbfea28806350f Mon Sep 17 00:00:00 2001 From: Oswald Buddenhagen Date: Mon, 15 Jul 2013 16:01:36 +0200 Subject: prune unused filesDiffer() and writeToFile() functions Change-Id: I470a5b3514260a02e73389d057d89c64b08e05d0 Reviewed-by: Joerg Bornemann --- tools/configure/configureapp.cpp | 43 ---------------------------------------- tools/configure/configureapp.h | 1 - 2 files changed, 44 deletions(-) (limited to 'tools/configure') diff --git a/tools/configure/configureapp.cpp b/tools/configure/configureapp.cpp index 349281dd1e..abc1ba4407 100644 --- a/tools/configure/configureapp.cpp +++ b/tools/configure/configureapp.cpp @@ -92,22 +92,6 @@ static inline void promptKeyPress() exit(0); // Exit cleanly for Ctrl+C } -bool writeToFile(const char* text, const QString &filename) -{ - QByteArray symFile(text); - QFile file(filename); - QDir dir(QFileInfo(file).absoluteDir()); - if (!dir.exists()) - dir.mkpath(dir.absolutePath()); - if (!file.open(QFile::WriteOnly | QFile::Text)) { - cout << "Couldn't write to " << qPrintable(filename) << ": " << qPrintable(file.errorString()) - << endl; - return false; - } - file.write(symFile); - return true; -} - Configure::Configure(int& argc, char** argv) { // Default values for indentation @@ -4286,31 +4270,4 @@ int Configure::platform() const return WINDOWS; } -bool -Configure::filesDiffer(const QString &fn1, const QString &fn2) -{ - QFile file1(fn1), file2(fn2); - if (!file1.open(QFile::ReadOnly) || !file2.open(QFile::ReadOnly)) - return true; - const int chunk = 2048; - int used1 = 0, used2 = 0; - char b1[chunk], b2[chunk]; - while (!file1.atEnd() && !file2.atEnd()) { - if (!used1) - used1 = file1.read(b1, chunk); - if (!used2) - used2 = file2.read(b2, chunk); - if (used1 > 0 && used2 > 0) { - const int cmp = qMin(used1, used2); - if (memcmp(b1, b2, cmp)) - return true; - if ((used1 -= cmp)) - memcpy(b1, b1+cmp, used1); - if ((used2 -= cmp)) - memcpy(b2, b2+cmp, used2); - } - } - return !file1.atEnd() || !file2.atEnd(); -} - QT_END_NAMESPACE diff --git a/tools/configure/configureapp.h b/tools/configure/configureapp.h index 8f95e1fb95..d77b136ac8 100644 --- a/tools/configure/configureapp.h +++ b/tools/configure/configureapp.h @@ -159,7 +159,6 @@ private: QString formatPath(const QString &path); QString formatPaths(const QStringList &paths); - bool filesDiffer(const QString &file1, const QString &file2); QString locateFile(const QString &fileName) const; bool findFile(const QString &fileName) const { return !locateFile(fileName).isEmpty(); } -- cgit v1.2.3 From ca645afdc4f51a4002d715ae02c4c38520257774 Mon Sep 17 00:00:00 2001 From: Oswald Buddenhagen Date: Mon, 15 Jul 2013 16:45:44 +0200 Subject: de-duplicate writeout of config files Change-Id: Iaad06f170cf2be3d3fca533a735b69316347ed5b Reviewed-by: Joerg Bornemann --- tools/configure/configureapp.cpp | 169 ++++++++++++++++++--------------------- tools/configure/configureapp.h | 10 +++ 2 files changed, 90 insertions(+), 89 deletions(-) (limited to 'tools/configure') diff --git a/tools/configure/configureapp.cpp b/tools/configure/configureapp.cpp index abc1ba4407..50b31bbb95 100644 --- a/tools/configure/configureapp.cpp +++ b/tools/configure/configureapp.cpp @@ -2806,21 +2806,19 @@ void Configure::generateOutputVars() void Configure::generateCachefile() { // Generate .qmake.cache - QFile cacheFile(buildPath + "/.qmake.cache"); - if (cacheFile.open(QFile::WriteOnly | QFile::Text)) { // Truncates any existing file. - QTextStream cacheStream(&cacheFile); + { + FileWriter cacheStream(buildPath + "/.qmake.cache"); cacheStream << "QT_SOURCE_TREE = " << formatPath(dictionary["QT_SOURCE_TREE"]) << endl; cacheStream << "QT_BUILD_TREE = " << formatPath(dictionary["QT_BUILD_TREE"]) << endl; - cacheStream.flush(); - cacheFile.close(); + if (!cacheStream.flush()) + dictionary[ "DONE" ] = "error"; } // Generate qmodule.pri - QFile moduleFile(dictionary[ "QT_BUILD_TREE" ] + "/mkspecs/qmodule.pri"); - if (moduleFile.open(QFile::WriteOnly | QFile::Text)) { // Truncates any existing file. - QTextStream moduleStream(&moduleFile); + { + FileWriter moduleStream(dictionary[ "QT_BUILD_TREE" ] + "/mkspecs/qmodule.pri"); moduleStream << "QT_BUILD_PARTS += " << buildParts.join(' ') << endl; if (!skipModules.isEmpty()) @@ -2882,8 +2880,8 @@ void Configure::generateCachefile() for (QStringList::Iterator var = qmakeVars.begin(); var != qmakeVars.end(); ++var) moduleStream << (*var) << endl; - moduleStream.flush(); - moduleFile.close(); + if (!moduleStream.flush()) + dictionary[ "DONE" ] = "error"; } } @@ -3079,9 +3077,8 @@ bool Configure::compilerSupportsFlag(const QString &compilerAndArgs) void Configure::generateQConfigPri() { // Generate qconfig.pri - QFile configFile(dictionary[ "QT_BUILD_TREE" ] + "/mkspecs/qconfig.pri"); - if (configFile.open(QFile::WriteOnly | QFile::Text)) { // Truncates any existing file. - QTextStream configStream(&configFile); + { + FileWriter configStream(dictionary[ "QT_BUILD_TREE" ] + "/mkspecs/qconfig.pri"); configStream << "CONFIG+= "; configStream << dictionary[ "BUILD" ]; @@ -3151,8 +3148,8 @@ void Configure::generateQConfigPri() if (dictionary[ "SHARED" ] == "no") configStream << "QT_DEFAULT_QPA_PLUGIN = q" << qpaPlatformName() << endl; - configStream.flush(); - configFile.close(); + if (!configStream.flush()) + dictionary[ "DONE" ] = "error"; } } @@ -3190,13 +3187,8 @@ QString Configure::addDefine(QString def) void Configure::generateConfigfiles() { - QDir(buildPath).mkpath("src/corelib/global"); - QString outName(buildPath + "/src/corelib/global/qconfig.h"); - QTemporaryFile tmpFile; - QTextStream tmpStream; - - if (tmpFile.open()) { - tmpStream.setDevice(&tmpFile); + { + FileWriter tmpStream(buildPath + "/src/corelib/global/qconfig.h"); if (dictionary[ "QCONFIG" ] == "full") { tmpStream << "/* Everything */" << endl; @@ -3206,8 +3198,7 @@ void Configure::generateConfigfiles() tmpStream << "#ifndef QT_BOOTSTRAPPED" << endl; QFile inFile(sourcePath + "/src/corelib/global/" + configName); if (inFile.open(QFile::ReadOnly)) { - QByteArray buffer = inFile.readAll(); - tmpFile.write(buffer.constData(), buffer.size()); + tmpStream << QTextStream(&inFile).readAll(); inFile.close(); } tmpStream << "#endif // QT_BOOTSTRAPPED" << endl; @@ -3338,68 +3329,40 @@ void Configure::generateConfigfiles() tmpStream<<"#define QT_QPA_DEFAULT_PLATFORM_NAME \"" << qpaPlatformName() << "\""< #include #include +#include #include #include @@ -191,5 +192,14 @@ public: Configure::ProjectType qmakeTemplate; }; +class FileWriter : public QTextStream +{ +public: + FileWriter(const QString &name); + bool flush(); +private: + QString m_name; + QBuffer m_buffer; +}; QT_END_NAMESPACE -- cgit v1.2.3 From 922df2c2339288299fe8d9d5c781397f18532ba3 Mon Sep 17 00:00:00 2001 From: Oswald Buddenhagen Date: Mon, 15 Jul 2013 16:46:28 +0200 Subject: don't change timestamp of unchanged files Change-Id: Ifa5c15a37d072c6c8edb50f8a4343d99ee0dccf9 Reviewed-by: Joerg Bornemann --- tools/configure/configureapp.cpp | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'tools/configure') diff --git a/tools/configure/configureapp.cpp b/tools/configure/configureapp.cpp index 50b31bbb95..5b62e8f106 100644 --- a/tools/configure/configureapp.cpp +++ b/tools/configure/configureapp.cpp @@ -4235,6 +4235,12 @@ FileWriter::FileWriter(const QString &name) bool FileWriter::flush() { QTextStream::flush(); + QFile oldFile(m_name); + if (oldFile.open(QIODevice::ReadOnly | QIODevice::Text)) { + if (oldFile.readAll() == m_buffer.data()) + return true; + oldFile.close(); + } QString dir = QFileInfo(m_name).absolutePath(); if (!QDir().mkpath(dir)) { cout << "Cannot create directory " << qPrintable(QDir::toNativeSeparators(dir)) << ".\n"; -- cgit v1.2.3 From 54987c6bf55b159d3ddb79461439700f6e0111f9 Mon Sep 17 00:00:00 2001 From: Oswald Buddenhagen Date: Wed, 17 Jul 2013 14:34:10 +0200 Subject: default to -compile-examples because of popular confusion. the packaging scripts now need to use -no-compile-examples explicitly. Task-number: QTBUG-32449 Change-Id: Iecab1f345afe21e540204fe69a2292ef932cbb61 Reviewed-by: Andy Shaw Reviewed-by: Joerg Bornemann --- tools/configure/configureapp.cpp | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) (limited to 'tools/configure') diff --git a/tools/configure/configureapp.cpp b/tools/configure/configureapp.cpp index 5b62e8f106..a6376bbb7d 100644 --- a/tools/configure/configureapp.cpp +++ b/tools/configure/configureapp.cpp @@ -256,7 +256,7 @@ Configure::Configure(int& argc, char** argv) dictionary[ "BUILDDEV" ] = "no"; - dictionary[ "COMPILE_EXAMPLES" ] = "auto"; + dictionary[ "COMPILE_EXAMPLES" ] = "yes"; dictionary[ "C++11" ] = "auto"; @@ -1702,7 +1702,7 @@ bool Configure::displayHelp() desc( "-skip ", "Exclude an entire module from the build.\n"); - desc( "-compile-examples", "Compile examples even in a production build.\n"); + desc( "-no-compile-examples", "Install only the sources of examples.\n"); desc("WIDGETS", "no", "-no-widgets", "Disable Qt Widgets module.\n"); desc("GUI", "no", "-no-gui", "Disable Qt GUI module.\n"); @@ -1987,13 +1987,6 @@ QString Configure::defaultTo(const QString &option) && (!QFile::exists(sourcePath + "/.git"))) return "no"; - // Do not actually build the examples in production builds with -prefix, unless requested - if (option == "COMPILE_EXAMPLES" - && QDir::cleanPath(dictionary[ "QT_BUILD_TREE" ]) - != QDir::cleanPath(dictionary[ "QT_INSTALL_PREFIX" ]) - && dictionary[ "BUILDDEV" ] == "no") - return "no"; - return "yes"; } -- cgit v1.2.3