[PATCH v2] Print git describe output into the log file.

Dan Nicholson dbn.lists at gmail.com
Fri Apr 16 06:31:00 PDT 2010


On Thu, Apr 15, 2010 at 11:04 PM, Peter Hutterer
<peter.hutterer at who-t.net> wrote:
> Run git describe on build and push the output into xorg-git-version.h. Then
> print that out in the logfile.
>
> Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
> ---
> Changes to first version:
> - target is PHONY to always regenerate
> - script reshuffled, no == anymore
> - don't print anything if no git version could be found.
>
> I think those were all suggested changes for the first round, right?
> Given how simple the script is, I also wonder if we should just add the commands
> to the makefile target directly instead of adding a script.

It might be nicer, but could get messy when you consider all the corner cases.

create_xorg_git_version = \
    vers=`git --git-dir='$(top_srcdir)' describe HEAD 2>/dev/null`; \
    if test "x$$vers" != x; then \
      echo "\#define XORG_GIT_VERSION \"$$vers\"" > $@.tmp; \
    else \
      echo "\#undef XORG_GIT_VERSION" > $@.tmp; \
    fi; \
    if -f $@ && cmp $@ $@.tmp; then \
      rm -f $@.tmp; \
    else \
      mv -f $@.tmp $@; \
    fi

xorg-git-version.h:
        $(AM_V_GEN)$(create_xorg_git_version)

>
> Cheers,
>  Peter
>
>  GIT-GENERATE-VERSION         |   26 ++++++++++++++++++++++++++
>  Makefile.am                  |    2 +-
>  hw/xfree86/common/xf86Init.c |    5 +++++
>  include/Makefile.am          |    9 +++++++++
>  4 files changed, 41 insertions(+), 1 deletions(-)
>  create mode 100755 GIT-GENERATE-VERSION
>
> diff --git a/GIT-GENERATE-VERSION b/GIT-GENERATE-VERSION
> new file mode 100755
> index 0000000..84896bd
> --- /dev/null
> +++ b/GIT-GENERATE-VERSION

If we do keep a stanadalone script, can we not make it an all caps
name and add .sh for clarity? xorg-git-version.sh would mirror the
filename.

> @@ -0,0 +1,26 @@
> +#!/bin/sh
> +# Get the git version if possible and store it in $GITFILE if it differs to
> +# the one contained already.
> +
> +GITFILE="xorg-git-version.h"

It might be nicer to make this a parameter so that in make you can just pass $@.

> +VER=""
> +OUTSTR=""
> +
> +if which git > /dev/null; then

Drop the "which git" since you can just unconditionally run "git
describe" and redirect errors to output.

> +    VER=`git describe HEAD 2>/dev/null`

Since we need to support builddir != srcdir builds, we need to
instruct git with --git-dir. I think the easiest way is to pass
$(top_srcdir) as a parameter to the script. Then you could do:

VER=`git ${1+--git-dir="$1"} describe HEAD 2>/dev/null`

Or, you can set the GIT_DIR environment variable on the command line in make:

xorg-git-version.h:
    GIT_DIR='$(top_srcdir)' $(SHELL) GIT-GENERATE-VERSION $@

> +fi
> +
> +if test -z "$VER"; then
> +    OUTSTR="#undef XORG_GIT_VERSION"
> +else
> +    OUTSTR="#define XORG_GIT_VERSION \"$VER\""
> +fi
> +
> +if test -e "$GITFILE"; then
> +    FILE_VER=`cat $GITFILE`
> +    if test "$FILE_VER" = "$VER"; then
> +        exit 0
> +    fi
> +fi

This part is a really great idea since it will prevent gratuitous
rebuilds, but you need to check $FILE_VER against $OUTSTR.

> +
> +echo "$OUTSTR" > $GITFILE
> diff --git a/Makefile.am b/Makefile.am
> index 8b7a2c8..cce5f23 100644
> --- a/Makefile.am
> +++ b/Makefile.am
> @@ -49,7 +49,7 @@ pkgconfigdir = $(libdir)/pkgconfig
>  pkgconfig_DATA = xorg-server.pc
>  endif
>
> -EXTRA_DIST = xorg-server.pc.in xorg-server.m4 autogen.sh
> +EXTRA_DIST = xorg-server.pc.in xorg-server.m4 autogen.sh GIT-GENERATE-VERSION
>
>  DISTCHECK_CONFIGURE_FLAGS=\
>        --with-xkb-path=$(XKB_BASE_DIRECTORY) \
> diff --git a/hw/xfree86/common/xf86Init.c b/hw/xfree86/common/xf86Init.c
> index 71ac9a9..d37a292 100644
> --- a/hw/xfree86/common/xf86Init.c
> +++ b/hw/xfree86/common/xf86Init.c
> @@ -34,6 +34,8 @@
>  #include <xorg-config.h>
>  #endif
>
> +#include <xorg-git-version.h>
> +
>  #include <stdlib.h>
>  #include <errno.h>
>
> @@ -242,6 +244,9 @@ xf86PrintBanner(void)
>   xf86ErrorFVerb(0, "\tBefore reporting problems, check "
>                  ""__VENDORDWEBSUPPORT__"\n"
>                  "\tto make sure that you have the latest version.\n");
> +#ifdef XORG_GIT_VERSION
> +  xf86ErrorFVerb(0, "git version: " XORG_GIT_VERSION "\n");
> +#endif
>  }
>
>  static void
> diff --git a/include/Makefile.am b/include/Makefile.am
> index eddc86c..d0f4a53 100644
> --- a/include/Makefile.am
> +++ b/include/Makefile.am
> @@ -62,6 +62,13 @@ sdk_HEADERS =                \
>  nodist_sdk_HEADERS = xorg-server.h
>  endif
>
> +BUILT_SOURCES = xorg-git-version.h
> +
> +xorg-git-version.h:
> +       sh $(top_srcdir)/GIT-GENERATE-VERSION

Use $(SHELL) since it's already set.

> +
> +.PHONY: xorg-git-version.h

Building off what Kristian said, it will be nicer to depend on the git
files so that we don't get the file regenerated unnecessarily. But
since they won't be there for tarballs, we probably need an
AM_CONDITIONAL.

configure.ac:
AM_CONDITIONAL([USING_GIT], [test -f "$srcdir/.git/HEAD"])

Makefile.am:
if USING_GIT
git_HEAD = $(top_srcdir)/.git/HEAD
endif

xorg-git-version.h: $(git_HEAD)
    do stuff...

To really use Kristian's suggestion, I think you'd need to make it:

git_HEAD = $(top_srcdir)/.git/`git --git-dir='$(top_srcdir)' symbolic-ref HEAD`

Mixing backticks into make variables can get ugly, but it probably
works. On the other hand, the simple .git/HEAD combined with the
version comparison in the script would reach the same effect.

--
Dan


More information about the xorg-devel mailing list