On Tue, 2010-04-13 at 11:25 +1000, Peter Hutterer 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 <[email protected]>
> ---
> Do we want something like this? Suggestions for less dodgy implementations
> are welcome, but the current one passes distcheck.
> 
>  GIT-GENERATE-VERSION         |   24 ++++++++++++++++++++++++
>  Makefile.am                  |    2 +-
>  hw/xfree86/common/xf86Init.c |    5 +++++
>  include/Makefile.am          |    7 +++++++
>  4 files changed, 37 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..6872a76
> --- /dev/null
> +++ b/GIT-GENERATE-VERSION
> @@ -0,0 +1,24 @@
> +#!/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"
> +
> +if ! which git > /dev/null; then
> +    VER="Git not available."
> +else
> +    VER=`git describe HEAD 2>/dev/null`
> +
> +    if test $? -ne 0; then
> +        VER="Unknown version or not build from git."
> +    fi
> +fi
> +
> +if test -e "$GITFILE"; then
> +    FILE_VER=$(sed -e "s/^#define XORG_GIT_VERSION //" < $GITFILE)
> +    if test "$FILE_VER" == "$VER"; then
> +        exit 0
> +    fi
> +fi
> +
> +echo "#define XORG_GIT_VERSION \"$VER\"" > $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..e052b8b 100644
> --- a/include/Makefile.am
> +++ b/include/Makefile.am
> @@ -62,6 +62,11 @@ 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
> +
>  AM_CFLAGS = $(DIX_CFLAGS)
>  
>  EXTRA_DIST =         \
> @@ -69,3 +74,5 @@ EXTRA_DIST =        \
>       eventconvert.h eventstr.h \
>       protocol-versions.h \
>       xsha1.h
> +
> +DISTCLEANFILES = xorg-git-version.h


When I just run the script from the root dir, I get this:

        >~/xorg/src/xserver$ ./GIT-GENERATE-VERSION
        test: 22: "xorg-server-1.8.0-40-ge35abc1": unexpected operator

The xorg-git-version.h gets created correctly. The script just need to
be a bit more robust, I guess.

The file xorg-git-version.h should be added to include/.gitignore.

Given that the purpose of this scheme is to "log" the most recent
commit, the xorg-git-version.h should be
updated after the repo has been updated. This isn't the case now. I can
do a git pull with new commits,
rebuild, and still get the same -ge35abc1. Perhaps it should be a PHONY
target like ChangeLog. This would make
the information in log unreliable.

A further improvement would be to run git show on the commit id (e.g.
e35abc1) and write it to the log.





Attachment: signature.asc
Description: This is a digitally signed message part

_______________________________________________
[email protected]: X.Org development
Archives: http://lists.x.org/archives/xorg-devel
Info: http://lists.x.org/mailman/listinfo/xorg-devel

Reply via email to