From 9cc01fc12110b1470ead344af9fafbab1c63b110 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 17 Dec 2014 00:15:27 +0100 Subject: [PATCH] build: embed git-commit-id as string inside libnm binary In the 'configure.ac' script we already detect the git commit id for the current source version. When creating a tarball, it is also included inside the generated 'configure' script. Add the commit id as a static string to nm-utils.c. That way, having a build of libnm.so or NetworkManager, you can quickly find the corresponding git commit: strings src/NetworkManager | grep NM_GIT_SHA Note that this only works after a new `autogen.sh` run. Only rebuilding is not enough. Hence, you must rebuild all to ensure that the correct commit id is embedded. https://bugzilla.gnome.org/show_bug.cgi?id=741651 (cherry picked from commit 924f7b2064eb7146bce6155c5fafb854b89d86c6) --- configure.ac | 1 + libnm-core/nm-utils.c | 6 ++++++ libnm-util/nm-utils.c | 6 ++++++ 3 files changed, 13 insertions(+) diff --git a/configure.ac b/configure.ac index 599619a8cc..3964be956a 100644 --- a/configure.ac +++ b/configure.ac @@ -60,6 +60,7 @@ AC_SUBST(NM_MAJOR_VERSION) AC_SUBST(NM_MINOR_VERSION) AC_SUBST(NM_MICRO_VERSION) AC_SUBST(NM_VERSION) +AC_DEFINE_UNQUOTED(NM_GIT_SHA,"$NM_GIT_SHA",[git commit id of the original source code version]) dnl dnl Checks for typedefs, structures, and compiler characteristics. diff --git a/libnm-core/nm-utils.c b/libnm-core/nm-utils.c index 4b284cfefd..e5a49d74b1 100644 --- a/libnm-core/nm-utils.c +++ b/libnm-core/nm-utils.c @@ -36,6 +36,7 @@ #include "nm-setting-private.h" #include "crypto.h" #include "gsystem-local-alloc.h" +#include "nm-utils-internal.h" #include "nm-setting-bond.h" #include "nm-setting-bridge.h" @@ -46,6 +47,9 @@ #include "nm-setting-wired.h" #include "nm-setting-wireless.h" +/* Embed the commit id in the build binary */ +static const char *const __nm_git_sha = STRLEN (NM_GIT_SHA) > 0 ? "NM_GIT_SHA:"NM_GIT_SHA : ""; + /** * SECTION:nm-utils * @short_description: Utility functions @@ -221,6 +225,8 @@ _nm_utils_init (void) GModule *self; gpointer func; + (void) __nm_git_sha; + if (initialized) return; initialized = TRUE; diff --git a/libnm-util/nm-utils.c b/libnm-util/nm-utils.c index b5bbfbd349..b6a9dc3004 100644 --- a/libnm-util/nm-utils.c +++ b/libnm-util/nm-utils.c @@ -37,6 +37,10 @@ #include "nm-dbus-glib-types.h" #include "nm-setting-private.h" #include "crypto.h" +#include "nm-utils-internal.h" + +/* Embed the commit id in the build binary */ +static const char *const __nm_git_sha = STRLEN (NM_GIT_SHA) > 0 ? "NM_GIT_SHA:"NM_GIT_SHA : ""; /** * SECTION:nm-utils @@ -232,6 +236,8 @@ static gboolean initialized = FALSE; gboolean nm_utils_init (GError **error) { + (void) __nm_git_sha; + if (!initialized) { initialized = TRUE;