Add extra version information framework
authorMichael Jeanson <mjeanson@efficios.com>
Fri, 29 Jun 2018 21:28:30 +0000 (17:28 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Thu, 5 Jul 2018 18:17:43 +0000 (14:17 -0400)
Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
.gitignore
Kbuild.common
extra-version-git.sh [new file with mode: 0755]
extra-version-name.sh [new file with mode: 0755]
extra-version-patches.sh [new file with mode: 0755]
extra_version/README [new file with mode: 0644]
extra_version/patches/README [new file with mode: 0644]
lttng-events.c

index f22e828ee1877f9a42578c0b955e0bbdc1bdb47d..38e1684190c2dc6104b188950254472f321eddca 100644 (file)
@@ -79,3 +79,5 @@ GTAGS
 *.orig
 *~
 \#*#
+
+/extra_version
index c0d54093be967a26d9b02071041b7f173c3e6715..bd24e801d7a94d8f93814acd8019b942da60bb6c 100644 (file)
@@ -34,6 +34,20 @@ ifneq ($(RT_PATCH_VERSION), 0)
   ccflags-y += -DRT_PATCH_VERSION=$(RT_PATCH_VERSION)
 endif
 
+EXTRA_VERSION_NAME:=$(shell $(TOP_LTTNG_MODULES_DIR)/extra-version-name.sh $(TOP_LTTNG_MODULES_DIR))
+
+ifneq ($(EXTRA_VERSION_NAME), 0)
+  ccflags-y += -DLTTNG_EXTRA_VERSION_NAME='"$(EXTRA_VERSION_NAME)"'
+endif
+
+EXTRA_VERSION_GIT:=$(shell $(TOP_LTTNG_MODULES_DIR)/extra-version-git.sh $(TOP_LTTNG_MODULES_DIR))
+
+ifneq ($(EXTRA_VERSION_GIT), 0)
+  ccflags-y += -DLTTNG_EXTRA_VERSION_GIT='"$(EXTRA_VERSION_GIT)"'
+endif
+
+EXTRA_VERSION_PATCHES:=$(shell $(TOP_LTTNG_MODULES_DIR)/extra-version-patches.sh $(TOP_LTTNG_MODULES_DIR))
+
 # Starting with kernel 4.12, the ftrace header was moved to private headers
 # and as such is not available when building against distro headers instead
 # of the full kernel sources. In the situation, define LTTNG_FTRACE_MISSING_HEADER
diff --git a/extra-version-git.sh b/extra-version-git.sh
new file mode 100755 (executable)
index 0000000..e5a3e17
--- /dev/null
@@ -0,0 +1,20 @@
+#!/bin/sh
+# SPDX-License-Identifier: (GPL-2.0 OR LGPL-2.1)
+
+# First argument is the path to the lttng modules sources.
+TOP_LTTNG_MODULES_DIR="$1"
+
+GIT_VERSION="0"
+
+if test -x "$(which git 2>&1;true)" && test -r "${TOP_LTTNG_MODULES_DIR}/.git"; then
+       GIT_VERSION_STR="$(cd "${TOP_LTTNG_MODULES_DIR}" && git describe --tags --dirty)"
+       GIT_CURRENT_TAG="$(cd "${TOP_LTTNG_MODULES_DIR}" && git describe --tags --exact-match --match="v[0-9]*" HEAD 2> /dev/null)"
+
+       GIT_VERSION="${GIT_VERSION_STR}"
+
+       if ! echo "${GIT_VERSION_STR}" | grep -- "-dirty" >/dev/null && test "x$GIT_CURRENT_TAG" != "x"; then
+               GIT_VERSION="0"
+       fi
+fi
+
+echo "${GIT_VERSION}"
diff --git a/extra-version-name.sh b/extra-version-name.sh
new file mode 100755 (executable)
index 0000000..f704256
--- /dev/null
@@ -0,0 +1,13 @@
+#!/bin/sh
+# SPDX-License-Identifier: (GPL-2.0 OR LGPL-2.1)
+
+# First argument is the path to the lttng modules sources.
+TOP_LTTNG_MODULES_DIR="$1"
+
+EXTRA_VERSION_NAME="$(sed -n '1p' "${TOP_LTTNG_MODULES_DIR}/extra_version/name" 2> /dev/null)"
+
+if [ "x${EXTRA_VERSION_NAME}" != "x" ]; then
+       echo "${EXTRA_VERSION_NAME}"
+else
+       echo "0"
+fi
diff --git a/extra-version-patches.sh b/extra-version-patches.sh
new file mode 100755 (executable)
index 0000000..4e8a1b5
--- /dev/null
@@ -0,0 +1,21 @@
+#!/bin/sh
+# SPDX-License-Identifier: (GPL-2.0 OR LGPL-2.1)
+
+# First argument is the path to the lttng modules sources.
+TOP_LTTNG_MODULES_DIR="$1"
+
+if ! test -d "${TOP_LTTNG_MODULES_DIR}"; then
+       exit 1
+fi
+
+TMPFILE="$(mktemp)"
+
+find "${TOP_LTTNG_MODULES_DIR}/extra_version/patches/" -maxdepth 1 ! -name 'README' -type f -printf '%f\n' | sort -r \
+       | sed -E 's/[^a-zA-Z0-9 \.]/-/g ; s/(.*)/MODULE_INFO(extra_version_patch, "\1");/g' >"${TMPFILE}" 2>/dev/null
+
+if test ! -f "${TOP_LTTNG_MODULES_DIR}/extra_version/patches.i" || \
+       test x"$(cat "${TMPFILE}")" != x"$(cat "${TOP_LTTNG_MODULES_DIR}/extra_version/patches.i")"; then
+       mv "${TMPFILE}" "${TOP_LTTNG_MODULES_DIR}/extra_version/patches.i"
+fi
+
+rm -f "${TMPFILE}"
diff --git a/extra_version/README b/extra_version/README
new file mode 100644 (file)
index 0000000..5eef496
--- /dev/null
@@ -0,0 +1,2 @@
+The first line of the "name" file is used to populate the "extra_version_name"
+modinfo key of each built module.
diff --git a/extra_version/patches/README b/extra_version/patches/README
new file mode 100644 (file)
index 0000000..22ea3d3
--- /dev/null
@@ -0,0 +1,2 @@
+The name of each file in this directory except this README will be used to
+populate a "extra_version_path" modinfo key for each built module.
index ec44502318d8ec132eb3835e8bdc828112010724..c1f00ff5c9000ac8d6c32026a00b17baa773cad5 100644 (file)
@@ -2809,12 +2809,22 @@ static int __init lttng_events_init(void)
        ret = lttng_init_cpu_hotplug();
        if (ret)
                goto error_hotplug;
-       printk(KERN_NOTICE "LTTng: Loaded modules v%s.%s.%s%s (%s)\n",
+       printk(KERN_NOTICE "LTTng: Loaded modules v%s.%s.%s%s (%s)%s%s\n",
                __stringify(LTTNG_MODULES_MAJOR_VERSION),
                __stringify(LTTNG_MODULES_MINOR_VERSION),
                __stringify(LTTNG_MODULES_PATCHLEVEL_VERSION),
                LTTNG_MODULES_EXTRAVERSION,
-               LTTNG_VERSION_NAME);
+               LTTNG_VERSION_NAME,
+#ifdef LTTNG_EXTRA_VERSION_GIT
+               LTTNG_EXTRA_VERSION_GIT[0] == '\0' ? "" : " - " LTTNG_EXTRA_VERSION_GIT,
+#else
+               "",
+#endif
+#ifdef LTTNG_EXTRA_VERSION_NAME
+               LTTNG_EXTRA_VERSION_NAME[0] == '\0' ? "" : " - " LTTNG_EXTRA_VERSION_NAME);
+#else
+               "");
+#endif
        return 0;
 
 error_hotplug:
@@ -2827,12 +2837,22 @@ error_kmem:
        lttng_tracepoint_exit();
 error_tp:
        lttng_context_exit();
-       printk(KERN_NOTICE "LTTng: Failed to load modules v%s.%s.%s%s (%s)\n",
+       printk(KERN_NOTICE "LTTng: Failed to load modules v%s.%s.%s%s (%s)%s%s\n",
                __stringify(LTTNG_MODULES_MAJOR_VERSION),
                __stringify(LTTNG_MODULES_MINOR_VERSION),
                __stringify(LTTNG_MODULES_PATCHLEVEL_VERSION),
                LTTNG_MODULES_EXTRAVERSION,
-               LTTNG_VERSION_NAME);
+               LTTNG_VERSION_NAME,
+#ifdef LTTNG_EXTRA_VERSION_GIT
+               LTTNG_EXTRA_VERSION_GIT[0] == '\0' ? "" : " - " LTTNG_EXTRA_VERSION_GIT,
+#else
+               "",
+#endif
+#ifdef LTTNG_EXTRA_VERSION_NAME
+               LTTNG_EXTRA_VERSION_NAME[0] == '\0' ? "" : " - " LTTNG_EXTRA_VERSION_NAME);
+#else
+               "");
+#endif
        return ret;
 }
 
@@ -2850,16 +2870,33 @@ static void __exit lttng_events_exit(void)
        kmem_cache_destroy(event_cache);
        lttng_tracepoint_exit();
        lttng_context_exit();
-       printk(KERN_NOTICE "LTTng: Unloaded modules v%s.%s.%s%s (%s)\n",
+       printk(KERN_NOTICE "LTTng: Unloaded modules v%s.%s.%s%s (%s)%s%s\n",
                __stringify(LTTNG_MODULES_MAJOR_VERSION),
                __stringify(LTTNG_MODULES_MINOR_VERSION),
                __stringify(LTTNG_MODULES_PATCHLEVEL_VERSION),
                LTTNG_MODULES_EXTRAVERSION,
-               LTTNG_VERSION_NAME);
+               LTTNG_VERSION_NAME,
+#ifdef LTTNG_EXTRA_VERSION_GIT
+               LTTNG_EXTRA_VERSION_GIT[0] == '\0' ? "" : " - " LTTNG_EXTRA_VERSION_GIT,
+#else
+               "",
+#endif
+#ifdef LTTNG_EXTRA_VERSION_NAME
+               LTTNG_EXTRA_VERSION_NAME[0] == '\0' ? "" : " - " LTTNG_EXTRA_VERSION_NAME);
+#else
+               "");
+#endif
 }
 
 module_exit(lttng_events_exit);
 
+#include "extra_version/patches.i"
+#ifdef LTTNG_EXTRA_VERSION_GIT
+MODULE_INFO(extra_version_git, LTTNG_EXTRA_VERSION_GIT);
+#endif
+#ifdef LTTNG_EXTRA_VERSION_NAME
+MODULE_INFO(extra_version_name, LTTNG_EXTRA_VERSION_NAME);
+#endif
 MODULE_LICENSE("GPL and additional rights");
 MODULE_AUTHOR("Mathieu Desnoyers <mathieu.desnoyers@efficios.com>");
 MODULE_DESCRIPTION("LTTng Events");
This page took 0.032 seconds and 4 git commands to generate.