common: support custom, extra information for build's version
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Tue, 21 Jan 2020 14:55:43 +0000 (09:55 -0500)
committerPhilippe Proulx <eeppeliteloop@gmail.com>
Tue, 21 Jan 2020 19:30:19 +0000 (14:30 -0500)
This patch adds a system of extra version information also found in
LTTng-tools.

`src/common/Makefile` generates `src/common/version.i` at every build.
This file contains:

* The current Git revision description.

* Extra name of the version (found in `version/extra_version_name`).

* Extra description of the version (found in
  `version/extra_version_description`).

* A list of patch file names found in `version/extra_patches`.

All definitions can be empty strings.

See `version/README.adoc` to learn more.

As of this patch, libbabeltrace2 does not offer getters for this data
and the CLI does not print it with the `--version` option. This is
reserved for subsequent patches.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: Ife50e5bcaa6b3bdeda6ee4e7c1fdeb2fb1f63887
Reviewed-on: https://review.lttng.org/c/babeltrace/+/2836
Reviewed-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Reviewed-by: Michael Jeanson <mjeanson@efficios.com>
Tested-by: jenkins <jenkins@lttng.org>
.gitignore
Makefile.am
src/cli/babeltrace2-cfg-cli-args.c
src/common/Makefile.am
version/README.adoc [new file with mode: 0644]
version/extra_patches/README.adoc [new file with mode: 0644]

index 16baf519da7b235bfd3152c0df1cfb33da9d2e64..a9a11a57c5a58f954027ff9fc7ecf2873559ccd4 100644 (file)
@@ -69,3 +69,4 @@ cscope*
 *.swp
 .theia
 compile_commands.json
+/version
index f49ba956e851efacb1ebe5bd3d0e6a9322b16e0b..7197944092b86733dd9bcb39629d80ec5c6442b3 100644 (file)
@@ -10,3 +10,5 @@ dist_doc_DATA = ChangeLog LICENSE mit-license.txt gpl-2.0.txt \
                std-ext-lib.txt README.adoc CONTRIBUTING.adoc
 
 dist_noinst_DATA = CodingStyle
+
+EXTRA_DIST = version
index 420e1efc0926ec18a98acfcd08c44caaf2c46ef0..73d67d7785d50f42ff89788d28dd4a10a5a07dd5 100644 (file)
@@ -197,10 +197,10 @@ end:
 static
 void print_version(void)
 {
-       if (GIT_VERSION[0] == '\0') {
+       if (BT_VERSION_GIT[0] == '\0') {
                puts("Babeltrace " VERSION);
        } else {
-               puts("Babeltrace " VERSION  " - " GIT_VERSION);
+               puts("Babeltrace " VERSION  " - " BT_VERSION_GIT);
        }
 }
 
index 16508165d77e42b2329606ca34b751c0a417b246..941bbaacdd0000c4dc15f1dde11647833981f0cd 100644 (file)
@@ -15,9 +15,9 @@ noinst_HEADERS = \
        list.h \
        macros.h \
        mmap-align.h \
-       safe.h \
-       version.h \
-       version.i
+       safe.h
+
+# The following section is based on a similar feature in LTTng-tools.
 
 ##
 ## This target generates an include file that contains the git version
@@ -41,34 +41,61 @@ noinst_HEADERS = \
 ## 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.
+## string as a failover. If a "version.i" is present, for example when building
+## from a distribution tarball, get the git_version using grep.
 ##
-## 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.
+## Fetch the BT_VERSION_EXTRA_NAME define from "version/extra_version_name" and output it
+## to "version.i.tmp".
+##
+## Fetch the BT_VERSION_EXTRA_DESCRIPTION define from "version/extra_version_description",
+## sanitize and format it with a sed script to replace all non-alpha-numeric values
+## with "-" and join all lines by replacing "\n" with litteral string c-style "\n" and
+## output it to "version.i.tmp".
+##
+## Repeat the same logic for the "version/extra_patches" directory.
+## Data fetched from "version/extra_patches" must be sanitized and
+## formatted.
+## The data is fetched using "ls" with an ignore pattern for the README.adoc file.
+## The sanitize step uses sed with a script to replace all
+## non-alpha-numeric values, except " " (space), to "-".
+## The formatting step uses sed with a script to join all lines
+## by replacing "\n" with litteral string c-style "\n".
+##
+## If we don't have a "version.i" or we have both files (version.i, version.i.tmp)
+## and they are different, copy "version.i.tmp" over "version.i".
+## This way the dependent targets are only rebuilt when the git version
+## string or either one of extra version string change.
 ##
-
 version_verbose = $(version_verbose_@AM_V@)
 version_verbose_ = $(version_verbose_@AM_DEFAULT_V@)
-version_verbose_0 = @echo "  GEN     " $@;
+version_verbose_0 = @echo "  GEN       " $@;
 
 version.i:
        $(version_verbose)rm -f version.i.tmp; \
+       if (test ! -f version.i && test -f "$(top_srcdir)/include/version.i"); then \
+               cp "$(top_srcdir)/include/version.i" version.i; \
+       fi; \
        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; \
+               echo "#define BT_VERSION_GIT \"$$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; \
+                       echo "#define BT_VERSION_GIT \"\"" > version.i.tmp; \
                fi; \
        fi; \
        if test ! -f version.i.tmp; then \
-               if test ! -f version.i; then \
-                       echo '#define GIT_VERSION ""' > version.i; \
+               if test -f version.i; then \
+                       $(GREP) "^#define \bBT_VERSION_GIT\b.*" version.i > version.i.tmp; \
+               else \
+                       echo '#define BT_VERSION_GIT ""' > version.i.tmp; \
                fi; \
-       elif test ! -f version.i || \
+       fi; \
+       echo "#define BT_VERSION_EXTRA_NAME \"`$(SED) -n '1p' "$(top_srcdir)/version/extra_version_name" 2> /dev/null`\"" >> version.i.tmp; \
+       echo "#define BT_VERSION_EXTRA_DESCRIPTION \"`$(SED) -E ':a ; N ; $$!ba ; s/[^a-zA-Z0-9 \n\t\.,]/-/g ; s/\r{0,1}\n/\\\n/g' "$(top_srcdir)/version/extra_version_description" 2> /dev/null`\"" >> version.i.tmp; \
+       echo "#define BT_VERSION_EXTRA_PATCHES \"`ls --ignore='README.adoc' -1 "$(top_srcdir)/version/extra_patches" | $(SED) -E ':a ; N ; $$!ba ; s/[^a-zA-Z0-9 \n\t\.]/-/g ; s/\r{0,1}\n/\\\n/g' 2> /dev/null`\"" >> version.i.tmp; \
+       if test ! -f version.i || \
                        test x"`cat version.i.tmp`" != x"`cat version.i`"; then \
                mv version.i.tmp version.i; \
        fi; \
@@ -88,3 +115,5 @@ CLEANFILES = version.i.tmp
 ## clean when it's part of a dist tarball.
 ##
 DISTCLEANFILES = version.i
+
+noinst_HEADERS += version.h version.i
diff --git a/version/README.adoc b/version/README.adoc
new file mode 100644 (file)
index 0000000..7039b48
--- /dev/null
@@ -0,0 +1,33 @@
+= Babeltrace's version extra information
+
+This directory contains files and a directory to add information to the
+version of a Babeltrace build. The CLI (`--version` option) and library
+can provide this information.
+
+The following directory and files are scanned at `src/common/version.i`
+generation time, which occurs at **every build**:
+
+`extra_version_name`::
+    If it exists, the first line of this file is the extra name of the
+    custom version.
+
+`extra_version_description`::
+    If it exists, the file's contents is the extra description of the
+    custom version.
++
+This should contain a description of local modifications applied to the
+source tree. A distribution packager can use this file, for example, to
+specify what changes were applied locally.
++
+All characters except alphanumeric ones, whitespaces, `.`, and `,` are
+replaced with `-`.
+
+`extra_patches`::
+    If it exists, this directory contains patch files applied to the
+    source tree.
++
+Each file name is included when generating `src/common/version.i`,
+except `README.adoc`.
++
+All characters except alphanumeric ones, whitespaces, and `.` are
+replaced with `-`.
diff --git a/version/extra_patches/README.adoc b/version/extra_patches/README.adoc
new file mode 100644 (file)
index 0000000..97ce76b
--- /dev/null
@@ -0,0 +1,3 @@
+= Babeltrace's version extra information patches
+
+NOTE: See the parent directory's `README.adoc` file.
This page took 0.02878 seconds and 4 git commands to generate.