From 24a3d6db4551bbd655dbca6a94cf21899f0b5444 Mon Sep 17 00:00:00 2001
From: Guillaume Roguez <guillaume.roguez@savoirfairelinux.com>
Date: Tue, 1 Sep 2015 14:21:58 -0400
Subject: [PATCH] api: make DRing::version() returning a git revision

This change provides a better way to find which sources are used
at runtime.

Issue: #79930
Change-Id: Icd505230269c4ba11e7d64e02471febcf68777a0
---
 globals.mak       |  5 +++++
 src/Makefile.am   |  6 +++++-
 src/buildinfo.cpp | 46 ++++++++++++++++++++++++++++++++++++++++++++++
 src/ring_api.cpp  |  6 ------
 4 files changed, 56 insertions(+), 7 deletions(-)
 create mode 100644 src/buildinfo.cpp

diff --git a/globals.mak b/globals.mak
index 2f1b5bf855..7d95ebce52 100644
--- a/globals.mak
+++ b/globals.mak
@@ -18,6 +18,9 @@ if BUILD_GSM
 GSMCODEC=-DHAVE_GSM_CODEC
 endif
 
+RING_DIRTY_REPO ?= $(shell git diff-index --quiet HEAD || echo dirty)
+RING_REVISION ?= $(shell git log -1 --format="%h" --abbrev=10)
+
 # Preprocessor flags
 AM_CPPFLAGS = \
 	-I$(src)/src \
@@ -29,6 +32,8 @@ AM_CPPFLAGS = \
 	-DPREFIX=\"$(prefix)\" \
 	-DPROGSHAREDIR=\"${datadir}/ring\" \
 	-DENABLE_TRACE \
+	-DRING_REVISION=\"${RING_REVISION}\" \
+	-DRING_DIRTY_REPO=\"${RING_DIRTY_REPO}\" \
 	$(SPEEXCODEC) \
 	$(GSMCODEC) \
 	$(OPUSCODEC)
diff --git a/src/Makefile.am b/src/Makefile.am
index d7cd0e82f8..411aed9c7e 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -105,7 +105,9 @@ if USE_DHT
 libring_la_CFLAGS += $(OPENDHT_CFLAGS)
 endif
 
-libring_la_SOURCES = conference.cpp \
+libring_la_SOURCES = \
+		buildinfo.cpp \
+		conference.cpp \
 		account_factory.cpp \
 		call_factory.cpp \
 		preferences.cpp \
@@ -168,3 +170,5 @@ if RING_VIDEO
 nobase_include_HEADERS+= \
 		dring/videomanager_interface.h
 endif
+
+.PHONY: buildinfo.cpp
diff --git a/src/buildinfo.cpp b/src/buildinfo.cpp
new file mode 100644
index 0000000000..8ca73e22f4
--- /dev/null
+++ b/src/buildinfo.cpp
@@ -0,0 +1,46 @@
+/*
+ *  Copyright (C) 2015 Savoir-faire Linux Inc.
+ *  Author: Guillaume Roguez <Guillaume.Roguez@savoirfairelinux.com>
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  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.
+ *
+ *  Additional permission under GNU GPL version 3 section 7:
+ *
+ *  If you modify this program, or any covered work, by linking or
+ *  combining it with the OpenSSL project's OpenSSL library (or a
+ *  modified version of that library), containing parts covered by the
+ *  terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc.
+ *  grants you additional permission to convey the resulting work.
+ *  Corresponding Source for a non-source form of such a combination
+ *  shall include the source code for the parts of OpenSSL used as well
+ *  as that of the covered work.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "dring.h"
+#include <string>
+
+namespace DRing {
+
+const char*
+version() noexcept
+{
+    return RING_DIRTY_REPO[0] ? PACKAGE_VERSION "-" RING_REVISION "-" RING_DIRTY_REPO : PACKAGE_VERSION "-" RING_REVISION;
+}
+
+} // namespace DRing
diff --git a/src/ring_api.cpp b/src/ring_api.cpp
index 37efc095d9..e06be3d120 100644
--- a/src/ring_api.cpp
+++ b/src/ring_api.cpp
@@ -50,12 +50,6 @@
 
 namespace DRing {
 
-const char*
-version() noexcept
-{
-    return PACKAGE_VERSION;
-}
-
 bool
 init(enum InitFlag flags) noexcept
 {
-- 
GitLab