From nobody Tue Nov 26 13:41:48 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=1573483513; cv=none; d=zoho.com; s=zohoarc; b=Roin4Vu96BFZQ6o2q2QNlcspkUNwvmPTmwPSnA52Fl0iS6scaR81HVQubcUDJ2z5fykuM9MNV6DtGQFO0fbWqPEv8qrNhZpwUh8FRACb0+701uoBKN6QTt7ZoxuZeb3MriN0W98wVEXkT5eDZFsFN/XdTlQhClSkNHMOBvjNy1I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1573483513; 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=kLnn9mNoJfxDPFlpzjHIxDUpSMWix0qa1ih6HIVdVW0=; b=TYral9mslKqryRqw0OmBG7U3ZLmXGnYYvn21iBwzqhodiGnUYr8F28pTJxtJPQyKxaTn9Bdowh8c98144YkmYdy0CgOXT5o7rQWrcuVL480mr1x+r9I//bjodM+vZkMjVRwYAldXQtcfy2mnKk1djXCUbDq51KibJtigoICFJbE= 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-2.mimecast.com [207.211.31.81]) by mx.zohomail.com with SMTPS id 1573483513396806.7295225340433; Mon, 11 Nov 2019 06:45:13 -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-205-PiaXwbzMPj-3tlUeAz2XPA-1; Mon, 11 Nov 2019 09:45:08 -0500 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 2AC838A2423; Mon, 11 Nov 2019 14:44:59 +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 07B584B4; Mon, 11 Nov 2019 14:44:59 +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 C16CB18034EE; Mon, 11 Nov 2019 14:44:58 +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 xABEiqNE020351 for ; Mon, 11 Nov 2019 09:44:52 -0500 Received: by smtp.corp.redhat.com (Postfix) id 39C595DD73; Mon, 11 Nov 2019 14:44:52 +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 9CCC85D9C9; Mon, 11 Nov 2019 14:44:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1573483512; 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=kLnn9mNoJfxDPFlpzjHIxDUpSMWix0qa1ih6HIVdVW0=; b=B87qr1XNiceypzsishtGb25a4rVunoUvxP7mf/KGU6aKiJ0NBU+C9UbpYtvztpdELTzTgn YHJ0WZO7FvWNF7P/HkxWTpvFbhxhoE9GRHiRBj6t2tv7NYrUlbzSRRmsQt/owbJ125x14O oMYurel21+0swJFYxVrdApx45MKQMB0= From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Mon, 11 Nov 2019 14:38:06 +0000 Message-Id: <20191111143826.16050-4-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 03/23] build-aux: rewrite mock inline 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.79 on 10.5.11.16 X-MC-Unique: PiaXwbzMPj-3tlUeAz2XPA-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 mock-noinline.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 | 2 +- build-aux/mock-noinline.pl | 75 --------------------------------- build-aux/syntax-check.mk | 4 +- scripts/mock-noinline.py | 85 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 88 insertions(+), 78 deletions(-) delete mode 100644 build-aux/mock-noinline.pl create mode 100644 scripts/mock-noinline.py diff --git a/Makefile.am b/Makefile.am index 5187ca6cc2..d9369c9197 100644 --- a/Makefile.am +++ b/Makefile.am @@ -49,7 +49,7 @@ EXTRA_DIST =3D \ scripts/check-spacing.py \ build-aux/header-ifdef.pl \ scripts/minimize-po.py \ - build-aux/mock-noinline.pl \ + scripts/mock-noinline.py \ scripts/prohibit-duplicate-header.py \ build-aux/syntax-check.mk \ build-aux/useless-if-before-free \ diff --git a/build-aux/mock-noinline.pl b/build-aux/mock-noinline.pl deleted file mode 100644 index b005b8d95e..0000000000 --- a/build-aux/mock-noinline.pl +++ /dev/null @@ -1,75 +0,0 @@ -#!/usr/bin/env perl - -my %noninlined; -my %mocked; - -# Functions in public header don't get the noinline annotation -# so whitelist them here -$noninlined{"virEventAddTimeout"} =3D 1; -# This one confuses the script as its defined in the mock file -# but is actually just a local helper -$noninlined{"virMockStatRedirect"} =3D 1; - -foreach my $arg (@ARGV) { - if ($arg =3D~ /\.h$/) { - #print "Scan header $arg\n"; - &scan_annotations($arg); - } elsif ($arg =3D~ /mock\.c$/) { - #print "Scan mock $arg\n"; - &scan_overrides($arg); - } -} - -my $warned =3D 0; -foreach my $func (keys %mocked) { - next if exists $noninlined{$func}; - - $warned++; - print STDERR "$func is mocked at $mocked{$func} but missing noinline a= nnotation\n"; -} - -exit $warned ? 1 : 0; - - -sub scan_annotations { - my $file =3D shift; - - open FH, $file or die "cannot read $file: $!"; - - my $func; - while () { - if (/^\s*(\w+)\(/ || /^(?:\w+\*?\s+)+(?:\*\s*)?(\w+)\(/) { - my $name =3D $1; - if ($name !~ /(?:G_GNUC|ATTRIBUTE)/) { - $func =3D $name; - } - } elsif (/^\s*$/) { - $func =3D undef; - } - if (/G_GNUC_NO_INLINE/) { - if (defined $func) { - $noninlined{$func} =3D 1; - } - } - } - - close FH -} - -sub scan_overrides { - my $file =3D shift; - - open FH, $file or die "cannot read $file: $!"; - - my $func; - while () { - if (/^(\w+)\(/ || /^\w+\s*(?:\*\s*)?(\w+)\(/) { - my $name =3D $1; - if ($name =3D~ /^vir/) { - $mocked{$name} =3D "$file:$."; - } - } - } - - close FH -} diff --git a/build-aux/syntax-check.mk b/build-aux/syntax-check.mk index d308896b26..0cfd181224 100644 --- a/build-aux/syntax-check.mk +++ b/build-aux/syntax-check.mk @@ -2162,8 +2162,8 @@ spacing-check: { echo '$(ME): incorrect formatting' 1>&2; exit 1; } =20 mock-noinline: - $(AM_V_GEN)$(VC_LIST) | $(GREP) '\.[ch]$$' | xargs \ - $(PERL) $(top_srcdir)/build-aux/mock-noinline.pl + $(AM_V_GEN)$(VC_LIST) | $(GREP) '\.[ch]$$' | $(RUNUTF8) xargs \ + $(PYTHON) $(top_srcdir)/scripts/mock-noinline.py =20 header-ifdef: $(AM_V_GEN)$(VC_LIST) | $(GREP) '\.[h]$$' | xargs \ diff --git a/scripts/mock-noinline.py b/scripts/mock-noinline.py new file mode 100644 index 0000000000..2770ea1238 --- /dev/null +++ b/scripts/mock-noinline.py @@ -0,0 +1,85 @@ +#!/usr/bin/env python +# +# Copyright (C) 2017-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 + +noninlined =3D {} +mocked =3D {} + +# Functions in public header don't get the noinline annotation +# so whitelist them here +noninlined["virEventAddTimeout"] =3D True +# This one confuses the script as its defined in the mock file +# but is actually just a local helper +noninlined["virMockStatRedirect"] =3D True + + +def scan_annotations(filename): + with open(filename, "r") as fh: + func =3D None + for line in fh: + line =3D line.strip() + m =3D re.search(r'''^\s*(\w+)\(''', line) + if m is None: + m =3D re.search(r'''^(?:\w+\*?\s+)+(?:\*\s*)?(\w+)\(''', l= ine) + if m is not None: + name =3D m.group(1) + if name.find("ATTRIBUTE") =3D=3D -1 and name.find("G_GNUC_= ") =3D=3D -1: + func =3D name + elif line =3D=3D "": + func =3D None + + if line.find("G_GNUC_NO_INLINE") !=3D -1: + if func is not None: + noninlined[func] =3D True + + +def scan_overrides(filename): + with open(filename, "r") as fh: + lineno =3D 0 + for line in fh: + lineno =3D lineno + 1 + + m =3D re.search(r'''^(\w+)\(''', line) + if m is None: + m =3D re.search(r'''^\w+\s*(?:\*\s*)?(\w+)\(''', line) + if m is not None: + name =3D m.group(1) + if name.startswith("vir"): + mocked[name] =3D "%s:%d" % (filename, lineno) + + +for filename in sys.argv[1:]: + if filename.endswith(".h"): + scan_annotations(filename) + elif filename.endswith("mock.c"): + scan_overrides(filename) + +warned =3D False +for func in mocked.keys(): + if func not in noninlined: + warned =3D True + print("%s is mocked at %s but missing noinline annotation" % + (func, mocked[func]), file=3Dsys.stderr) + +if warned: + sys.exit(1) +sys.exit(0) --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list