Add git version string
authorMichael Jeanson <mjeanson@efficios.com>
Tue, 1 May 2018 18:30:02 +0000 (14:30 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Wed, 12 Sep 2018 19:26:54 +0000 (15:26 -0400)
Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
.gitignore
cli/babeltrace-cfg-cli-args.c
include/Makefile.am
include/version.h [new file with mode: 0644]

index a1740cb1f087058f9b7ef6eada9886f2398308a3..edcf8edc9ce6eb1f93b561350e7de2c2bba47329 100644 (file)
@@ -64,6 +64,8 @@ plugins/ctf/common/metadata/parser.output
 /cli/babeltrace-log.bin
 /include/config.h
 /include/config.h.in
+/include/version.i
+/include/version.i.tmp
 /config.status
 *.log
 aclocal.m4
index 58739d26d51f8f850aeab06a60bbb29e15812f7d..3af66edf2274a76e0fe66a053f43a90d21e91491 100644 (file)
@@ -41,6 +41,7 @@
 #include "babeltrace-cfg.h"
 #include "babeltrace-cfg-cli-args.h"
 #include "babeltrace-cfg-cli-args-connect.h"
+#include "version.h"
 
 /*
  * Error printf() macro which prepends "Error: " the first time it's
@@ -729,7 +730,11 @@ end:
 static
 void print_version(void)
 {
-       puts("Babeltrace " VERSION);
+       if (GIT_VERSION[0] == '\0') {
+               puts("Babeltrace " VERSION);
+       } else {
+               puts("Babeltrace " VERSION  " - " GIT_VERSION);
+       }
 }
 
 /*
index c026e74cfbb373c8a0e9cdb18332ee8eb90a2a7c..669e003bd620a80db0ba295cd109aa55237a9b40 100644 (file)
@@ -1,3 +1,73 @@
+##
+## This target generates an include file that contains the git version
+## string of the current branch, it must be continuously updated when
+## we build in the git repo and shipped in dist tarballs to reflect the
+## status of the tree when it was generated. If the tree is clean and
+## the current commit is tag a starting with "v", consider this a
+## release version and set an empty git version.
+##
+## Here is what the inline script does:
+##
+## First, delete any stale "version.i.tmp" file.
+##
+## If "bootstrap" and ".git" exists in the top source directory and the git
+## executable is available, get the current git version string in the form:
+##
+##  "latest_tag"(-"number_of_commits_on_top")(-g"latest_commit_hash")(-dirty)
+##
+## And store it in "version.i.tmp", if the current commit is tagged, the tag
+## starts with "v" and the tree is clean, consider this a release version and
+## overwrite the git version with an empty string in "version.i.tmp".
+##
+## If we don't have a "version.i.tmp" nor a "version.i", generate an empty
+## string as a failover.
+##
+## If we don't have a "version.i" or we have both files and they are different,
+## copy "version.i.tmp" over "version.i". This way the dependent targets are
+## only rebuilt when the version string changes.
+##
+
+version_verbose = $(version_verbose_@AM_V@)
+version_verbose_ = $(version_verbose_@AM_DEFAULT_V@)
+version_verbose_0 = @echo "  GEN       " $@;
+
+version.i:
+       $(version_verbose)rm -f version.i.tmp; \
+       if (test -r "$(top_srcdir)/bootstrap" && test -r "$(top_srcdir)/.git") && \
+                       test -x "`which git 2>&1;true`"; then \
+               GIT_VERSION_STR="`cd "$(top_srcdir)" && git describe --tags --dirty`"; \
+               GIT_CURRENT_TAG="`cd "$(top_srcdir)" && git describe --tags --exact-match --match="v[0-9]*" HEAD 2> /dev/null`"; \
+               echo "#define GIT_VERSION \"$$GIT_VERSION_STR\"" > version.i.tmp; \
+               if ! $(GREP) -- "-dirty" version.i.tmp > /dev/null && \
+                               test "x$$GIT_CURRENT_TAG" != "x"; then \
+                       echo "#define GIT_VERSION \"\"" > version.i.tmp; \
+               fi; \
+       fi; \
+       if test ! -f version.i.tmp; then \
+               if test ! -f version.i; then \
+                       echo '#define GIT_VERSION ""' > version.i; \
+               fi; \
+       elif test ! -f version.i || \
+                       test x"`cat version.i.tmp`" != x"`cat version.i`"; then \
+               mv version.i.tmp version.i; \
+       fi; \
+       rm -f version.i.tmp; \
+       true
+
+##
+## version.i is defined as a .PHONY target even if it's a real file,
+## we want the target to be re-run on every make.
+##
+.PHONY: version.i
+
+CLEANFILES = version.i.tmp
+
+##
+## Only clean "version.i" on dist-clean, we need to keep it on regular
+## clean when it's part of a dist tarball.
+##
+DISTCLEANFILES = version.i
+
 # Core API
 babeltraceincludedir = "$(includedir)/babeltrace"
 babeltraceinclude_HEADERS = \
@@ -151,4 +221,6 @@ noinst_HEADERS = \
        babeltrace/plugin/plugin-so-internal.h \
        babeltrace/prio-heap-internal.h \
        babeltrace/ref-internal.h \
-       babeltrace/values-internal.h
+       babeltrace/values-internal.h \
+       version.h \
+       version.i
diff --git a/include/version.h b/include/version.h
new file mode 100644 (file)
index 0000000..4f80251
--- /dev/null
@@ -0,0 +1,28 @@
+#ifndef VERSION_H
+#define VERSION_H
+
+/*
+ * Copyright (C) 2018 Michael Jeanson <mjeanson@efficios.com>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#include "version.i"
+
+#endif /* VERSION_H */
This page took 0.027957 seconds and 4 git commands to generate.