From patchwork Tue May 31 15:04:04 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laszlo Ersek X-Patchwork-Id: 68944 Delivered-To: patch@linaro.org Received: by 10.140.92.199 with SMTP id b65csp2007704qge; Tue, 31 May 2016 08:06:52 -0700 (PDT) X-Received: by 10.140.93.97 with SMTP id c88mr30427358qge.64.1464707210004; Tue, 31 May 2016 08:06:50 -0700 (PDT) Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id x91si31339202qtd.1.2016.05.31.08.06.49 for (version=TLS1 cipher=AES128-SHA bits=128/128); Tue, 31 May 2016 08:06:49 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org Received: from localhost ([::1]:36861 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b7lFp-00037z-Jq for patch@linaro.org; Tue, 31 May 2016 11:06:49 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39462) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b7lDN-0001u9-18 for qemu-devel@nongnu.org; Tue, 31 May 2016 11:04:18 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b7lDG-0005t3-UF for qemu-devel@nongnu.org; Tue, 31 May 2016 11:04:15 -0400 Received: from mx1.redhat.com ([209.132.183.28]:44858) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b7lDG-0005sy-Oc for qemu-devel@nongnu.org; Tue, 31 May 2016 11:04:10 -0400 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1BFA47F344 for ; Tue, 31 May 2016 15:04:10 +0000 (UTC) Received: from lacos-laptop-7.usersys.redhat.com (ovpn-116-184.phx2.redhat.com [10.3.116.184]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u4VF48AR015682; Tue, 31 May 2016 11:04:09 -0400 From: Laszlo Ersek To: qemu-devel@nongnu.org Date: Tue, 31 May 2016 17:04:04 +0200 Message-Id: <1464707044-10447-1-git-send-email-lersek@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Tue, 31 May 2016 15:04:10 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH] configure: save git working tree information in "pkgversion" X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" 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" Cc: Kashyap Chamarthy Signed-off-by: Laszlo Ersek --- configure | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) -- 1.8.3.1 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