qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH] configure: save git working tree information in "pk


From: Laszlo Ersek
Subject: [Qemu-devel] [PATCH] configure: save git working tree information in "pkgversion"
Date: Tue, 31 May 2016 17:04:04 +0200

When building QEMU from a git working tree (either in-tree or
out-of-tree), it is useful to capture the working tree status in the QEMU
binary, for the "-version" option to report.

Daniel suggested using the "pkgversion" variable (tied to the
"--with-pkgversion" option) of the configure script for this. Downstream
packagers of QEMU already use this option for customizing their builds,
plus libvirtd captures "pkgversion" (with the "-version" option) in
"/var/log/libvirt/qemu/$GUEST.log", whenever a guest is started.

The information we include in "pkgversion" is the output of git-describe,
with a plus sign (+) appended if there are staged or unstaged changes to
tracked files, at the time of "configure" being executed.

The content of "pkgversion" is not changed when "--with-pkgversion" is
used on the command line.

Cc: "Daniel P. Berrange" <address@hidden>
Cc: Kashyap Chamarthy <address@hidden>
Signed-off-by: Laszlo Ersek <address@hidden>
---
 configure | 38 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 38 insertions(+)

diff --git a/configure b/configure
index b5aab7257b33..20a7ec5cc0fd 100755
--- a/configure
+++ b/configure
@@ -4255,6 +4255,44 @@ if have_backend "dtrace"; then
 fi
 
 ##########################################
+# save git working tree information in pkgversion
+
+# If pkgversion has not been set to a non-empty string, fetch the output of
+# "git describe" into it. If the working tree is unclean (there are staged or
+# unstaged changes in tracked files), then append a plus sign.
+#
+# If we're not building from a git working tree, then pkgversion is not
+# changed. Otherwise, git errors are fatal.
+
+if test -z "$pkgversion" && test -d "$source_path/.git"; then
+  pkgversion=$(
+    export GIT_DIR=$source_path/.git
+    export GIT_WORK_TREE=$source_path
+
+    git_desc=$(git describe)
+    git_exit=$?
+    if test $git_exit -ne 0; then
+      exit $git_exit
+    fi
+
+    git_changes=
+    for git_diff_option in "" --staged; do
+      git diff $git_diff_option --quiet
+      git_exit=$?
+      case $git_exit in
+      (0) ;;
+      (1) git_changes=+
+          ;;
+      (*) exit $git_exit
+          ;;
+      esac
+    done
+
+    printf " (%s%s)" "$git_desc" "$git_changes"
+  ) || error_exit "Failed to get git description, working tree or index status"
+fi
+
+##########################################
 # check and set a backend for coroutine
 
 # We prefer ucontext, but it's not always possible. The fallback
-- 
1.8.3.1




reply via email to

[Prev in Thread] Current Thread [Next in Thread]