On 6 June 2016 at 18:35, Paolo Bonzini <pbonz...@redhat.com> wrote:
> From: Fam Zheng <f...@redhat.com>
>
> Currently, if not specified in "./configure", QEMU_PKGVERSION will be
> empty. Write a rule in Makefile to generate a value from "git describe"
> combined with a possible git tree cleanness suffix, and write into a new
> header.
>
>     $ cat qemu-version.h
>     #define QEMU_PKGVERSION "-v2.6.0-557-gd6550e9-dirty"
>
> Include the header in .c files where the macro is referenced. It's not
> necessary to include it in all files, otherwise each time the content of
> the file changes, all sources have to be recompiled.
>
> +qemu-version.h: FORCE
> +       $(call quiet-command, \
> +               (cd $(SRC_PATH); \
> +               printf '#define QEMU_PKGVERSION '; \
> +               if test -n "$(PKGVERSION)"; then \
> +                       printf '"$(PKGVERSION)"\n'; \
> +               else \
> +                       if test -d .git; then \
> +                               printf '" ('; \
> +                               git describe --match 'v*' 2>/dev/null | tr -d 
> '\n'; \
> +                               if ! git diff-index --quiet HEAD &>/dev/null; 
> then \
> +                                       printf -- '-dirty'; \
> +                               fi; \
> +                               printf ')"\n'; \
> +                       else \
> +                               printf '""\n'; \
> +                       fi; \
> +               fi) > $@.tmp)
> +       $(call quiet-command, cmp --quiet $@ $@.tmp || mv $@.tmp $@)

I've just discovered that this rune incorrectly always
adds "-dirty" to the version string if /bin/sh is dash.

This is because "&>/dev/null" is not POSIX shell syntax, it is a
bash extension, and if you run this with dash then the command
always fails.

I'm not sure why we are redirecting anything here, since we
are using git diff-index's --quiet option which suppresses
all output. The simplest fix would seem to be to just delete
the redirect option entirely.

The fix for this should probably be cc:stable since it's
annoying that you can't out of the box build QEMU and have
the version number say '2.7.0' rather than '2.7.0-dirty'...

thanks
-- PMM

Reply via email to