]> asedeno.scripts.mit.edu Git - PuTTY.git/commitdiff
Show the git commit hash in local dev builds too.
authorSimon Tatham <anakin@pobox.com>
Sat, 21 Jan 2017 14:57:31 +0000 (14:57 +0000)
committerSimon Tatham <anakin@pobox.com>
Sat, 21 Jan 2017 14:57:31 +0000 (14:57 +0000)
This is perhaps the more useful end of the mechanism I added in the
previous commit: now, when a developer runs a configure+make build
from a git checkout (rather than from a bob-built source tarball), the
Makefile will automatically run 'git rev-parse HEAD' and embed the
result in the binaries.

So now when I want to deploy my own bleeding-edge code for day-to-day
use on my own machine, I can easily check whether I've done it right
(e.g. did I install to the right prefix?), and also easily check
whether any given PuTTY or pterm has been restarted since I rolled out
a new version.

In order to arrange this (and in particular to force version.o to be
rebuilt when _any_ source file changes), I've had to reintroduce some
of the slightly painful Makefile nastiness that I removed in 4d8782e74
when I retired the 'manifest' system, namely having version.o depend
on a file empty.h, which in turn is trivially rebuilt by a custom make
rule whose dependencies include $(allsources). That's a bit
unfortunate, but I think acceptable: the main horribleness of the
manifest system was not that part, but the actual _manifests_, which
were there to arrange that if you modified the sources in a
distribution tarball the binaries would automatically switch to
reporting themselves as local builds rather than the version baked
into the tarball. I haven't reintroduced that part of the system: if
you check out a given git commit, modify the checked-out sources, and
build the result, the Makefile won't make any inconvenient attempts to
detect that, and the resulting build will still announce itself as the
git commit you started from.

Recipe
version.c
version.h

diff --git a/Recipe b/Recipe
index 379f9b6b7fe9173bebaa4014663a907be5d4e857..952373f20e25bab0c92335cd431bd5b62d5fef0c 100644 (file)
--- a/Recipe
+++ b/Recipe
 # ------------------------------------------------------------
 # Additional text added verbatim to each individual Makefile.
 
+!cflags am version -DSOURCE_COMMIT=\"`git rev-parse HEAD 2>/dev/null`\"
+!begin am
+BUILT_SOURCES = empty.h
+CLEANFILES = empty.h
+empty.h: $(allsources)
+       echo '/* Empty file touched by automake makefile to force rebuild of version.o */' >$@
+
+!end
+!begin >empty.h
+/* Empty file touched by automake makefile to force rebuild of version.o */
+!end
+
 !begin vc vars
 CFLAGS = $(CFLAGS) /DHAS_GSSAPI
 !end
index 231c1a75b803c1c031980bab8f82b866e8714163..59e9ca758f5a445eea7ee549f08b9034eead1aa8 100644 (file)
--- a/version.c
+++ b/version.c
@@ -8,6 +8,10 @@
  * to do here is to drop it into variables of the right names.
  */
 
+#ifdef SOURCE_COMMIT
+#include "empty.h"
+#endif
+
 #include "version.h"
 
 const char ver[] = TEXTVER;
index a9fab69248f0ebfec5390097d09ac1a81db70268..26242ad6d9e368ec4526112f0c10fba7bcd20c34 100644 (file)
--- a/version.h
+++ b/version.h
 #define TEXTVER "Unidentified build"
 #define SSHVER "PuTTY-Unidentified-Local-Build"
 #define BINARY_VERSION 0,0,0,0
+
+#ifndef SOURCE_COMMIT
+/*
+ * git commit id from which this build was made. This is defined by
+ * Buildscr for official builds - both source archives and prebuilt
+ * binaries - in the course of overwriting this file as described
+ * above. But we put it here under ifdef, so that it can also be
+ * passed in on the command line for Unix local development builds,
+ * which I treat specially because Unix developers - e.g. me - are
+ * quite likely to run 'make install' straight out of their dev
+ * directory so as to use the bleeding-edge code for day-to-day
+ * running.
+ *
+ * Windows doesn't really need the same treatment, because the easiest
+ * way to install a build properly on Windows is to run the installer,
+ * and the easiest way to do that is to run Buildscr, which will
+ * populate this field its own way. It's only the Unix automake build
+ * where you might go straight from local 'make' to 'make install'
+ * without going through Buildscr.
+ */
 #define SOURCE_COMMIT "unavailable"
+#endif