From nobody Sun Feb 8 01:33:55 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1570621411; cv=none; d=zoho.com; s=zohoarc; b=hQmz0sl2yVOyrcGA2oRwe0aq6gVH5tl1VuEQs6zic2L+3r5z5B0bDfDEBZCThzvka52feoaGS0Dp6NIOnGuSap7GJjvCKQqrg2Fpc2AaEbvheuy1ZiWbl3fXkalEieTR1dQpjSjjgDwwIMkliF2fuXO/0lhUFPCnorkTfxxETuk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1570621411; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=y14nvQnC29vqa/5PRtYPXCxZ5Id5VrsBbPHkqEvb/eY=; b=fApQQOSCVrPI3ED9UUZnT+fUSP2ZU3t+oUabvAnuhnjerf1NoSzEn9TV0NP67vOEBq8VqZe2gb2R7Z9aXzl2Sk+m+tV8D3DdOecHKlv9gvt0QYczmqBicByaDBnnLT2ntgNs/z6xazZJIr4wsPskxFtlT85AibodZqNrQxMv/TQ= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1570621411220182.17211363942477; Wed, 9 Oct 2019 04:43:31 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A5A8381F31; Wed, 9 Oct 2019 11:43:29 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7CCDC5C1D6; Wed, 9 Oct 2019 11:43:29 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 39F10180BA9B; Wed, 9 Oct 2019 11:43:29 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x99BhJ0l030080 for ; Wed, 9 Oct 2019 07:43:19 -0400 Received: by smtp.corp.redhat.com (Postfix) id EBD506031D; Wed, 9 Oct 2019 11:43:19 +0000 (UTC) Received: from catbus.gsslab.fab.redhat.com (dhcp-32.gsslab.fab.redhat.com [10.33.9.32]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5E9B360475; Wed, 9 Oct 2019 11:43:18 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Wed, 9 Oct 2019 12:37:29 +0100 Message-Id: <20191009113741.5002-15-berrange@redhat.com> In-Reply-To: <20191009113741.5002-1-berrange@redhat.com> References: <20191009113741.5002-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v4 14/26] src: rewrite driver impl checker in Python X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Wed, 09 Oct 2019 11:43:30 +0000 (UTC) As part of an goal to eliminate Perl from libvirt build tools, rewrite the check-driverimpls.pl tool in Python. This was a straight conversion, manually going line-by-line to change the syntax from Perl to Python. Thus the overall structure of the file and approach is the same. Signed-off-by: Daniel P. Berrang=C3=A9 --- Makefile.am | 1 + scripts/check-driverimpls.py | 102 +++++++++++++++++++++++++++++++++++ src/Makefile.am | 4 +- src/check-driverimpls.pl | 80 --------------------------- 4 files changed, 105 insertions(+), 82 deletions(-) create mode 100755 scripts/check-driverimpls.py delete mode 100755 src/check-driverimpls.pl diff --git a/Makefile.am b/Makefile.am index 51c39b6e01..68a1df0167 100644 --- a/Makefile.am +++ b/Makefile.am @@ -48,6 +48,7 @@ EXTRA_DIST =3D \ scripts/augeas-gentest.py \ scripts/check-aclperms.py \ scripts/check-drivername.py \ + scripts/check-driverimpls.py \ scripts/check-spacing.py \ scripts/check-symfile.py \ scripts/check-symsorting.py \ diff --git a/scripts/check-driverimpls.py b/scripts/check-driverimpls.py new file mode 100755 index 0000000000..78d53e75a4 --- /dev/null +++ b/scripts/check-driverimpls.py @@ -0,0 +1,102 @@ +#!/usr/bin/env python +# +# Copyright (C) 2013-2019 Red Hat, Inc. +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library. If not, see +# . +# + +from __future__ import print_function + +import re +import sys + + +def checkdriverimpls(filename): + intable =3D False + mainprefix =3D None + + errs =3D False + with open(filename, "r") as fh: + lineno =3D 0 + for line in fh: + lineno =3D lineno + 1 + if intable: + if line.find("}") !=3D -1: + intable =3D False + mainprefix =3D None + continue + + m =3D re.search(r'''\.(\w+)\s*=3D\s*(\w+),?/''', line) + if m is not None: + api =3D m.group(1) + impl =3D m.group(2) + + if api in ["no", "name"]: + continue + if impl in ["NULL"]: + continue + + suffix =3D impl + prefix =3D re.sub(r'''^([a-z]+)(.*?)$''', r'''\1''', i= mpl) + + if mainprefix is not None: + if mainprefix !=3D prefix: + print("%s:%d Bad prefix '%s' for API '%s', " + + "expecting '%s'" % + (filename, lineno, prefix, api, mainpref= ix), + file=3Dsys.stderr) + errs =3D True + else: + mainprefix =3D prefix + + if not api.startswith(mainprefix): + suffix =3D re.sub(r'''^[a-z]+''', "", suffix) + suffix =3D re.sub(r'''^([A-Z]+)''', + lambda m: m.group(1).lower(), suff= ix) + + if api !=3D suffix: + want =3D api + if want.startswith("nwf"): + want =3D "NWF" + want[3:] + + if not api.startswith(mainprefix): + want =3D re.sub(r'''^([a-z])''', + lambda m: m.group(1).upper(), wa= nt) + want =3D mainprefix + want + + print("%s:%d Bad impl name '%s' for API " + + "'%s', expecting '%s'" % + (filename, lineno, impl, api, want), + file=3Dsys.stderr) + errs =3D True + else: + m =3D re.search(r'''^(?:static\s+)?(vir(?:\w+)?Driver)''' + + r'''\s+(?!.*;)''', line) + if m is not None: + drv =3D m.group(1) + if drv in ["virNWFilterCallbackDriver", + "virNWFilterTechDriver", + "virConnectDriver"]: + continue + intable =3D True + + return errs + + +status =3D 0 +for filename in sys.argv[1:]: + if checkdriverimpls(filename): + status =3D 1 +sys.exit(status) diff --git a/src/Makefile.am b/src/Makefile.am index 9cf4ef2a6c..e3d58e4112 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -354,7 +354,7 @@ check-drivername: $(srcdir)/libvirt_lxc.syms =20 check-driverimpls: - $(AM_V_GEN)$(PERL) $(srcdir)/check-driverimpls.pl \ + $(AM_V_GEN)$(RUNUTF8) $(PYTHON) $(top_srcdir)/scripts/check-driverimpls.p= y \ $(filter /%,$(DRIVER_SOURCE_FILES)) \ $(filter $(srcdir)/%,$(DRIVER_SOURCE_FILES)) \ $(addprefix $(srcdir)/,$(filter-out $(srcdir)/%, \ @@ -370,7 +370,7 @@ check-aclperms: $(srcdir)/access/viraccessperm.h \ $(srcdir)/access/viraccessperm.c =20 -EXTRA_DIST +=3D check-driverimpls.pl check-aclrules.pl +EXTRA_DIST +=3D check-aclrules.pl =20 check-local: check-protocol check-symfile check-symsorting \ check-drivername check-driverimpls check-aclrules \ diff --git a/src/check-driverimpls.pl b/src/check-driverimpls.pl deleted file mode 100755 index 3c0d54724c..0000000000 --- a/src/check-driverimpls.pl +++ /dev/null @@ -1,80 +0,0 @@ -#!/usr/bin/env perl -# -# Copyright (C) 2013 Red Hat, Inc. -# -# This library is free software; you can redistribute it and/or -# modify it under the terms of the GNU Lesser General Public -# License as published by the Free Software Foundation; either -# version 2.1 of the License, or (at your option) any later version. -# -# This library is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# Lesser General Public License for more details. -# -# You should have received a copy of the GNU Lesser General Public -# License along with this library. If not, see -# . -# - -use strict; -use warnings; - -my $intable =3D 0; -my $table; -my $mainprefix; - -my $status =3D 0; -while (<>) { - if ($intable) { - if (/}/) { - $intable =3D 0; - $table =3D undef; - $mainprefix =3D undef; - } elsif (/\.(\w+)\s*=3D\s*(\w+),?/) { - my $api =3D $1; - my $impl =3D $2; - - next if $api eq "no"; - next if $api eq "name"; - next if $impl eq "NULL"; - - my $suffix =3D $impl; - my $prefix =3D $impl; - $prefix =3D~ s/^([a-z]+)(.*?)$/$1/; - - if (defined $mainprefix) { - if ($mainprefix ne $prefix) { - print "$ARGV:$. Bad prefix '$prefix' for API '$api', e= xpecting '$mainprefix'\n"; - $status =3D 1; - } - } else { - $mainprefix =3D $prefix; - } - - if ($api !~ /^$mainprefix/) { - $suffix =3D~ s/^[a-z]+//; - $suffix =3D~ s/^([A-Z]+)/lc $1/e; - } - - if ($api ne $suffix) { - my $want =3D $api; - $want =3D~ s/^nwf/NWF/; - if ($api !~ /^$mainprefix/) { - $want =3D~ s/^([a-z])/uc $1/e; - $want =3D $mainprefix . $want; - } - print "$ARGV:$. Bad impl name '$impl' for API '$api', expe= cting '$want'\n"; - $status =3D 1; - } - } - } elsif (/^(?:static\s+)?(vir(?:\w+)?Driver)\s+(?!.*;)/) { - next if $1 eq "virNWFilterCallbackDriver" || - $1 eq "virNWFilterTechDriver" || - $1 eq "virConnectDriver"; - $intable =3D 1; - $table =3D $1; - } -} - -exit $status; --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list