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 :)
- // 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();
+
- 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);
+ }