From mboxrd@z Thu Jan 1 00:00:00 1970 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=-6.3 required=3.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,HTML_MESSAGE,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=no 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 6FBD6C4363D for ; Tue, 6 Oct 2020 11:59:27 +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 AE7322080A for ; Tue, 6 Oct 2020 11:59:26 +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="RbeXGiud" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org AE7322080A 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]:33874 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kPlcr-0007Aa-Qz for qemu-devel@archiver.kernel.org; Tue, 06 Oct 2020 07:59:25 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45720) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kPlc3-0006Tv-5T; Tue, 06 Oct 2020 07:58:35 -0400 Received: from mail-lf1-x141.google.com ([2a00:1450:4864:20::141]:33222) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kPlc0-0002hy-UA; Tue, 06 Oct 2020 07:58:34 -0400 Received: by mail-lf1-x141.google.com with SMTP id l2so1718882lfk.0; Tue, 06 Oct 2020 04:58:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:reply-to:from:date:message-id :subject:to:cc; bh=d/ACYVMmG+7n+3iSOZ1DEV1o5A2H0K9Zn5bkNvKZ2OQ=; b=RbeXGiudpGC2/loMBwz3GbqJUOQU/C/HmANVyg/EDrCQEU/Jn0thcNagsQyQdSmSvU xBgCpygQqRUFdagP8GHKz4Hu3v1ZMpaHsMfFN6mHM8naFWEl/Xc49sffd9AkrL+iCxmb ORhs+D+rJsEBtLBjCag03Zr48kpQk7JTCsX5cFeBh3p0037uZ6lTg1BKW6fC8taL4Hva fC/3i1dk7kj3fhCTt833r2Fp/iTgiBWpTY64hYPQIbZs2Dgu5jPcW7PkuwPKHWIp0t4p u1cSCmmAnt66/Dx6zL+3FzhQ+6N5vHn6wKwQo6lmPY13NoOIXLIrkw/Tyvy20tjqkUIN l3FA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:reply-to :from:date:message-id:subject:to:cc; bh=d/ACYVMmG+7n+3iSOZ1DEV1o5A2H0K9Zn5bkNvKZ2OQ=; b=nf7CiNc/hIrTAHsMaTM7UgJ23cnl/9Vew6os+cwDWFN4+JWIJ+Ytn21UUAELLJK+Mb omXHc4dBbkVbN6etgEvSy16j79+O/5FrjZVqlKZYIHOJbhxnrjZbbPbwHQ1MZiKr7dQj MZCVTDYL5Ud621gwgNNQEqTtT95eEeFTM2BsGH2nrNeQOklzyq3YwIMleOFXesU04ss8 AsV0S06C2oQUmSluHosV9z3amhsFKoArL4IYSqY8lA6REskQZ1LQughl1aSEEOKKOpwU Yf9iFSuh5LRH8Wm4ZTTRbcEttTTwrQ7kAJNGqKrVSMIkupLb7bD8PD1rWXIXTt8eoLZI UlGA== X-Gm-Message-State: AOAM5300bw082oWRGNUqpA+Ub60vQslKdPHYC0m6e6dyXA6ZbrGN1DMq 82zAYLOnVjnTluG/04GF+N0mbJj2HYwueCmLXKs= X-Google-Smtp-Source: ABdhPJwV6YpJoW9WD9yvShhtZ3IA79b+CYQsLHSM5Ae0ZkGGIa7PEJ7X/DYhwh6551UOA5yddYDmiN0z/JhUpnRtIcg= X-Received: by 2002:a19:383:: with SMTP id 125mr409686lfd.356.1601985510444; Tue, 06 Oct 2020 04:58:30 -0700 (PDT) MIME-Version: 1.0 References: <20201006112139.700-1-luoyonggang@gmail.com> In-Reply-To: From: =?UTF-8?B?572X5YuH5YiaKFlvbmdnYW5nIEx1byk=?= Date: Tue, 6 Oct 2020 19:58:19 +0800 Message-ID: Subject: Re: [PATCH v5] scripts: Convert qemu-version.sh to qemu-version.py To: Paolo Bonzini Content-Type: multipart/alternative; boundary="0000000000004911cd05b0ff5159" Received-SPF: pass client-ip=2a00:1450:4864:20::141; envelope-from=luoyonggang@gmail.com; helo=mail-lf1-x141.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, HTML_MESSAGE=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: , Reply-To: luoyonggang@gmail.com Cc: QEMU Trivial , Peter Maydell , Thomas Huth , qemu-level , =?UTF-8?B?UGhpbGlwcGUgTWF0aGlldS1EYXVk6IyF?= Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" --0000000000004911cd05b0ff5159 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Tue, Oct 6, 2020 at 7:34 PM Paolo Bonzini wrote: > > On 06/10/20 13:21, Yonggang Luo wrote: > > 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.co= m/ > > > > Testing args length and if not enough, setting pkgversion and version to '' > > > > Signed-off-by: Yonggang Luo > > --- > > meson.build | 2 +- > > scripts/qemu-version.py | 31 +++++++++++++++++++++++++++++++ > > scripts/qemu-version.sh | 25 ------------------------- > > 3 files changed, 32 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 95a532bd29..20f653b6eb 100644 > > --- a/meson.build > > +++ b/meson.build > > @@ -1072,7 +1072,7 @@ tracetool =3D [ > > '--backend=3D' + config_host['TRACE_BACKENDS'] > > ] > > > > -qemu_version_cmd =3D [find_program('scripts/qemu-version.sh'), > > +qemu_version_cmd =3D [find_program('scripts/qemu-version.py'), > > meson.current_source_dir(), > > config_host['PKGVERSION'], meson.project_version()= ] > > qemu_version =3D custom_target('qemu-version.h', > > diff --git a/scripts/qemu-version.py b/scripts/qemu-version.py > > new file mode 100644 > > index 0000000000..e6eb548220 > > --- /dev/null > > +++ b/scripts/qemu-version.py > > @@ -0,0 +1,31 @@ > > +#!/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 > > + > > +def main(_program, dir, pkgversion, version, *unused): > > + if len(pkgversion) =3D=3D 0: > > + pc =3D subprocess.run(['git', 'describe', '--match', "'v*'", '--dirty', '--always'], > > + stdout=3Dsubprocess.PIPE, stderr=3Dsubprocess.DEVNULL, cwd=3Ddir) > > + if pc.returncode =3D=3D 0: > > + pkgversion =3D pc.stdout.decode('utf8').strip() > > + > > + fullversion =3D version > > + if pkgversion: > > + fullversion =3D "{} ({})".format(version, pkgversion) > > + > > + print('#define QEMU_PKGVERSION "%s"' % pkgversion) > > + print('#define QEMU_FULL_VERSION "%s"' % fullversion) > > + > > +if __name__ =3D=3D "__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=3D"$1" > > -pkgversion=3D"$2" > > -version=3D"$3" > > - > > -if [ -z "$pkgversion" ]; then > > - cd "$dir" > > - if [ -e .git ]; then > > - pkgversion=3D$(git describe --match 'v*' --dirty | echo "") > > - fi > > -fi > > - > > -if [ -n "$pkgversion" ]; then > > - fullversion=3D"$version ($pkgversion)" > > -else > > - fullversion=3D"$version" > > -fi > > - > > -cat < > -#define QEMU_PKGVERSION "$pkgversion" > > -#define QEMU_FULL_VERSION "$fullversion" > > -EOF > > > > Hmm it still doesn't check for a ".git" directory. I'll fix it up, but > please pay more attention to the reviews. Oh sorry for that I didn't explain that, I am using stderr=3Dsubprocess.DEVNULL to supress git error, so if git failed then it does nothing But after deep though, with .git check are more safe > > Paolo > -- =E6=AD=A4=E8=87=B4 =E7=A4=BC =E7=BD=97=E5=8B=87=E5=88=9A Yours sincerely, Yonggang Luo --0000000000004911cd05b0ff5159 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable


On Tue, Oct 6, 2020 at 7:34 PM Paolo Bonzini <<= a href=3D"mailto:pbonzini@redhat.com" target=3D"_blank">pbonzini@redhat.com= > wrote:
>
> On 06/10/20 13:21, Yonggang Luo wrote:
&= gt; > The sh script are harder to maintain for compatible different
&= gt; > xsh environment so convert it to python script
> > Also i= ncorporate the fixes in
> > https= ://patchew.org/QEMU/20200929143654.518157-1-marcandre.lureau@redhat.com/
> >
> > Testing args length and if not enough, setting = pkgversion and version to ''
> >
> > Signed-off-b= y: Yonggang Luo <
luoyonggang@gmail.com>
> > ---
> > =C2=A0meson= .build =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 | =C2=A02 +-
> > = =C2=A0scripts/qemu-version.py | 31 +++++++++++++++++++++++++++++++
> = > =C2=A0scripts/qemu-version.sh | 25 -------------------------
> &= gt; =C2=A03 files changed, 32 insertions(+), 26 deletions(-)
> > = =C2=A0create mode 100644 scripts/qemu-version.py
> > =C2=A0delete = mode 100755 scripts/qemu-version.sh
> >
> > diff --git a/= meson.build b/meson.build
> > index 95a532bd29..20f653b6eb 100644<= br>> > --- a/meson.build
> > +++ b/meson.build
> > = @@ -1072,7 +1072,7 @@ tracetool =3D [
> > =C2=A0 =C2=A0 '--bac= kend=3D' + config_host['TRACE_BACKENDS']
> > =C2=A0]> >
> > -qemu_version_cmd =3D [find_program('scripts/= qemu-version.sh'),
> > +qemu_version_cmd =3D [find_program(= 9;scripts/qemu-version.py'),
> > =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0meson.current_source_dir(),=
> > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0config_host['PKGVERSION'], meson.project_version()= ]
> > =C2=A0qemu_version =3D custom_target('qemu-version.h'= ;,
> > diff --git a/scripts/qemu-version.py b/scripts/qemu-version= .py
> > new file mode 100644
> > index 0000000000..e6eb54= 8220
> > --- /dev/null
> > +++ b/scripts/qemu-version.py<= br>> > @@ -0,0 +1,31 @@
> > +#!/usr/bin/env python3
> = > +
> > +#
> > +# Script for retrieve qemu git version= information
> > +#
> > +# Authors:
> > +# =C2= =A0Yonggang Luo <luoyonggang@gmail.com>
> > +#
> > +# This work= is licensed under the terms of the GNU GPL, version 2
> > +# or, = at your option, any later version.=C2=A0 See the COPYING file in
> &g= t; +# the top-level directory.
> > +
> > +import sys
&= gt; > +import subprocess
> > +
> > +def main(_program,= dir, pkgversion, version, *unused):
> > + =C2=A0 =C2=A0if len(pkg= version) =3D=3D 0:
> > + =C2=A0 =C2=A0 =C2=A0 =C2=A0pc =3D subproc= ess.run(['git', 'describe', '--match', "'v= *'", '--dirty', '--always'],
> > + =C2=A0= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0stdout=3Dsubprocess.PIPE, stderr=3Dsubprocess.DEVNULL, cwd= =3Ddir)
> > + =C2=A0 =C2=A0 =C2=A0 =C2=A0if pc.returncode =3D=3D 0= :
> > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0pkgversion =3D pc= .stdout.decode('utf8').strip()
> > +
> > + =C2=A0= =C2=A0fullversion =3D version
> > + =C2=A0 =C2=A0if pkgversion:> > + =C2=A0 =C2=A0 =C2=A0 =C2=A0fullversion =3D "{} ({})"= ;.format(version, pkgversion)
> > +
> > + =C2=A0 =C2=A0pr= int('#define QEMU_PKGVERSION "%s"' % pkgversion)
> = > + =C2=A0 =C2=A0print('#define QEMU_FULL_VERSION "%s"'= ; % fullversion)
> > +
> > +if __name__ =3D=3D "__ma= in__":
> > + =C2=A0 =C2=A0main(*sys.argv)
> > diff -= -git a/scripts/qemu-version.sh b/scripts/qemu-version.sh
> > delet= ed file mode 100755
> > index 03128c56a2..0000000000
> > = --- a/scripts/qemu-version.sh
> > +++ /dev/null
> > @@ -1= ,25 +0,0 @@
> > -#!/bin/sh
> > -
> > -set -eu> > -
> > -dir=3D"$1"
> > -pkgversion=3D= "$2"
> > -version=3D"$3"
> > -
>= ; > -if [ -z "$pkgversion" ]; then
> > - =C2=A0 =C2= =A0cd "$dir"
> > - =C2=A0 =C2=A0if [ -e .git ]; then
= > > - =C2=A0 =C2=A0 =C2=A0 =C2=A0pkgversion=3D$(git describe --match = 'v*' --dirty | echo "")
> > - =C2=A0 =C2=A0fi> > -fi
> > -
> > -if [ -n "$pkgversion"= ]; then
> > - =C2=A0 =C2=A0fullversion=3D"$version ($pkgvers= ion)"
> > -else
> > - =C2=A0 =C2=A0fullversion=3D&qu= ot;$version"
> > -fi
> > -
> > -cat <<= ;EOF
> > -#define QEMU_PKGVERSION "$pkgversion"
> = > -#define QEMU_FULL_VERSION "$fullversion"
> > -EOF<= br>> >
>
> Hmm it still doesn't check for a ".gi= t" directory.=C2=A0 I'll fix it up, but
> please pay more at= tention to the reviews.
Oh sorry for that I didn't explain that, I = am using=C2=A0 stderr=3Dsubprocess.DEVNULL=C2=A0 to supress git error, so if git failed th= en it does nothing

But after deep though, with .gi= t check are more safe
>
> Paolo
>


--
=C2=A0= =C2=A0 =C2=A0 =C2=A0 =C2=A0=E6=AD=A4=E8=87=B4
=E7=A4=BC
=E7=BD=97=E5= =8B=87=E5=88=9A
Yours
=C2=A0 =C2=A0 sincerely,
Yonggang Luo
<= /div> --0000000000004911cd05b0ff5159--