From nobody Sun Feb 8 12:37:33 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=1569337474; cv=none; d=zoho.com; s=zohoarc; b=OTwAYrDHM9rUKJBoDjsaPx8RK8GkZFGpFEPnbn5nAmBVYc+cUkqq2ABIy2T78fgQMSs9QhpgAt0mj6dJaxNudQDY18EyGeIienfWVb1CIAIL0Fqez48zymXcldGSulhhMWzrsJI6Q+ZPKSbJE2a0OVOMouZuaAlYWeGrTCOh4XU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1569337474; 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=sjt3HTbEA8kyWLrcMkiS9mWJLsTXySYqLVvQOKAxo8w=; b=B8XyuiY/7jD7ASbjRz0L5x7iXn4CAceVE8bWF4J991w8Cfjoa7fIrytr1trrK+7ZiSMFV7lDA4TIt4Rc/ss2FfvlrGnf1pv/LhN83NGTkFItwMRh60u3Sp5hG32kJLvYj+AQkw1hBOW1eWDYgkTYPbvfDBFk7GRmZio/zn3WJ5E= 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 1569337474683508.20128246169213; Tue, 24 Sep 2019 08:04:34 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id F35E030603AD; Tue, 24 Sep 2019 15:04:32 +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 C6DDF61559; Tue, 24 Sep 2019 15:04:32 +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 9168C4EE6A; Tue, 24 Sep 2019 15:04:32 +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 x8OF4CuT027859 for ; Tue, 24 Sep 2019 11:04:12 -0400 Received: by smtp.corp.redhat.com (Postfix) id 05A025D9E2; Tue, 24 Sep 2019 15:04:12 +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 6C0105D9D5; Tue, 24 Sep 2019 15:04:11 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Tue, 24 Sep 2019 15:58:47 +0100 Message-Id: <20190924145903.17123-7-berrange@redhat.com> In-Reply-To: <20190924145903.17123-1-berrange@redhat.com> References: <20190924145903.17123-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 v3 06/22] 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: , 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.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Tue, 24 Sep 2019 15:04:33 +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 | 89 ++++++++++++++++++++++++++++++++++++++ cfg.mk | 4 +- 4 files changed, 92 insertions(+), 78 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 03bf1beb78..db77da890c 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..53aeeb429c --- /dev/null +++ b/build-aux/mock-noinline.py @@ -0,0 +1,89 @@ +#!/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: + lineno =3D 0 + for line in fh: + lineno =3D lineno + 1 + + 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 d52d42c06c..b73d3ae1bf 100644 --- a/cfg.mk +++ b/cfg.mk @@ -1161,8 +1161,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)/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