From nobody Sun Feb 8 07:08:14 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=1567679288; cv=none; d=zoho.com; s=zohoarc; b=UG9VvXqLa98weq448/lXREk8OZNNosOQOR1oTLbwVFQ0ZPN7z+lV9myN3iw/FODQxU7h2oaz3JJj5ObZRA1dEtJZ9fnWGDtDHAgvl8Qe6a+eHIoLUwNBVYkPF9J3vb2REDuWG0DJvrKuruI3u/p2M/56Aj8GkZXiQ909VSpSFAc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1567679288; 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:ARC-Authentication-Results; bh=ry6JqGwRHlvHPtlykOqx1ub2sAmg4qHWVApOxfb0/Gw=; b=LXnVId6RCRwEKm2wnjcHgaiZNjWLazDNkYyar/1kZiHGZSNEGUMYPjSFP2tcqg0kNPEotT6SVU4MtVsrsR+gGJxvlr24K2jxAZbyJJjrsHcMAbHIipaA5aSWuwgEdEOAI6Ol2BHnUErXxqbcLPrI074Gnnec+Cpo9tVWglho/cQ= 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 1567679288337756.9644272388426; Thu, 5 Sep 2019 03:28:08 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C1E943175295; Thu, 5 Sep 2019 10:28:06 +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 94B556061E; Thu, 5 Sep 2019 10:28:06 +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 58F8424F36; Thu, 5 Sep 2019 10:28:06 +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 x85AQkjJ028067 for ; Thu, 5 Sep 2019 06:26:46 -0400 Received: by smtp.corp.redhat.com (Postfix) id CD9185DA21; Thu, 5 Sep 2019 10:26:46 +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 3B66B5D9E1; Thu, 5 Sep 2019 10:26:46 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Thu, 5 Sep 2019 11:22:05 +0100 Message-Id: <20190905102206.18753-11-berrange@redhat.com> In-Reply-To: <20190905102206.18753-1-berrange@redhat.com> References: <20190905102206.18753-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 10/11] docs: 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: , 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.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.49]); Thu, 05 Sep 2019 10:28:07 +0000 (UTC) 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 --- Makefile.am | 2 +- build-aux/mock-noinline.pl | 75 -------------------------------- build-aux/mock-noinline.py | 88 ++++++++++++++++++++++++++++++++++++++ cfg.mk | 2 +- 4 files changed, 90 insertions(+), 77 deletions(-) delete mode 100644 build-aux/mock-noinline.pl create mode 100644 build-aux/mock-noinline.py diff --git a/Makefile.am b/Makefile.am index d28c3ebcea..8bbc6e1747 100644 --- a/Makefile.am +++ b/Makefile.am @@ -46,7 +46,7 @@ EXTRA_DIST =3D \ build-aux/gitlog-to-changelog \ build-aux/header-ifdef.pl \ build-aux/minimize-po.py \ - build-aux/mock-noinline.pl \ + build-aux/mock-noinline.py \ build-aux/prohibit-duplicate-header.py \ build-aux/useless-if-before-free \ build-aux/vc-list-files \ diff --git a/build-aux/mock-noinline.pl b/build-aux/mock-noinline.pl deleted file mode 100644 index 958e133885..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 !~ /ATTRIBUTE/) { - $func =3D $name; - } - } elsif (/^\s*$/) { - $func =3D undef; - } - if (/ATTRIBUTE_NOINLINE/) { - 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/mock-noinline.py b/build-aux/mock-noinline.py new file mode 100644 index 0000000000..fdc60c5de9 --- /dev/null +++ b/build-aux/mock-noinline.py @@ -0,0 +1,88 @@ +#!/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): + funcprog1 =3D re.compile(r'''^\s*(\w+)\(.*''') + funcprog2 =3D re.compile(r'''^(?:\w+\*?\s+)+(?:\*\s*)?(\w+)\(.*''') + with open(filename, "r") as fh: + func =3D None + for line in fh: + line =3D line.strip() + m =3D funcprog1.match(line) + if m is None: + m =3D funcprog2.match(line) + if m is not None: + name =3D m.group(1) + if name.find("ATTRIBUTE") =3D=3D -1: + func =3D name + elif line =3D=3D "": + func =3D None + + if line.find("ATTRIBUTE_NOINLINE") !=3D -1: + if func is not None: + noninlined[func] =3D True + +def scan_overrides(filename): + funcprog1 =3D re.compile(r'''^(\w+)\(.*''') + funcprog2 =3D re.compile(r'''^\w+\s*(?:\*\s*)?(\w+)\(.*''') + with open(filename, "r") as fh: + func =3D None + lineno =3D 0 + for line in fh: + lineno =3D lineno + 1 + #line =3D line.strip() + + m =3D funcprog1.match(line) + if m is None: + m =3D funcprog2.match(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) diff --git a/cfg.mk b/cfg.mk index 02bade7f8a..732ee8084c 100644 --- a/cfg.mk +++ b/cfg.mk @@ -1157,7 +1157,7 @@ spacing-check: =20 mock-noinline: $(AM_V_GEN)$(VC_LIST) | $(GREP) '\.[ch]$$' | xargs \ - $(PERL) $(top_srcdir)/build-aux/mock-noinline.pl + $(PYTHON) $(top_srcdir)/build-aux/mock-noinline.py =20 header-ifdef: $(AM_V_GEN)$(VC_LIST) | $(GREP) '\.[h]$$' | xargs \ --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list