]> git.puffer.fish Git - mirror/frr.git/commitdiff
build: include git info
authorDavid Lamparter <equinox@opensourcerouting.org>
Tue, 27 Nov 2012 01:34:56 +0000 (01:34 +0000)
committerDavid Lamparter <equinox@opensourcerouting.org>
Wed, 12 Dec 2012 14:34:37 +0000 (15:34 +0100)
If enabled with --with-pkg-gitversion on ./configure, this will append
git version strings and branch information at the following places:
 - overall version number: 0.99.21-g0123456
 - login motd and show version: tag information + git id + branches

Sample output:
  Hello, this is Quagga (version 0.99.21-g14b49ad-dirty).
  Copyright 1996-2005 Kunihiro Ishiguro, et al.

  This is a git build of quagga_0_99_21_release-106-g14b49ad-dirty
  Associated branch(es):
local:master

[v2]: fix build without gitinfo (add "else" branch)
[v2]: fix for repos without any tags (different git describe output)
Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
configure.ac
lib/.gitignore
lib/Makefile.am
lib/command.c
lib/gitversion.pl [new file with mode: 0644]
lib/version.h.in

index 9bbe89f37fa701a66f8a9b23c86588ebc4cec050..fb6efd7eae80c13ef913f57cd8761836701590d8 100755 (executable)
@@ -21,6 +21,7 @@ AC_CANONICAL_TARGET()
 AM_INIT_AUTOMAKE(1.6)
 AM_CONFIG_HEADER(config.h)
 
+AC_PATH_PROG(PERL, perl)
 AC_CHECK_PROG([GAWK],[gawk],[gawk],[not-in-PATH])
 if test "x$GAWK" = "xnot-in-PATH" ; then
        AC_MSG_ERROR([GNU awk is required for lib/memtype.h made by memtypes.awk.
@@ -192,6 +193,12 @@ dnl ----------------------
 AC_ARG_WITH(pkg-extra-version,
        AS_HELP_STRING([--with-pkg-extra-version=VER], [add extra version field, for packagers/distributions]),
        [EXTRAVERSION=$withval],)
+AC_ARG_WITH(pkg-git-version,
+       AS_HELP_STRING([--with-pkg-git-version], [add git information to MOTD and build version string]),
+       [ if test "x$withval" != "xno"; then
+               with_pkg_git_version="1"
+               AC_DEFINE(GIT_VERSION, [1], [include git version info])
+       fi ],)
 AC_ARG_ENABLE(vtysh,
 [  --enable-vtysh          include integrated vty shell for Quagga])
 AC_ARG_ENABLE(ipv6,
@@ -398,11 +405,13 @@ dnl Add extra version string to package
 dnl name, string and version fields.
 dnl -----------------------------------
 if test "x${EXTRAVERSION}" != "x" ; then
-  VERSION=${VERSION}${EXTRAVERSION}
-  PACKAGE_VERSION=${PACKAGE_VERSION}${EXTRAVERSION}
-  PACKAGE_STRING=${PACKAGE_STRING}${EXTRAVERSION}
+  VERSION="${VERSION}${EXTRAVERSION}"
+  PACKAGE_VERSION="${PACKAGE_VERSION}${EXTRAVERSION}"
+  PACKAGE_STRING="${PACKAGE_STRING}${EXTRAVERSION}"
 fi
 
+AM_CONDITIONAL([GIT_VERSION], [test "x$with_pkg_git_version" != "x"])
+
 dnl ------------------------------------
 dnl Check C keywords and standard  types
 dnl ------------------------------------
@@ -611,7 +620,6 @@ dnl ---------------------
 case "${enable_vtysh}" in
   "yes") VTYSH="vtysh";
          AC_DEFINE(VTYSH,,VTY shell)
-        AC_PATH_PROG(PERL, perl)
 dnl     Vtysh uses libreadline, which looks for termcap functions at
 dnl     configure time.  We follow readlines search order.
 dnl     The required procedures are in libtermcap on NetBSD, in
index 00af85a6e0b84d504ce6ed13798bd295ee18d463..02aa432ce16d7b17ef48642bffb4377a87a2bcf0 100644 (file)
@@ -5,6 +5,8 @@ Makefile.in
 *.la
 version.c
 version.h
+gitversion.h
+gitversion.h.tmp
 .deps
 .nfs*
 .libs
index e00ad54dcd258cee6a649e691216109366cb7f0c..690c18ff9f6283257b188ba17e6ea5a96a7b5298 100644 (file)
@@ -14,7 +14,7 @@ libzebra_la_SOURCES = \
        zclient.c sockopt.c smux.c agentx.c snmp.c md5.c if_rmap.c keychain.c privs.c \
        sigevent.c pqueue.c jhash.c memtypes.c workqueue.c
 
-BUILT_SOURCES = memtypes.h route_types.h
+BUILT_SOURCES = memtypes.h route_types.h gitversion.h
 
 libzebra_la_DEPENDENCIES = @LIB_REGEX@
 
@@ -36,3 +36,25 @@ memtypes.h: $(srcdir)/memtypes.c $(srcdir)/memtypes.awk
 
 route_types.h: $(srcdir)/route_types.txt $(srcdir)/route_types.pl
        @PERL@ $(srcdir)/route_types.pl < $(srcdir)/route_types.txt > $@
+
+if GIT_VERSION
+
+# bit of a trick here to always have up-to-date git stamps without triggering
+# unneccessary rebuilds.  .PHONY causes the .tmp file to be rebuilt always,
+# but if we use that on gitversion.h it'll ripple through the .c file deps.
+# (even if gitversion.h's file timestamp doesn't change, make will think it
+# did, because of .PHONY...)
+
+.PHONY: gitversion.h.tmp
+.SILENT: gitversion.h gitversion.h.tmp
+GITH=gitversion.h
+gitversion.h.tmp: $(srcdir)/../.git
+       @PERL@ $(srcdir)/gitversion.pl $(srcdir) > ${GITH}.tmp
+gitversion.h: gitversion.h.tmp
+       { test -f ${GITH} && diff -s -q ${GITH}.tmp ${GITH}; } || cp -v ${GITH}.tmp ${GITH}
+
+else
+.PHONY: gitversion.h
+gitversion.h:
+       /bin/true
+endif
index 64563b5d0265debddd87bb77cb178bbc3b4b5f34..3b3fadac4f8c401d07f23fba188c2e8ab3dd8007 100644 (file)
@@ -84,7 +84,7 @@ static const char *default_motd =
 "\r\n\
 Hello, this is " QUAGGA_PROGNAME " (version " QUAGGA_VERSION ").\r\n\
 " QUAGGA_COPYRIGHT "\r\n\
-\r\n";
+" GIT_INFO "\r\n";
 
 
 static const struct facility_map {
@@ -2409,7 +2409,7 @@ DEFUN (show_version,
 {
   vty_out (vty, "Quagga %s (%s).%s", QUAGGA_VERSION, host.name?host.name:"",
           VTY_NEWLINE);
-  vty_out (vty, "%s%s", QUAGGA_COPYRIGHT, VTY_NEWLINE);
+  vty_out (vty, "%s%s%s", QUAGGA_COPYRIGHT, GIT_INFO, VTY_NEWLINE);
 
   return CMD_SUCCESS;
 }
diff --git a/lib/gitversion.pl b/lib/gitversion.pl
new file mode 100644 (file)
index 0000000..448f13d
--- /dev/null
@@ -0,0 +1,47 @@
+#!/usr/bin/perl -w
+use strict;
+
+my $dir = shift;
+chdir $dir || die "$dir: $!\n";
+
+my $gitdesc = `git describe --always --dirty || echo -- \"0-gUNKNOWN\"`;
+chomp $gitdesc;
+my $gitsuffix = ($gitdesc =~ /([0-9a-fA-F]{7}(-dirty)?)$/) ? $1 : "-gUNKNOWN";
+
+printf STDERR "git suffix: %s\n", $gitsuffix;
+printf "#define GIT_SUFFIX \"%s\"\n", $gitsuffix;
+
+my $gitcommit = `git log -1 --format=\"%H\" || echo DEADBEEF`;
+chomp $gitcommit;
+open(BRANCHES, "git branch -a -v --abbrev=40|") || die "git branch: $!\n";
+my @names = ();
+while (<BRANCHES>) {
+       chomp $_;
+       if (/\s+(.*?)\s+$gitcommit/) {
+               my $branch = $1;
+               if ($branch =~ /^remotes\/(.*?)(\/.*)$/) {
+                       my $path = $2;
+                       my $url = `git config --get "remote.$1.url"`;
+                       chomp $url;
+                       $url =~ s/^(git:|https?:|git@)\/\/github\.com/github/i;
+                       $url =~ s/^(ssh|git):\/\/git\.sv\.gnu\.org\/srv\/git\//savannah:/i;
+                       $url =~ s/^(ssh|git):\/\/git\.savannah\.nongnu\.org\//savannah:/i;
+
+                       push @names, $url.$path;
+               } else {
+                       push @names, 'local:'.$branch;
+               }
+       }
+}
+
+printf STDERR "git branches: %s\n", join(", ", @names);
+
+my $cr = "\\r\\n\\";
+printf <<EOF, $gitdesc, join($cr."\n\\t", @names);
+#define GIT_INFO "$cr
+This is a git build of %s$cr
+Associated branch(es):$cr
+\\t%s$cr
+"
+EOF
+
index 429474d141dabf82ca47beceb342db2f5008e961..7e9985f008ca35a99f2133b1249ee602f94edfc8 100644 (file)
 #ifndef _ZEBRA_VERSION_H
 #define _ZEBRA_VERSION_H
 
+#ifdef GIT_VERSION
+#include "gitversion.h"
+#endif
+
+#ifndef GIT_SUFFIX
+#define GIT_SUFFIX ""
+#endif
+#ifndef GIT_INFO
+#define GIT_INFO ""
+#endif
+
 #define QUAGGA_PROGNAME   "@PACKAGE_NAME@"
 
-#define QUAGGA_VERSION     "@PACKAGE_VERSION@"
+#define QUAGGA_VERSION     "@PACKAGE_VERSION@" GIT_SUFFIX
 
 #define ZEBRA_BUG_ADDRESS "@PACKAGE_BUGREPORT@"