Add git commit id to the version if it's not a tag
authorRaphaël Beamonte <raphael.beamonte@gmail.com>
Wed, 11 Dec 2013 16:39:41 +0000 (11:39 -0500)
committerDavid Goulet <dgoulet@efficios.com>
Tue, 13 May 2014 18:23:36 +0000 (14:23 -0400)
Signed-off-by: Raphaël Beamonte <raphael.beamonte@gmail.com>
Signed-off-by: David Goulet <dgoulet@efficios.com>
.gitignore
Makefile.am
include/Makefile.am
include/version.h.tmpl [new file with mode: 0644]
src/bin/lttng-sessiond/lttng-sessiond.h
src/bin/lttng/commands/version.c
src/bin/lttng/lttng.c
src/bin/lttng/utils.h

index b2ab0724e00de6f5e5ca4db92321b343d7b3a35b..052ffe4b744faff7259a1d60d65c0ee0cd52ce81 100644 (file)
@@ -82,3 +82,5 @@ health_check
 /tests/unit/ini_config/ini_config
 
 /benchmark/
+
+/include/version.h
index 584f59b2e63102d1fb687a988899eb32746f4753..c6c7af5ceb92b66ad7f3e7e140a0957f1ca9e3ac 100644 (file)
@@ -1,9 +1,9 @@
 ACLOCAL_AMFLAGS = -I config
 
-SUBDIRS = src \
+SUBDIRS = include \
+                 src \
                  tests \
                  extras \
-                 include \
                  doc
 
 dist_doc_DATA = LICENSE \
index 547857edb8f62e5072eeda76637cd4459d71876f..24f2f57aa2479a22093fdf802b290539cd6afd4e 100644 (file)
@@ -1,9 +1,83 @@
+##
+## The version.h file must be verified and generated or updated if the
+## git commit id (called git version here) changed since the last build
+## of lttng-tools.
+##
+version.h:
+       ##
+       ## We first create variables for the current git version and
+       ## the locations of the version.h and version.h.tmpl files
+       ##
+       @echo -n "Generating version.h ... "
+       @(version_h_tmpl="$(top_builddir)/include/version.h.tmpl"; \
+       if [ -f "$${version_h_tmpl}" ]; then \
+               version_h="$(top_builddir)/include/version.h"; \
+               ##
+               ## We check the git version format we will use depending on
+               ## whether or not we are in the master branch or on a tag
+               ##
+               git_branch="$$(git describe --all 2>/dev/null)"; \
+               if [ -z "$${git_branch}" ]; then \
+                       git_version=""; \
+               else \
+                       git_describe="$$(git describe)"; \
+                       if [ "$${git_branch}" == "$${git_describe}" ] || \
+                               [ "$${git_branch}" == "heads/master" ]; then \
+                               git_version="$${git_describe}"; \
+                       else \
+                               git_version="$$(git describe --long --all)"; \
+                       fi; \
+               fi; \
+               ##
+               ## If the version.h file doesn't exist or is not up to date,
+               ## We replace it by the version.h.tmpl file
+               ##
+               if [ ! -e "$${version_h}" ] || \
+                       [ "$${version_h_tmpl}" -nt "$${version_h}" ]; then \
+                       cp "$${version_h_tmpl}" "$${version_h}"; \
+               fi; \
+               if [ -n "$${git_version}" ]; then \
+                       ##
+                       ## We remove the leading "v" for the version number
+                       ##
+                       git_version="$$(echo "$${git_version}" | sed -r "s/^v([0-9])/\1/")"; \
+                       ##
+                       ## If we have a git version, we verify that it isn't the same
+                       ## as the one currently in the file (if there is one), as we
+                       ## don't want to update the file if it is already up to date
+                       ##
+                       if [ $$(grep -cE "^#define GIT_VERSION \"?$${git_version}\"?$$" "$${version_h}") -eq 0 ]; then \
+                               if [ $$(grep -c "^#define GIT_VERSION" "$${version_h}") -gt 0 ]; then \
+                                       ##
+                                       ## If there is already a GIT_VERSION defined,
+                                       ## we just replace it by the new version
+                                       ##
+                                       sed -i "s'^#define GIT_VERSION.*$$'#define GIT_VERSION \"$${git_version}\"'" "$${version_h}"; \
+                               else \
+                                       ##
+                                       ## Else, we add a GIT_VERSION define
+                                       ## containing our new version.
+                                       ##
+                                       sed -i "s'^\(#define VERSION_H.*\)$$'\1\n\n#define GIT_VERSION \"$${git_version}\"'" "$${version_h}"; \
+                               fi; \
+                       fi; \
+               fi; \
+       fi)
+       @echo "ok"
+
+##
+## version.h is defined as a .PHONY file even if it's a real file as
+## we want our routine to be runned for each build.
+##
+.PHONY: version.h
+
 lttnginclude_HEADERS = \
        lttng/health.h \
        lttng/lttng.h \
        lttng/lttng-error.h \
        lttng/snapshot.h \
-       lttng/save.h
+       lttng/save.h \
+       version.h
 
 noinst_HEADERS = \
        lttng/snapshot-internal.h \
diff --git a/include/version.h.tmpl b/include/version.h.tmpl
new file mode 100644 (file)
index 0000000..639e6d7
--- /dev/null
@@ -0,0 +1,34 @@
+/*
+ * Copyright (C) 2013-2014 - Raphaël Beamonte <raphael.beamonte@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2 only,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include <config.h>
+
+#ifndef VERSION_H
+#define VERSION_H
+
+#define GIT_VERSION
+
+/*
+ * Define the macro containing the FULL version
+ */
+#ifdef GIT_VERSION
+#define FULL_VERSION "" GIT_VERSION
+#else /* GIT_VERSION */
+#define FULL_VERSION "v" VERSION
+#endif /* GIT_VERSION */
+
+#endif /* VERSION_H */
index 6ee1fe9510ef4d91c64ce6a00034c46101d723cb..0f4c6687892792a338d5a455ad6be574cf07486b 100644 (file)
@@ -1,5 +1,6 @@
 /*
  * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
+ * Copyright (C) 2013 - Raphaël Beamonte <raphael.beamonte@gmail.com>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License, version 2 only,
@@ -28,6 +29,7 @@
 
 #include "session.h"
 #include "ust-app.h"
+#include "version.h"
 
 extern const char default_home_dir[],
        default_tracing_group[],
index 7f69de3dd19a9a1ac438c455ee2231c628c5a93d..f2f435e4bf4c84fa6912450d252595633968d585 100644 (file)
@@ -78,7 +78,7 @@ int cmd_version(int argc, const char **argv)
                }
        }
 
-       MSG("lttng version " VERSION " - " VERSION_NAME);
+       MSG("lttng version " FULL_VERSION " - " VERSION_NAME);
        MSG("\n" VERSION_DESCRIPTION "\n");
        MSG("Web site: http://lttng.org");
        MSG("\nlttng is free software and under the GPL license and part LGPL");
index bc7577d77db148d508614e2a3d2929e1bdfeddb1..3227499f532fefdd3ed378e8d8d171ce7e40be4a 100644 (file)
@@ -89,7 +89,7 @@ static struct cmd_struct commands[] =  {
 
 static void usage(FILE *ofp)
 {
-       fprintf(ofp, "LTTng Trace Control " VERSION" - " VERSION_NAME"\n\n");
+       fprintf(ofp, "LTTng Trace Control " FULL_VERSION" - " VERSION_NAME"\n\n");
        fprintf(ofp, "usage: lttng [OPTIONS] <COMMAND> [<ARGS>]\n");
        fprintf(ofp, "\n");
        fprintf(ofp, "Options:\n");
@@ -131,7 +131,7 @@ static void usage(FILE *ofp)
 
 static void version(FILE *ofp)
 {
-       fprintf(ofp, "%s (LTTng Trace Control) " VERSION" - " VERSION_NAME"\n",
+       fprintf(ofp, "%s (LTTng Trace Control) " FULL_VERSION" - " VERSION_NAME"\n",
                        progname);
 }
 
index 8b9d029f1806385660455c4d56ebf6e2a60ba930..d3941279a316d1c306d2dacd2ba839ae70db0a64 100644 (file)
@@ -19,6 +19,7 @@
 #define _LTTNG_UTILS_H
 
 #include <popt.h>
+#include "version.h"
 
 #include <lttng/lttng.h>
 
This page took 0.029885 seconds and 4 git commands to generate.