From nobody Sat Feb 7 22:06:46 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=1570621400; cv=none; d=zoho.com; s=zohoarc; b=TWovKNCy7KFUm7BLSoi5fwchyyANX7e3n5n+GdmeYXv6a8Ri+7g6JevBBBrSIfoaPIFy3+jc25HD46wrA7HcHwbkUlFhtAYL0YPGFLhw+mUgc8MA9zREfT5lmFPtx6kpI0JGIziIGJWWAFs30bvhoCl/fKpvpijU7tCHiVd3qtc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1570621400; 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=C7yCvCzlJ8yr6LwtgMnM8XQksGlHc+1dLkAgE2YklCQ=; b=nCBleHSp76Gz5i/j2FW8/adhpk8dvYqIpg5VAydCmJ4AxXN4abzzAsuXOQuL7E0+0rdeyZk3BAl+EA3CWyRXtkdyZ/XaUF+SWNE47dpPnC1/X5FZD2/R+Axcmnqc1VP99lPJm7CqJWbC77LwZM1bAsR+vjSV4UE88fnUH8vKuJc= 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 1570621400590393.97390736371597; Wed, 9 Oct 2019 04:43:20 -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 D5EB151F04; Wed, 9 Oct 2019 11:43:18 +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 AAA15F6F0; Wed, 9 Oct 2019 11:43:18 +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 6D65E4EA71; Wed, 9 Oct 2019 11:43:18 +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 x99BhA4c029981 for ; Wed, 9 Oct 2019 07:43:10 -0400 Received: by smtp.corp.redhat.com (Postfix) id D919C60167; Wed, 9 Oct 2019 11:43:10 +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 4CDD360497; Wed, 9 Oct 2019 11:43:10 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Wed, 9 Oct 2019 12:37:19 +0100 Message-Id: <20191009113741.5002-5-berrange@redhat.com> In-Reply-To: <20191009113741.5002-1-berrange@redhat.com> References: <20191009113741.5002-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 v4 04/26] 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.30]); Wed, 09 Oct 2019 11:43:19 +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 ------------ cfg.mk | 4 +- scripts/prohibit-duplicate-header.py | 56 ++++++++++++++++++++++++++ 4 files changed, 59 insertions(+), 29 deletions(-) delete mode 100644 build-aux/prohibit-duplicate-header.pl create mode 100644 scripts/prohibit-duplicate-header.py diff --git a/Makefile.am b/Makefile.am index 02506f2183..ce63966411 100644 --- a/Makefile.am +++ b/Makefile.am @@ -50,7 +50,7 @@ EXTRA_DIST =3D \ build-aux/header-ifdef.pl \ scripts/minimize-po.py \ build-aux/mock-noinline.pl \ - build-aux/prohibit-duplicate-header.pl \ + scripts/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/cfg.mk b/cfg.mk index 3eae469165..8ac6ac53d7 100644 --- a/cfg.mk +++ b/cfg.mk @@ -1152,8 +1152,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)/scripts/prohibit-duplicate-header.py =20 spacing-check: $(AM_V_GEN)$(VC_LIST) | $(GREP) '\.c$$' | xargs \ diff --git a/scripts/prohibit-duplicate-header.py b/scripts/prohibit-duplic= ate-header.py new file mode 100644 index 0000000000..dfdfa0bf0b --- /dev/null +++ b/scripts/prohibit-duplicate-header.py @@ -0,0 +1,56 @@ +#!/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: + for line in fh: + lineno =3D lineno + 1 + + headermatch =3D re.search(r'''^# *include *[<"]([^>"]*\.h)[">]= ''', line) + if headermatch is not None: + inc =3D headermatch.group(1) + + if inc in includes: + print("%s:%d: %s" % (filename, lineno, inc), + file=3Dsys.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) --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list