summaryrefslogtreecommitdiffstats
path: root/lib/gitversion.pl
diff options
context:
space:
mode:
authorDavid Lamparter <equinox@opensourcerouting.org>2012-11-27 02:34:56 +0100
committerDavid Lamparter <equinox@opensourcerouting.org>2012-12-12 15:34:37 +0100
commit0be793e674c8b076f0e8bf327257f15803480f49 (patch)
tree28c42a679265d25ea41f4265232e2bcc167b1f49 /lib/gitversion.pl
parentzebra: include intf when sending IPv4 nexthop to FPM (diff)
downloadfrr-0be793e674c8b076f0e8bf327257f15803480f49.tar.xz
frr-0be793e674c8b076f0e8bf327257f15803480f49.zip
build: include git info
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>
Diffstat (limited to 'lib/gitversion.pl')
-rw-r--r--lib/gitversion.pl47
1 files changed, 47 insertions, 0 deletions
diff --git a/lib/gitversion.pl b/lib/gitversion.pl
new file mode 100644
index 000000000..448f13d67
--- /dev/null
+++ b/lib/gitversion.pl
@@ -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
+