- added build time to window title properly

Mon, 28 Apr 2014 17:50:42 +0300

author
Santeri Piippo <crimsondusk64@gmail.com>
date
Mon, 28 Apr 2014 17:50:42 +0300
changeset 745
ab8adddc0f5c
parent 744
bbe0e1834065
child 746
893c43b337dd

- added build time to window title properly

src/main.h file | annotate | diff | comparison | revisions
src/mainWindow.cc file | annotate | diff | comparison | revisions
src/version.cc file | annotate | diff | comparison | revisions
src/version.h file | annotate | diff | comparison | revisions
updaterevision/updaterevision.c file | annotate | diff | comparison | revisions
--- a/src/main.h	Mon Apr 28 17:34:10 2014 +0300
+++ b/src/main.h	Mon Apr 28 17:50:42 2014 +0300
@@ -36,7 +36,3 @@
 static const std::nullptr_t null = nullptr;
 
 void assertionFailure (const char* file, int line, const char* funcname, const char* expr);
-
-// Version string identifier. These are defined in Version.cc.
-const char* versionString();
-const char* fullVersionString();
--- a/src/mainWindow.cc	Mon Apr 28 17:34:10 2014 +0300
+++ b/src/mainWindow.cc	Mon Apr 28 17:50:42 2014 +0300
@@ -281,9 +281,8 @@
 	title += " [pre-release build]";
 #endif // DEBUG
 
-#ifdef COMPILE_DATE
-	title += " (built " COMPILE_DATE ")";
-#endif // COMPILE_DATE
+	if (compileTimeString()[0] != '\0')
+		title += format (" (built %1)", compileTimeString());
 
 	setWindowTitle (title);
 }
--- a/src/version.cc	Mon Apr 28 17:34:10 2014 +0300
+++ b/src/version.cc	Mon Apr 28 17:50:42 2014 +0300
@@ -27,6 +27,7 @@
 
 char g_versionString[64] = {'\0'};
 char g_fullVersionString[256] = {'\0'};
+char g_buildTime[256] = {'\0'};
 
 // =============================================================================
 //
@@ -59,3 +60,15 @@
 
 	return g_fullVersionString;
 }
+
+// =============================================================================
+//
+const char* compileTimeString()
+{
+#ifdef BUILD_TIME
+	if (g_buildTime[0] == '\0')
+		strcpy (g_buildTime, BUILD_TIME);
+#endif
+
+	return g_buildTime;
+}
--- a/src/version.h	Mon Apr 28 17:34:10 2014 +0300
+++ b/src/version.h	Mon Apr 28 17:50:42 2014 +0300
@@ -53,3 +53,7 @@
 #ifdef RELEASE
 # undef DEBUG
 #endif // RELEASE
+
+const char* versionString();
+const char* fullVersionString();
+const char* compileTimeString();
--- a/updaterevision/updaterevision.c	Mon Apr 28 17:34:10 2014 +0300
+++ b/updaterevision/updaterevision.c	Mon Apr 28 17:50:42 2014 +0300
@@ -13,6 +13,7 @@
 #include <string.h>
 #include <ctype.h>
 #include <errno.h>
+#include <time.h>
 
 #ifdef _WIN32
 #define popen _popen
@@ -38,6 +39,11 @@
 	FILE *stream = NULL;
 	int gotrev = 0, needupdate = 1;
 
+	// [SP] Stuff for build time.
+	time_t now;
+	char currentTime[128];
+	char* cp;
+
 	vertag[0] = '\0';
 	lastlog[0] = '\0';
 
@@ -96,6 +102,9 @@
 		// Read the revision that's in this file already. If it's the same as
 		// what we've got, then we don't need to modify it and can avoid rebuilding
 		// dependant files.
+		// [SP] I'm including build date in the file now so it must always be rebuilt.
+		// In LDForge, this is ony used by the very-quick-to-build version.cc anyway.
+#if 0
 		if (fgets(lasthash, sizeof lasthash, stream) == lasthash)
 		{
 			stripnl(lasthash);
@@ -104,9 +113,24 @@
 				needupdate = 0;
 			}
 		}
+#endif
 		fclose (stream);
 	}
 
+	// [SP] Current time.
+	now = time (NULL);
+	strftime (currentTime, sizeof currentTime, "%F %T %z", localtime (&now));
+
+	// [SP] For some dumb reason asctime includes a newline character. Get rid of it.
+	for (cp = &currentTime[0]; *cp != '\0'; ++cp)
+	{
+		if (*cp == '\n')
+		{
+			*cp = '\0';
+			break;
+		}
+	}
+
 	if (needupdate)
 	{
 		stream = fopen (argv[1], "w");
@@ -122,10 +146,11 @@
 "\n"
 "#define GIT_DESCRIPTION \"%s\"\n"
 "#define GIT_HASH \"%s\"\n"
-"#define GIT_TIME \"%s\"\n",
-			hash, vertag, hash, lastlog);
+"#define GIT_TIME \"%s\"\n"
+"#define BUILD_TIME \"%s\"\n",
+			hash, vertag, hash, lastlog, currentTime);
 		fclose(stream);
-		fprintf(stderr, "%s updated to commit %s.\n", argv[1], vertag);
+		fprintf(stderr, "%s updated to commit %s (build time: %s).\n", argv[1], vertag, currentTime);
 	}
 	else
 	{

mercurial