From nobody Sun Feb 8 11:25:57 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=1568219307; cv=none; d=zoho.com; s=zohoarc; b=SFrzBU6qsKw+dpoWJUIDRkHzne/sTO8+eOzmQcwh262hktz1sMF+viBL1NgJygZftdszu14FV6lrTbGn03GYFR6vNzkRd+jvfOplmDmSyvU+3tWK4LyCcwwlXIwA9lBLeayhJvCZq7l+JmG4to806qasrjYXg8S9lxLnBUnPHIE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1568219307; 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=clmj4PSkokxhvTeVZ+VV4tLYsoLsqAYujAjk3olPWkQ=; b=f5nNXYgNZ1uiwT1wLehptzLYcsxzGosDgMurJAxOu+5foFL08nws3fMb/d8OLO6rzN7hkONMXwm/T5qT5uqTfKTqAXj+nCB4eTaUo+QfQ7vlPqAD+MRr4gokBtJrluKWATWaW5PRahX2f4Dny+qDn4dfm9g9YreauZzU8h4VAAA= 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 1568219307643814.6725693757111; Wed, 11 Sep 2019 09:28:27 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C692F30821DF; Wed, 11 Sep 2019 16:28:25 +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 A0C4B19C77; Wed, 11 Sep 2019 16:28:25 +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 53308180BA9D; Wed, 11 Sep 2019 16:28:25 +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 x8BGSGTa013084 for ; Wed, 11 Sep 2019 12:28:16 -0400 Received: by smtp.corp.redhat.com (Postfix) id 3B0F16017E; Wed, 11 Sep 2019 16:28:16 +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 9F59860167; Wed, 11 Sep 2019 16:28:15 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Wed, 11 Sep 2019 17:23:15 +0100 Message-Id: <20190911162333.8668-7-berrange@redhat.com> In-Reply-To: <20190911162333.8668-1-berrange@redhat.com> References: <20190911162333.8668-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 v2 06/24] build-aux: rewrite duplicate header 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.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.47]); Wed, 11 Sep 2019 16:28:26 +0000 (UTC) As part of an goal to eliminate Perl from libvirt build tools, rewrite the prohibit-duplicate-header.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/prohibit-duplicate-header.pl | 26 ------------- build-aux/prohibit-duplicate-header.py | 54 ++++++++++++++++++++++++++ cfg.mk | 4 +- 4 files changed, 57 insertions(+), 29 deletions(-) delete mode 100644 build-aux/prohibit-duplicate-header.pl create mode 100644 build-aux/prohibit-duplicate-header.py diff --git a/Makefile.am b/Makefile.am index 8f688d40d0..a7d8da7146 100644 --- a/Makefile.am +++ b/Makefile.am @@ -47,7 +47,7 @@ EXTRA_DIST =3D \ build-aux/header-ifdef.pl \ build-aux/minimize-po.py \ build-aux/mock-noinline.pl \ - build-aux/prohibit-duplicate-header.pl \ + build-aux/prohibit-duplicate-header.py \ build-aux/useless-if-before-free \ build-aux/vc-list-files \ ci/Makefile \ diff --git a/build-aux/prohibit-duplicate-header.pl b/build-aux/prohibit-du= plicate-header.pl deleted file mode 100644 index 4a2ea65665..0000000000 --- a/build-aux/prohibit-duplicate-header.pl +++ /dev/null @@ -1,26 +0,0 @@ -#!/usr/bin/env perl - -use strict; - -my $file =3D " "; -my $ret =3D 0; -my %includes =3D ( ); -my $lineno =3D 0; - -while (<>) { - if (not $file eq $ARGV) { - %includes =3D ( ); - $file =3D $ARGV; - $lineno =3D 0; - } - $lineno++; - if (/^# *include *[<"]([^>"]*\.h)[">]/) { - $includes{$1}++; - if ($includes{$1} =3D=3D 2) { - $ret =3D 1; - print STDERR "$ARGV:$lineno: $_"; - print STDERR "Do not include a header more than once per file\= n"; - } - } -} -exit $ret; diff --git a/build-aux/prohibit-duplicate-header.py b/build-aux/prohibit-du= plicate-header.py new file mode 100644 index 0000000000..0ef86e8453 --- /dev/null +++ b/build-aux/prohibit-duplicate-header.py @@ -0,0 +1,54 @@ +#!/usr/bin/env python +# +# Copyright (C) 2016-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 check_file(filename): + includes =3D {} + lineno =3D 0 + errs =3D False + with open(filename, "r") as fh: + headerprog =3D re.compile(r'''^# *include *[<"]([^>"]*\.h)[">]\s*$= ''') + for line in fh: + lineno =3D lineno + 1 + + headermatch =3D headerprog.match(line) + if headermatch is not None: + inc =3D headermatch.group(1) + + if inc in includes: + print("%s:%d: %s" % (filename, lineno, inc), file=3Dsy= s.stderr) + errs =3D True + else: + includes[inc] =3D True + + return errs + +ret =3D 0 + +for filename in sys.argv[1:]: + if check_file(filename): + ret =3D 1 + +if ret =3D=3D 1: + print("Do not include a header more than once per file", file=3Dsys.st= derr) + +sys.exit(ret) diff --git a/cfg.mk b/cfg.mk index d09ab507e0..933857bc2f 100644 --- a/cfg.mk +++ b/cfg.mk @@ -1147,8 +1147,8 @@ endif =20 # Don't include duplicate header in the source (either *.c or *.h) prohibit-duplicate-header: - $(AM_V_GEN)$(VC_LIST_EXCEPT) | $(GREP) '\.[chx]$$' | xargs \ - $(PERL) -W $(top_srcdir)/build-aux/prohibit-duplicate-header.pl + $(AM_V_GEN)$(VC_LIST_EXCEPT) | $(GREP) '\.[chx]$$' | $(RUNUTF8) xargs \ + $(PYTHON) $(top_srcdir)/build-aux/prohibit-duplicate-header.py =20 spacing-check: $(AM_V_GEN)$(VC_LIST) | $(GREP) '\.c$$' | xargs \ --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list