Don't touch version.gen if nothing version-related changed
authorManuel Nickschas <sputnick@quassel-irc.org>
Mon, 1 Feb 2010 22:16:05 +0000 (23:16 +0100)
committerManuel Nickschas <sputnick@quassel-irc.org>
Mon, 1 Feb 2010 22:16:05 +0000 (23:16 +0100)
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 :)

src/common/genversion.cpp

index 946e500..904e971 100644 (file)
@@ -100,14 +100,23 @@ int main(int argc, char **argv) {
     verfile.close();
   }
 
     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);
   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;
   }
     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();
   gen.close();
+
   return EXIT_SUCCESS;
 }
   return EXIT_SUCCESS;
 }