trace-cmd: Make the version defines part of tc-version.h
PATCH 1/1 trace-cmd: Make the version defines part of tc-version.h
From: "Steven Rostedt (VMware)" <[email protected]>
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.
--- Makefile | 4 ---- scripts/utils.mk | 9 +++++++++ tracecmd/trace-record.c | 3 ++- 3 files changed, 11 insertions(+), 5 deletions(-)
Makefile +0 -4
@@ -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) ###
scripts/utils.mk +9 -0
@@ -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
tracecmd/trace-record.c +2 -1
@@ -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 ;
Signature · 1 line
2.20.1
Quoted 14 lines · Steven Rostedt
From: "Steven Rostedt (VMware)" <[email protected]>
Move the version string creations as part of the
tc-version.hfile, and havetrace-record.cinclude and use that. TheVERSION_STRINGis already defined
and obsoletesTRACECMD_VERSION. For consistency, useVERSION_GITto 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.
Quoted 1 line
Signed-off-by Steven Rostedt (VMware) <[email protected]>
Thanks, Steven. I completely missed tc-version.h header's existence in the initial patch.
Cheers,
--Slavi