diff mbox series

trace-cmd: Make the version defines part of tc-version.h

Message ID 20190612085136.248a4a0e@gandalf.local.home (mailing list archive)
State Accepted
Commit d74f3845ddebf0b93f86c832385431a5e7dfa14c
Headers show
Series trace-cmd: Make the version defines part of tc-version.h | expand

Commit Message

Steven Rostedt June 12, 2019, 12:51 p.m. UTC
From: "Steven Rostedt (VMware)" <rostedt@goodmis.org>

Move the version string creations as part of the tc-version.h file, and have
trace-record.c include and use that. The VERSION_STRING is already defined
and obsoletes TRACECMD_VERSION. For consistency, use VERSION_GIT to define
the git sha1. Also, add logic to detect if the source file is a git repo,
and use "not-a-git-repo" as the sha1 if it is not found. Add a "+" to the
end of the git sha1 if the repo has modifications in it.

Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
---
 Makefile                | 4 ----
 scripts/utils.mk        | 9 +++++++++
 tracecmd/trace-record.c | 3 ++-
 3 files changed, 11 insertions(+), 5 deletions(-)

Comments

Slavomir Kaslev June 12, 2019, 2:28 p.m. UTC | #1
On Wed, 2019-06-12 at 08:51 -0400, Steven Rostedt wrote:
> From: "Steven Rostedt (VMware)" <rostedt@goodmis.org>
> 
> Move the version string creations as part of the tc-version.h file,
> and have
> trace-record.c include and use that. The VERSION_STRING is already
> defined
> and obsoletes TRACECMD_VERSION. For consistency, use VERSION_GIT to
> define
> the git sha1. Also, add logic to detect if the source file is a git
> repo,
> and use "not-a-git-repo" as the sha1 if it is not found. Add a "+" to
> the
> end of the git sha1 if the repo has modifications in it.
> 
> Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>

Thanks, Steven. I completely missed tc-version.h header's existence in
the initial patch.

Reviewed-by: Slavomir Kaslev <kaslevs@vmware.com>

Cheers,

--Slavi
diff mbox series

Patch

diff --git a/Makefile b/Makefile
index 2062d976..6df1f07b 100644
--- a/Makefile
+++ b/Makefile
@@ -238,10 +238,6 @@  endif
 override CFLAGS += $(INCLUDES) $(PLUGIN_DIR_SQ) $(VAR_DIR)
 override CFLAGS += $(udis86-flags) $(blk-flags)
 
-# Append version define
-override CFLAGS += -DTRACECMD_VERSION=\"$(TRACECMD_VERSION)\"
-override CFLAGS += -DTRACECMD_VERSION_GIT=\"$(shell git log -1 --pretty=format:"%H")\"
-
 CMD_TARGETS = trace-cmd $(BUILD_PYTHON)
 
 ###
diff --git a/scripts/utils.mk b/scripts/utils.mk
index f5feeca0..260023a1 100644
--- a/scripts/utils.mk
+++ b/scripts/utils.mk
@@ -79,6 +79,15 @@  define make_version.h
 	echo '#define EXTRAVERSION ' $(EXTRAVERSION);					\
 	echo '#define VERSION_STRING "'$(VERSION).$(PATCHLEVEL).$(EXTRAVERSION)'"';	\
 	echo '#define FILE_VERSION '$(FILE_VERSION);					\
+	if [ -d $(src)/.git ]; then							\
+	  d=`git diff`;									\
+	  x="";										\
+	  if [ ! -z "$$d" ]; then x="+"; fi;						\
+	  echo '#define VERSION_GIT "'$(shell 						\
+		git log -1 --pretty=format:"%H" 2>/dev/null)$$x'"';			\
+	else										\
+	  echo '#define VERSION_GIT "not-a-git-repo"';					\
+	fi										\
 	) > $1
 endef
 
diff --git a/tracecmd/trace-record.c b/tracecmd/trace-record.c
index 8aa83455..ee35ada1 100644
--- a/tracecmd/trace-record.c
+++ b/tracecmd/trace-record.c
@@ -34,6 +34,7 @@ 
 #include <limits.h>
 #include <libgen.h>
 
+#include "version.h"
 #include "trace-local.h"
 #include "trace-msg.h"
 
@@ -3149,7 +3150,7 @@  static void add_version(struct tracecmd_output *handle)
 	char *str;
 	int len;
 
-	len = asprintf(&str, "%s %s", TRACECMD_VERSION, TRACECMD_VERSION_GIT);
+	len = asprintf(&str, "%s %s", VERSION_STRING, VERSION_GIT);
 	if (len < 0)
 		return;