[lttng-dev] [PATCH babeltrace] Add git version string

Mathieu Desnoyers mathieu.desnoyers at efficios.com
Thu Sep 13 11:41:14 EDT 2018


----- On Sep 12, 2018, at 3:43 PM, Jeremie Galarneau jeremie.galarneau at efficios.com wrote:

> Merged in master and stable-2.0.

stable-2.0, really ? :) That brings up good memories.

Thanks,

Mathieu

> 
> Thanks!
> Jérémie
> 
> On Tue, May 01, 2018 at 02:30:02PM -0400, Michael Jeanson wrote:
>> Signed-off-by: Michael Jeanson <mjeanson at efficios.com>
>> ---
>>  .gitignore                    |  2 +
>>  cli/babeltrace-cfg-cli-args.c |  7 +++-
>>  include/Makefile.am           | 74 ++++++++++++++++++++++++++++++++++-
>>  include/version.h             | 28 +++++++++++++
>>  4 files changed, 109 insertions(+), 2 deletions(-)
>>  create mode 100644 include/version.h
>> 
>> diff --git a/.gitignore b/.gitignore
>> index a1740cb1..edcf8edc 100644
>> --- a/.gitignore
>> +++ b/.gitignore
>> @@ -64,6 +64,8 @@ plugins/ctf/common/metadata/parser.output
>>  /cli/babeltrace-log.bin
>>  /include/config.h
>>  /include/config.h.in
>> +/include/version.i
>> +/include/version.i.tmp
>>  /config.status
>>  *.log
>>  aclocal.m4
>> diff --git a/cli/babeltrace-cfg-cli-args.c b/cli/babeltrace-cfg-cli-args.c
>> index 8f01e64b..7783f25a 100644
>> --- a/cli/babeltrace-cfg-cli-args.c
>> +++ b/cli/babeltrace-cfg-cli-args.c
>> @@ -41,6 +41,7 @@
>>  #include "babeltrace-cfg.h"
>>  #include "babeltrace-cfg-cli-args.h"
>>  #include "babeltrace-cfg-cli-args-connect.h"
>> +#include "version.h"
>>  
>>  /*
>>   * Error printf() macro which prepends "Error: " the first time it's
>> @@ -729,7 +730,11 @@ end:
>>  static
>>  void print_version(void)
>>  {
>> -	puts("Babeltrace " VERSION);
>> +	if (GIT_VERSION[0] == '\0') {
>> +		puts("Babeltrace " VERSION);
>> +	} else {
>> +		puts("Babeltrace " VERSION  " - " GIT_VERSION);
>> +	}
>>  }
>>  
>>  /*
>> diff --git a/include/Makefile.am b/include/Makefile.am
>> index c026e74c..669e003b 100644
>> --- a/include/Makefile.am
>> +++ b/include/Makefile.am
>> @@ -1,3 +1,73 @@
>> +##
>> +## This target generates an include file that contains the git version
>> +## string of the current branch, it must be continuously updated when
>> +## we build in the git repo and shipped in dist tarballs to reflect the
>> +## status of the tree when it was generated. If the tree is clean and
>> +## the current commit is tag a starting with "v", consider this a
>> +## release version and set an empty git version.
>> +##
>> +## Here is what the inline script does:
>> +##
>> +## First, delete any stale "version.i.tmp" file.
>> +##
>> +## If "bootstrap" and ".git" exists in the top source directory and the git
>> +## executable is available, get the current git version string in the form:
>> +##
>> +##  "latest_tag"(-"number_of_commits_on_top")(-g"latest_commit_hash")(-dirty)
>> +##
>> +## And store it in "version.i.tmp", if the current commit is tagged, the tag
>> +## starts with "v" and the tree is clean, consider this a release version and
>> +## overwrite the git version with an empty string in "version.i.tmp".
>> +##
>> +## If we don't have a "version.i.tmp" nor a "version.i", generate an empty
>> +## string as a failover.
>> +##
>> +## If we don't have a "version.i" or we have both files and they are different,
>> +## copy "version.i.tmp" over "version.i". This way the dependent targets are
>> +## only rebuilt when the version string changes.
>> +##
>> +
>> +version_verbose = $(version_verbose_ at AM_V@)
>> +version_verbose_ = $(version_verbose_ at AM_DEFAULT_V@)
>> +version_verbose_0 = @echo "  GEN       " $@;
>> +
>> +version.i:
>> +	$(version_verbose)rm -f version.i.tmp; \
>> +	if (test -r "$(top_srcdir)/bootstrap" && test -r "$(top_srcdir)/.git") && \
>> +			test -x "`which git 2>&1;true`"; then \
>> +		GIT_VERSION_STR="`cd "$(top_srcdir)" && git describe --tags --dirty`"; \
>> +		GIT_CURRENT_TAG="`cd "$(top_srcdir)" && git describe --tags --exact-match
>> --match="v[0-9]*" HEAD 2> /dev/null`"; \
>> +		echo "#define GIT_VERSION \"$$GIT_VERSION_STR\"" > version.i.tmp; \
>> +		if ! $(GREP) -- "-dirty" version.i.tmp > /dev/null && \
>> +				test "x$$GIT_CURRENT_TAG" != "x"; then \
>> +			echo "#define GIT_VERSION \"\"" > version.i.tmp; \
>> +		fi; \
>> +	fi; \
>> +	if test ! -f version.i.tmp; then \
>> +		if test ! -f version.i; then \
>> +			echo '#define GIT_VERSION ""' > version.i; \
>> +		fi; \
>> +	elif test ! -f version.i || \
>> +			test x"`cat version.i.tmp`" != x"`cat version.i`"; then \
>> +		mv version.i.tmp version.i; \
>> +	fi; \
>> +	rm -f version.i.tmp; \
>> +	true
>> +
>> +##
>> +## version.i is defined as a .PHONY target even if it's a real file,
>> +## we want the target to be re-run on every make.
>> +##
>> +.PHONY: version.i
>> +
>> +CLEANFILES = version.i.tmp
>> +
>> +##
>> +## Only clean "version.i" on dist-clean, we need to keep it on regular
>> +## clean when it's part of a dist tarball.
>> +##
>> +DISTCLEANFILES = version.i
>> +
>>  # Core API
>>  babeltraceincludedir = "$(includedir)/babeltrace"
>>  babeltraceinclude_HEADERS = \
>> @@ -151,4 +221,6 @@ noinst_HEADERS = \
>>  	babeltrace/plugin/plugin-so-internal.h \
>>  	babeltrace/prio-heap-internal.h \
>>  	babeltrace/ref-internal.h \
>> -	babeltrace/values-internal.h
>> +	babeltrace/values-internal.h \
>> +	version.h \
>> +	version.i
>> diff --git a/include/version.h b/include/version.h
>> new file mode 100644
>> index 00000000..4f802517
>> --- /dev/null
>> +++ b/include/version.h
>> @@ -0,0 +1,28 @@
>> +#ifndef VERSION_H
>> +#define VERSION_H
>> +
>> +/*
>> + * Copyright (C) 2018 Michael Jeanson <mjeanson at efficios.com>
>> + *
>> + * Permission is hereby granted, free of charge, to any person obtaining a copy
>> + * of this software and associated documentation files (the "Software"), to
>> deal
>> + * in the Software without restriction, including without limitation the rights
>> + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
>> + * copies of the Software, and to permit persons to whom the Software is
>> + * furnished to do so, subject to the following conditions:
>> + *
>> + * The above copyright notice and this permission notice shall be included in
>> + * all copies or substantial portions of the Software.
>> + *
>> + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
>> + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
>> + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
>> + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
>> + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
>> FROM,
>> + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
>> THE
>> + * SOFTWARE.
>> + */
>> +
>> +#include "version.i"
>> +
>> +#endif /* VERSION_H */
>> --
>> 2.17.0
>> 
> _______________________________________________
> lttng-dev mailing list
> lttng-dev at lists.lttng.org
> https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev

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


More information about the lttng-dev mailing list