[lttng-dev] [PATCH lttng-tools 2/2] Fix: git version build system integration

Mathieu Desnoyers mathieu.desnoyers at efficios.com
Tue Jul 29 18:33:04 EDT 2014


Patch 1/2 is still good, but this patch will have a v2 coming
soon.

----- Original Message -----
> From: "Mathieu Desnoyers" <mathieu.desnoyers at efficios.com>
> To: dgoulet at efficios.com
> Cc: lttng-dev at lists.lttng.org, "Mathieu Desnoyers" <mathieu.desnoyers at efficios.com>
> Sent: Tuesday, July 29, 2014 6:10:28 PM
> Subject: [PATCH lttng-tools 2/2] Fix: git version build system integration
> 
> Fix:
> - Don't overwrite version.h if the previous content matches.
> - While we are there, if we notice the previous content matches,
>   print a (cached) message to show that we do not overwrite the
>   content.
> - Introduce LTTNG_TOOLS_BUILD_GIT_SOURCE automake conditional rather
>   than compile-time define to disable the feature. It ensures we
>   do not invoke "git describe" when configure --disable-git-version
>   has been requested.
> - Use git describe rather than git describe --long --all. Based
>   on the last tag, and adds the first numbers of git revision.
>   Last tag is useful both to the developer and in a bug report,
>   whereas the branch name returned by --long --all is meaningless
>   in a bug report.
> - We want to ship version.h.tmpl in the tarball (make dist), not
>   version.h which is generated. Someone could very well do a
>   git init on the extracted tarball and want to have git tracking
>   support.
> - Fix the git prefix " - " that is incorrectly printed in some
>   situations, e.g. when GIT_SOURCE was active, but we are in
>   a non-git tree (or git is not available).
> - Fix incorrect handling of out of tree build. Invoke git describe from
>   top_srcdir.
> 
> Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers at efficios.com>
> ---
>  configure.ac                     |  8 +++---
>  include/Makefile.am              | 60
>  +++++++++++++++++++++-------------------
>  include/version.h.tmpl           | 14 +++-------
>  src/bin/lttng/commands/version.c |  3 +-
>  src/bin/lttng/lttng.c            |  8 ++++--
>  5 files changed, 47 insertions(+), 46 deletions(-)
> 
> diff --git a/configure.ac b/configure.ac
> index bd49df7..a8e04f5 100644
> --- a/configure.ac
> +++ b/configure.ac
> @@ -262,11 +262,11 @@ AC_CHECK_LIB([c], [open_memstream],
>  AC_ARG_ENABLE([git-version],
>                [AC_HELP_STRING([--disable-git-version],
>                                [Do not use the git version for the build])],
> -              [disable_git_version=yes], [disable_git_version=no]
> +              [have_git_version=$enableval], [have_git_version=yes]
>  )
> -if test "x${disable_git_version:-no}" = xno; then
> -    AC_DEFINE_UNQUOTED([GIT_SOURCE], 1, [Disable git version.])
> -fi
> +
> +AM_CONDITIONAL([LTTNG_TOOLS_BUILD_GIT_SOURCE],
> +	[test "x${have_git_version}" = "xyes"])
>  
>  # For Python
>  # SWIG version needed or newer:
> diff --git a/include/Makefile.am b/include/Makefile.am
> index 767b05b..4b59e72 100644
> --- a/include/Makefile.am
> +++ b/include/Makefile.am
> @@ -1,3 +1,9 @@
> +if LTTNG_TOOLS_BUILD_GIT_SOURCE
> +GIT_DESCRIBE_CMD = (cd $(top_srcdir); git describe)
> +else
> +GIT_DESCRIBE_CMD = /bin/true
> +endif
> +
>  ##
>  ## The version.h file must be verified and generated or updated if the
>  ## git commit id (called git version here) changed since the last build
> @@ -6,49 +12,44 @@
>  version.h:
>  	##
>  	## We first create variables for the current git version and
> -	## the locations of the version.h and version.h.tmpl files
> +	## the locations of the version.h and version.h.tmpl files.
>  	##
> -	@echo -n "Generating version.h ... "
> +	@echo -n "Generating version.h... "
>  	@(version_h_tmpl="$(top_srcdir)/include/version.h.tmpl"; \
>  	if [ -f "$${version_h_tmpl}" ]; then \
>  		version_h="$(top_builddir)/include/version.h"; \
>  		##
> -		## We check the git version format we will use depending on
> -		## whether or not we are in the master branch or on a tag
> +		## Check whether we are in a git repo.
>  		##
> -		git_branch="$$(git describe --all 2>/dev/null)"; \
> -		if [ -z "$${git_branch}" ]; then \
> -			git_version=""; \
> +		git_describe="$$($(GIT_DESCRIBE_CMD) 2>/dev/null)"; \
> +		if [ $$? -eq 0 ]; then \
> +			git_version="$${git_describe}"; \
>  		else \
> -			git_describe="$$(git describe)"; \
> -			if [ "$${git_branch}" == "$${git_describe}" ]; then \
> -				git_version="$${git_describe}"; \
> -			else \
> -				git_version="$$(git describe --long --all)"; \
> -			fi; \
> +			git_version=""; \
>  		fi; \
>  		##
>  		## If the version.h file doesn't exist or is not up to date,
> -		## We replace it by the version.h.tmpl file
> +		## We replace it by the version.h.tmpl file.
>  		##
>  		if [ ! -e "$${version_h}" ] || \
>  			[ "$${version_h_tmpl}" -nt "$${version_h}" ]; then \
>  			cp "$${version_h_tmpl}" "$${version_h}"; \
>  		fi; \
> -		if [ -n "$${git_version}" ]; then \
> -			##
> -			## We remove the leading "v" for the version number
> -			##
> -			git_version="$$(echo "$${git_version}" | sed -r "s/^v([0-9])/\1/")"; \
> -			##
> -			## If we have a git version, we verify that it isn't the same
> -			## as the one currently in the file (if there is one), as we
> -			## don't want to update the file if it is already up to date
> -			##
> -			if [ $$(grep -cE "^#define GIT_VERSION_SED \"?$${git_version}\"?$$"
> "$${version_h}") -eq 0 ]; then \
> -				sed -i "s'^#define GIT_VERSION_SED.*$$'#define GIT_VERSION
> \"$${git_version}\"'" "$${version_h}"; \
> -			fi; \
> +		echo -n "git version: \"$${git_version}\""; \
> +		##
> +		## We verify that git_version isn't the same as the one
> +		## currently in the file (if there is one), as we don't
> +		## want to update the file if it is already up to date.
> +		##
> +		version_match='^#define GIT_VERSION.*'; \
> +		old_version=$$(grep "$${version_match}" "$${version_h}"); \
> +		new_version="#define GIT_VERSION	\"$${git_version}\""; \
> +		if [ x"$${old_version}" != x"$${new_version}" ]; then \
> +			sed -i "s'$${version_match}'$${new_version}'" "$${version_h}"; \
> +		else \
> +			echo -n " (cached)"; \
>  		fi; \
> +		echo -n "... "; \
>  	fi)
>  	@echo "ok"
>  
> @@ -58,6 +59,9 @@ version.h:
>  ##
>  .PHONY: version.h
>  
> +nodist_noinst_HEADERS = \
> +	version.h
> +
>  lttnginclude_HEADERS = \
>  	lttng/health.h \
>  	lttng/lttng.h \
> @@ -71,7 +75,7 @@ lttnginclude_HEADERS = \
>  	lttng/snapshot.h \
>  	lttng/save.h \
>  	lttng/load.h \
> -	version.h
> +	version.h.tmpl
>  
>  noinst_HEADERS = \
>  	lttng/snapshot-internal.h \
> diff --git a/include/version.h.tmpl b/include/version.h.tmpl
> index e2ce531..d3f3302 100644
> --- a/include/version.h.tmpl
> +++ b/include/version.h.tmpl
> @@ -1,3 +1,6 @@
> +#ifndef VERSION_H
> +#define VERSION_H
> +
>  /*
>   * Copyright (C) 2013-2014 - Raphaël Beamonte <raphael.beamonte at gmail.com>
>   *
> @@ -17,15 +20,6 @@
>  
>  #include <config.h>
>  
> -#ifndef VERSION_H
> -#define VERSION_H
> -
> -#ifdef GIT_SOURCE
> -#define GIT_VERSION_PREFIX " - "
> -#define GIT_VERSION_SED ""
> -#else
> -#define GIT_VERSION_PREFIX ""
> -#define GIT_VERSION ""
> -#endif
> +#define GIT_VERSION	""
>  
>  #endif /* VERSION_H */
> diff --git a/src/bin/lttng/commands/version.c
> b/src/bin/lttng/commands/version.c
> index 4e46d72..f4d8963 100644
> --- a/src/bin/lttng/commands/version.c
> +++ b/src/bin/lttng/commands/version.c
> @@ -164,7 +164,8 @@ int cmd_version(int argc, const char **argv)
>  	if (lttng_opt_mi) {
>  		ret = print_mi();
>  	} else {
> -		MSG("lttng version " VERSION " - " VERSION_NAME GIT_VERSION_PREFIX
> GIT_VERSION);
> +		MSG("lttng version " VERSION " - " VERSION_NAME "%s",
> +			GIT_VERSION[0] == '\0' ? "" : " - " GIT_VERSION);
>  		MSG("\n" VERSION_DESCRIPTION "\n");
>  		MSG("Web site: http://lttng.org");
>  		MSG("\n%s", lttng_license);
> diff --git a/src/bin/lttng/lttng.c b/src/bin/lttng/lttng.c
> index 41232be..c0c914a 100644
> --- a/src/bin/lttng/lttng.c
> +++ b/src/bin/lttng/lttng.c
> @@ -90,7 +90,8 @@ static struct cmd_struct commands[] =  {
>  
>  static void usage(FILE *ofp)
>  {
> -	fprintf(ofp, "LTTng Trace Control " VERSION " - " VERSION_NAME" - "
> GIT_VERSION "\n\n");
> +	fprintf(ofp, "LTTng Trace Control " VERSION " - " VERSION_NAME "%s\n\n"
> +		GIT_VERSION[0] == '\0' ? "" : " - " GIT_VERSION);
>  	fprintf(ofp, "usage: lttng [OPTIONS] <COMMAND> [<ARGS>]\n");
>  	fprintf(ofp, "\n");
>  	fprintf(ofp, "Options:\n");
> @@ -134,8 +135,9 @@ static void usage(FILE *ofp)
>  
>  static void version(FILE *ofp)
>  {
> -	fprintf(ofp, "%s (LTTng Trace Control) " VERSION" - " VERSION_NAME" - "
> GIT_VERSION "\n",
> -			progname);
> +	fprintf(ofp, "%s (LTTng Trace Control) " VERSION" - " VERSION_NAME "%s\n",
> +			progname,
> +			GIT_VERSION[0] == '\0' ? "" : " - " GIT_VERSION);
>  }
>  
>  /*
> --
> 2.0.1
> 
> 

-- 
Mathieu Desnoyers
EfficiOS Inc.
http://www.efficios.com



More information about the lttng-dev mailing list