From: Manuel Nickschas Date: Mon, 1 Feb 2010 22:16:05 +0000 (+0100) Subject: Don't touch version.gen if nothing version-related changed X-Git-Tag: 0.6-beta1~49 X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=commitdiff_plain;h=f8a3a06fef833858bd93f8441d56a29b82d9bade Don't touch version.gen if nothing version-related changed This avoids unnecessarily recompiling main.cpp (and hence relinking all three binaries) twice with every make. Funnily enough, even though we've had genversion misbehaving for several years, I never before thought about simply comparing the old with the new contents prior to touching the file. Thanks to MisterN for poking me and making me think about a solution :) --- diff --git a/src/common/genversion.cpp b/src/common/genversion.cpp index 946e5000..904e9718 100644 --- a/src/common/genversion.cpp +++ b/src/common/genversion.cpp @@ -100,14 +100,23 @@ int main(int argc, char **argv) { verfile.close(); } - // ok, create our version.gen now + // generate the contents for version.gen + QByteArray contents = QString("QString buildinfo = \"%1,%2,%3,%4,%5,%6,%7,%8\";\n") + .arg(basever, descrver, dirty, committish, commitdate, protover, clientneeds, coreneeds) + .toAscii(); + QFile gen(target); - if(!gen.open(QIODevice::WriteOnly | QIODevice::Text)) { + if(!gen.open(QIODevice::ReadWrite | QIODevice::Text)) { qFatal("%s", qPrintable(QString("Could not write %1!").arg(target))); return EXIT_FAILURE; } - gen.write(QString("QString buildinfo = \"%1,%2,%3,%4,%5,%6,%7,%8\";\n") - .arg(basever, descrver, dirty, committish, commitdate, protover, clientneeds, coreneeds).toAscii()); + QByteArray oldContents = gen.readAll(); + if(oldContents != contents) { // only touch the file if something changed + gen.seek(0); + gen.write(contents); + gen.waitForBytesWritten(10000); + } gen.close(); + return EXIT_SUCCESS; }