From nobody Tue Nov 26 13:41:13 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 207.211.31.81 as permitted sender) client-ip=207.211.31.81; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 207.211.31.81 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=1573483524; cv=none; d=zoho.com; s=zohoarc; b=L5f1jdwC4MFzDNLE3BJLZtvJ8Q3zNkoaCCZRWpN+q2TRLrFpDh9B5Cq9M2X7wPbiSuRhMBxJY/EqQe6opAY+snyxGqoLSeE6pnIEqdcO1nWdk03ISmUpgMkqqmy8+B4FRbXkV6eBNOGeKlvMqtVhk9aVqR9VzTtu9LiLHXZnOXs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1573483524; 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=ZKjYDIo+KGyEClqJI317b/hd7waZ6QhXFJJ/QIFmBq4=; b=jzU6AWR7O9ady7LIakxykNfDpI905n2Zlu+tO7Af2A3lPTDw2fSgIritZUDJnxNMIsYU73Dh0kTSrgmokKdynXKsVPeTgTIo5ZCqiT/2bGQOtzbEdqdbRm38Y+41aooP/WYKuDPuqAeRjB1WuKx0pPdjIj666T3gMaKS0u6C7Ks= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 207.211.31.81 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-1.mimecast.com (us-smtp-1.mimecast.com [207.211.31.81]) by mx.zohomail.com with SMTPS id 1573483524330587.0352184692581; Mon, 11 Nov 2019 06:45:24 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-57-aGeTu-oVPEK8CRRLb0ijAQ-1; Mon, 11 Nov 2019 09:45:18 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 651D28A243E; Mon, 11 Nov 2019 14:45:09 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 262131001B03; Mon, 11 Nov 2019 14:45:09 +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 A3C5E4BB65; Mon, 11 Nov 2019 14:45:08 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id xABEixvQ020435 for ; Mon, 11 Nov 2019 09:44:59 -0500 Received: by smtp.corp.redhat.com (Postfix) id 56CEE5DD73; Mon, 11 Nov 2019 14:44:59 +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 BBB985D9C9; Mon, 11 Nov 2019 14:44:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1573483523; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=ZKjYDIo+KGyEClqJI317b/hd7waZ6QhXFJJ/QIFmBq4=; b=Tzz6+QR0ym+KrbCcRRfFNUj7xx4bTlIkYqUBUDBNMx8BiLdpHS6r6W7vowMzwd1M0uEqxc od9ZQztR2tzKvDLcS4Rc79Su6KLdWHJ/MGGzYptXOhjdNoccLelfhB8x15P0NtnZ+tThjn jB1W9SdqtlMPTcHfWXTc7a7d48tDd/g= From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Mon, 11 Nov 2019 14:38:14 +0000 Message-Id: <20191111143826.16050-12-berrange@redhat.com> In-Reply-To: <20191111143826.16050-1-berrange@redhat.com> References: <20191111143826.16050-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v5 11/23] 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: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-MC-Unique: aGeTu-oVPEK8CRRLb0ijAQ-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" 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 Reviewed-by: J=C3=A1n Tomko Tested-by: Cole Robinson --- 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 7155ab6ce9..407a664626 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 55ad51abf1..62f1d55402 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -350,7 +350,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)/%, \ @@ -366,7 +366,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