From patchwork Wed Oct 7 19:50:35 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?572X5YuH5YiaKFlvbmdnYW5nIEx1byk=?= X-Patchwork-Id: 271850 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.3 required=3.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_INVALID, DKIM_SIGNED, FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 57C27C4363C for ; Wed, 7 Oct 2020 19:51:50 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 9B924206F4 for ; Wed, 7 Oct 2020 19:51:49 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="IpTz36up" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9B924206F4 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:57610 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kQFTY-000391-KM for qemu-devel@archiver.kernel.org; Wed, 07 Oct 2020 15:51:48 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58988) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kQFSl-0002D0-Jx; Wed, 07 Oct 2020 15:50:59 -0400 Received: from mail-pf1-x42e.google.com ([2607:f8b0:4864:20::42e]:35561) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kQFSj-0002YF-89; Wed, 07 Oct 2020 15:50:59 -0400 Received: by mail-pf1-x42e.google.com with SMTP id k8so1999908pfk.2; Wed, 07 Oct 2020 12:50:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=1YYyNUTrs8LpEP4iBDXNDMxJb6UWYAD/KDaE5MUPJZw=; b=IpTz36upedFkt5KT5PKxM98CEnCkW7Wp0xFqsr5n12rLDEDxYqqWAfaWsZRYUbfhF1 /zb5YOmarZcJWGo4ilM7R6CehJX4g2ijtxQtd/ACd0wzoPF5dpOqvyQ4WDckbkW3W1e2 Sv6EXK7hhW58XoZQ9/A/xqK/n0x5bvmz2f00gOXthJgSpKXJDfA4/7GDbT8sCua+BBdO dBHIx7vcGowLvi/nLXvgDSGfsm9uHBIdhVBQNXOHNmPRM1RfvHVw+FmU177zt4es81YV fQh2kChBWUVFFj6cOMd1s15nmWeEKocPa5kyf4D9Zo5eAEw2MZecGMczDVDI7V3MRYO9 OKKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=1YYyNUTrs8LpEP4iBDXNDMxJb6UWYAD/KDaE5MUPJZw=; b=phob5T9u7dmbwLlgFrOiIc5DgqoG9OCWxwqn2//w8IXep5FBQToHk2Di5IzEwO9b8R IrzJtcKQpVbe3ubPMg/EjADsYfGAtDq1/ivg5PdUI9wYg7A+RyRqSOms9bf19mskhwoi WpjEhA+CAUzqQpejsjbWeLIcrIIDD8s+hX080sD/TDOqw1nOBZRIFpsofpby+5U4NNQM a4RqTZvjl5jHAvMzeIXi7XT7AQVUQLTrk05HVz2oWfsTIAE7pesvkNzC8+u2T3oQt5TR XbbSDDfIo1O8qxO8d9B2vQvOS6gUG4ErD8y+UO5z2Io3fnvdiBiI+rgBxHnneoCNpgUf +eLA== X-Gm-Message-State: AOAM530JDhXUzisIcbxhsPzT2q1vhG8ie5w3QdxMnEv2AYS7W1WEhutc 1ztvBrG4vX19rOXWiRDX/k4592sGHCJ9pA== X-Google-Smtp-Source: ABdhPJxFOWK6IQ+T8mIXPzDhYfnts6HsMzIHq4gbwkWkgWhh/q8XtopCMtr1Px/gZbXpXvXk9rOZcg== X-Received: by 2002:a17:90a:64ce:: with SMTP id i14mr2879009pjm.97.1602100254788; Wed, 07 Oct 2020 12:50:54 -0700 (PDT) Received: from localhost.localdomain ([103.94.185.75]) by smtp.googlemail.com with ESMTPSA id 9sm4105141pfx.138.2020.10.07.12.50.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Oct 2020 12:50:53 -0700 (PDT) From: Yonggang Luo To: qemu-devel@nongnu.org Subject: [PATCH v9] scripts: Convert qemu-version.sh to qemu-version.py Date: Thu, 8 Oct 2020 03:50:35 +0800 Message-Id: <20201007195035.2006-1-luoyonggang@gmail.com> X-Mailer: git-send-email 2.28.0.windows.1 MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::42e; envelope-from=luoyonggang@gmail.com; helo=mail-pf1-x42e.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Thomas Huth , QEMU Trivial , =?utf-8?q?Philippe_Mathieu-Da?= =?utf-8?b?dWTojIU=?= , Yonggang Luo , Paolo Bonzini Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" The sh script are harder to maintain for compatible different xsh environment so convert it to python script Also incorporate the fixes in https://patchew.org/QEMU/20200929143654.518157-1-marcandre.lureau@redhat.com/ Using --match=v* instead of --match 'v*' for speed up the git version And using --match=v\\* to resolve wildcard problem on windows. Tested under Ubuntu/msys2/mingw. Signed-off-by: Yonggang Luo Message-Id: <20201006112139.700-1-luoyonggang@gmail.com> Signed-off-by: Paolo Bonzini --- meson.build | 2 +- scripts/qemu-version.py | 35 +++++++++++++++++++++++++++++++++++ scripts/qemu-version.sh | 25 ------------------------- 3 files changed, 36 insertions(+), 26 deletions(-) create mode 100644 scripts/qemu-version.py delete mode 100755 scripts/qemu-version.sh diff --git a/meson.build b/meson.build index 26230614ba..1d3bb25bc6 100644 --- a/meson.build +++ b/meson.build @@ -1132,7 +1132,7 @@ tracetool = [ '--backend=' + config_host['TRACE_BACKENDS'] ] -qemu_version_cmd = [find_program('scripts/qemu-version.sh'), +qemu_version_cmd = [find_program('scripts/qemu-version.py'), meson.current_source_dir(), config_host['PKGVERSION'], meson.project_version()] qemu_version = custom_target('qemu-version.h', diff --git a/scripts/qemu-version.py b/scripts/qemu-version.py new file mode 100644 index 0000000000..c633cb1e54 --- /dev/null +++ b/scripts/qemu-version.py @@ -0,0 +1,35 @@ +#!/usr/bin/env python3 + +# +# Script for retrieve qemu git version information +# +# Authors: +# Yonggang Luo +# +# This work is licensed under the terms of the GNU GPL, version 2 +# or, at your option, any later version. See the COPYING file in +# the top-level directory. + +import sys +import subprocess +import os, os.path +import platform + +def main(_program, dir, pkgversion, version, *unused): + os.chdir(dir) + if not pkgversion and os.path.exists('.git'): + match_expression = '--match=v\\*' if platform.system() == 'Windows' else '--match=v*' + pc = subprocess.run(['git', 'describe', match_expression, '--dirty', '--always'], + stdout=subprocess.PIPE, stderr=subprocess.DEVNULL, encoding='utf8', shell=False) + if pc.returncode == 0: + pkgversion = pc.stdout.strip() + + fullversion = version + if pkgversion: + fullversion = "{} ({})".format(version, pkgversion) + + print('#define QEMU_PKGVERSION "%s"' % pkgversion) + print('#define QEMU_FULL_VERSION "%s"' % fullversion) + +if __name__ == "__main__": + main(*sys.argv) diff --git a/scripts/qemu-version.sh b/scripts/qemu-version.sh deleted file mode 100755 index 03128c56a2..0000000000 --- a/scripts/qemu-version.sh +++ /dev/null @@ -1,25 +0,0 @@ -#!/bin/sh - -set -eu - -dir="$1" -pkgversion="$2" -version="$3" - -if [ -z "$pkgversion" ]; then - cd "$dir" - if [ -e .git ]; then - pkgversion=$(git describe --match 'v*' --dirty | echo "") - fi -fi - -if [ -n "$pkgversion" ]; then - fullversion="$version ($pkgversion)" -else - fullversion="$version" -fi - -cat <