Let PKGVERSION include the "git describe" output
v2 cover Let PKGVERSION include the "git describe" output
v2: Address Eric's comments:
"echo -n" -> "printf".
"-unclean" -> "-dirty".Makefile happened to be in my working set because of the docker test work, so I went ahead to try this nice feature last evening before going to bed. My apologies if we have duplicated work.
Please review, especially please comment on the redundant version string:
$ qemu-img --version qemu-img version 2.6.50-v2.6.0-603-g684a494, Copyright (c) 2004-2008 Fabrice Bellard
Fam Zheng (2):
Makefile: Add a "FORCE" target
Makefile: Derive "PKGVERSION" from "git describe" by default
Makefile | 24 ++++++++++++++++++++++-- linux-user/main.c | 1 + qemu-img.c | 1 + qmp.c | 1 + scripts/create_config | 4 ---- vl.c | 1 + 6 files changed, 26 insertions(+), 6 deletions(-)
Signature · 1 line
2.8.2
PATCH v2 1/2 Makefile: Add a "FORCE" target
--- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Makefile +1 -1
@@ -81,7 +81,7 @@ Makefile: ; configure: ; .PHONY: all clean cscope distclean dvi html info install install-doc \ - pdf recurse-all speed test dist msi + pdf recurse-all speed test dist msi FORCE $(call set-vpath, $(SRC_PATH))
Signature · 1 line
2.8.2
PATCH v2 2/2 Makefile: Derive "PKGVERSION" from "git describe" by default
In reply to Fam ZhengCurrently, 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.
--- Makefile | 22 +++++++++++++++++++++- linux-user/main.c | 1 + qemu-img.c | 1 + qmp.c | 1 + scripts/create_config | 4 ---- vl.c | 1 + 6 files changed, 25 insertions(+), 5 deletions(-)
Makefile +21 -1
@@ -49,7 +49,7 @@ ifneq ($(filter-out $(UNCHECKED_GOALS),$(MAKECMDGOALS)),$(if $(MAKECMDGOALS),,fa endif endif -GENERATED_HEADERS = config-host.h qemu-options.def +GENERATED_HEADERS = qemu-version.h config-host.h qemu-options.def GENERATED_HEADERS += qmp-commands.h qapi-types.h qapi-visit.h qapi-event.h GENERATED_SOURCES += qmp-marshal.c qapi-types.c qapi-visit.c qapi-event.c GENERATED_HEADERS += qmp-introspect.h
@@ -166,6 +166,26 @@ endif all: $(DOCS) $(TOOLS) $(HELPERS-y) recurse-all modules +qemu-version.h: FORCE + $(call quiet-command, \ + (cd $(SRC_PATH); \ + printf '#define QEMU_PKGVERSION '; \ + if test -n "$(PKGVERSION)"; then \ + printf '"$(PKGVERSION)"\n'; \ + else \ + printf '"-'; \ + if ! git status &>/dev/null; then \ + printf "no-git"; \ + else \ + git describe 2>/dev/null | tr -d '\n'; \ + if ! git diff-index --quiet HEAD &>/dev/null; then \ + printf '-dirty'; \ + fi \ + fi; \ + printf '"\n'; \ + fi) > [email protected]) + $(call quiet-command, cmp --quiet $@ [email protected] || mv [email protected] $@) + config-host.h: config-host.h-timestamp config-host.h-timestamp: config-host.mak qemu-options.def: $(SRC_PATH)/qemu-options.hx
linux-user/main.c +1 -0
@@ -17,6 +17,7 @@* along with this program; if not, see <http://www.gnu.org/licenses/>. */ #include "qemu/osdep.h" +#include "qemu-version.h" #include <sys/mman.h> #include <sys/syscall.h> #include <sys/resource.h>
qemu-img.c +1 -0
@@ -22,6 +22,7 @@* THE SOFTWARE. */ #include "qemu/osdep.h" +#include "qemu-version.h" #include "qapi/error.h" #include "qapi-visit.h" #include "qapi/qmp-output-visitor.h"
qmp.c +1 -0
@@ -14,6 +14,7 @@*/ #include "qemu/osdep.h" +#include "qemu-version.h" #include "qemu/cutils.h" #include "monitor/monitor.h" #include "sysemu/sysemu.h"
scripts/create_config +0 -4
@@ -9,10 +9,6 @@ case $line in version=${line#*=} echo "#define QEMU_VERSION \"$version\"" ;; - PKGVERSION=*) # configuration - pkgversion=${line#*=} - echo "#define QEMU_PKGVERSION \"$pkgversion\"" - ;; qemu_*dir=*) # qemu-specific directory configuration name=${line%=*} value=${line#*=}
vl.c +1 -0
@@ -22,6 +22,7 @@* THE SOFTWARE. */ #include "qemu/osdep.h" +#include "qemu-version.h" #include "qemu/cutils.h" #include "qemu/help_option.h"
Signature · 1 line
2.8.2
Quoted 18 lines · Fam Zheng
v2: Address Eric's comments:
"echo -n" -> "printf". "-unclean" -> "-dirty".
Makefilehappened to be in my working set because of the docker test work, so I went ahead to try this nice feature last evening before going to bed. My apologies if we have duplicated work.Please review, especially please comment on the redundant version string:
$ qemu-img --version qemu-img version 2.6.50-v2.6.0-603-g684a494, Copyright (c) 2004-2008 Fabrice BellardFam Zheng (2):
Makefile: Add a "FORCE" target
Makefile: Derive "PKGVERSION" from "git describe" by default
Quoted 8 lines
Makefile | 24 ++++++++++++++++++++++-- linux-user/main.c | 1 + qemu-img.c | 1 + qmp.c | 1 + scripts/create_config | 4 ---- vl.c | 1 + 6 files changed, 26 insertions(+), 6 deletions(-)
I only skimmed the git commands in patch #2:
git status --> this verifies if we have git at all, and refreshes the
index if we do, in the same step, so that's good
git describe --> okay
git diff-index --quiet HEAD --> okay
Another advantage of this approach seems to be that it sets the version at "make", not at "configure", time.
Some comments / questions on the version string:
- What happens if "--with-pkgversion=blah" was passed to ./configure? Do I see it right that in that case there's no change in behavior?
- I think the following format would look better (stolen from --with-pkgversion):
2.6.50 (v2.6.0-603-g684a494)
Thanks
Laszlo
Quoted 3 lines · Laszlo Ersek
Some comments / questions on the version string:
- What happens if "--with-pkgversion=blah" was passed to ./configure? Do I see it right that in that case there's no change in behavior?
Yes, Makefile only generates it when ./configure says it's empty.
Quoted 5 lines
- I think the following format would look better (stolen from --with-pkgversion):
2.6.50 (v2.6.0-603-g684a494)
Great idea!
Fam