From nobody Sat Feb 7 15:26:28 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=1567679276; cv=none; d=zoho.com; s=zohoarc; b=Vw3Ap3pZ/IsuIBf7u1E2WhJYFHpvtgwN6QqM8WCVU2G0y0r5o8CjiwvXYl0bOg/pTcTRVJBZtx33f7ZneNRPldoaMcYv6zQYxaU9cM8JaYzW67OIqbEBVqkljAo69ZS8IL4UhuQNtTLLOjOExIYbRBaF5W5imiu1na/XRhWi3Yc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1567679276; 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=oIgnQsG9SNWqY8lVmLit8WDp0DokvuYYqP5DQl4LeKU=; b=Uac+4l/NuKAURopXnlz2D17HYXs5Cd9y9yv/uzOVcg1BmTWmxsakPdBZz3wvsxI7d7v1huUOicxIk824GtaAx5vj3vruPfo1J5ZLEtgGcEqx2ID3zoiLWvAawSliWB7f5ppC5YMYStgETLivt/OHJwAFzH4Hs5FYDdKOlbeQe5Y= 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 1567679276744523.9029566866241; Thu, 5 Sep 2019 03:27:56 -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 9A30A30603AA; Thu, 5 Sep 2019 10:27:55 +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 7275F5D704; Thu, 5 Sep 2019 10:27:55 +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 3233A24F36; Thu, 5 Sep 2019 10:27:55 +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 x85AQd3J028002 for ; Thu, 5 Sep 2019 06:26:39 -0400 Received: by smtp.corp.redhat.com (Postfix) id 1A78B5DA60; Thu, 5 Sep 2019 10:26:39 +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 7CD165D9E2; Thu, 5 Sep 2019 10:26:38 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Thu, 5 Sep 2019 11:21:59 +0100 Message-Id: <20190905102206.18753-5-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 04/11] docs: rewrite symfile sorting 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]); Thu, 05 Sep 2019 10:27:56 +0000 (UTC) As part of an goal to eliminate Perl from libvirt build tools, rewrite the check-symsorting.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 --- src/Makefile.am | 6 +-- src/check-symsorting.pl | 106 ------------------------------------- src/check-symsorting.py | 112 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 115 insertions(+), 109 deletions(-) delete mode 100755 src/check-symsorting.pl create mode 100755 src/check-symsorting.py diff --git a/src/Makefile.am b/src/Makefile.am index 2eb4387231..f30b085d07 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -285,12 +285,12 @@ check-symfile: check-admin-symfile: endif ! WITH_LINUX check-symsorting: - $(AM_V_GEN)$(PERL) $(srcdir)/check-symsorting.pl \ + $(AM_V_GEN)$(PYTHON) $(srcdir)/check-symsorting.py \ $(srcdir) $(SYM_FILES) check-admin-symsorting: - $(AM_V_GEN)$(PERL) $(srcdir)/check-symsorting.pl \ + $(AM_V_GEN)$(PYTHON) $(srcdir)/check-symsorting.py \ $(srcdir) $(ADMIN_SYM_FILES) -EXTRA_DIST +=3D check-symfile.pl check-symsorting.pl +EXTRA_DIST +=3D check-symfile.pl check-symsorting.py =20 # Keep this list synced with RPC_PROBE_FILES PROTOCOL_STRUCTS =3D \ diff --git a/src/check-symsorting.pl b/src/check-symsorting.pl deleted file mode 100755 index 51e38bdedb..0000000000 --- a/src/check-symsorting.pl +++ /dev/null @@ -1,106 +0,0 @@ -#!/usr/bin/env perl - -# Copyright (C) 2012-2013 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 -# . - -use strict; -use warnings; - -die "syntax: $0 SRCDIR SYMFILE..." unless int(@ARGV) >=3D 2; - -my $ret =3D 0; -my $srcdir =3D shift; -my $lastgroup =3D undef; -foreach my $symfile (@ARGV) { - open SYMFILE, $symfile or die "cannot read $symfile: $!"; - - my $line =3D 0; - my $groupfile =3D ""; - my @group; - - while () { - chomp; - - if (/^#\s*((\w+\/)*(\w+\.h))\s*$/) { - $groupfile =3D $1; - } elsif (/^#/) { - # Ignore comments - } elsif (/^\s*$/) { - if (@group) { - &check_sorting(\@group, $symfile, $line, $groupfile); - } - @group =3D (); - $line =3D $.; - } else { - $_ =3D~ s/;//; - push @group, $_; - } - } - - close SYMFILE; - if (@group) { - &check_sorting(\@group, $symfile, $line, $groupfile); - } - $lastgroup =3D undef; -} - -sub check_sorting { - my $group =3D shift; - my $symfile =3D shift; - my $line =3D shift; - my $groupfile =3D shift; - - my @group =3D @{$group}; - my @sorted =3D sort { lc $a cmp lc $b } @group; - my $sorted =3D 1; - my $first; - my $last; - - # Check that groups are in order and groupfile exists - if (defined $lastgroup && lc $lastgroup ge lc $groupfile) { - print "Symbol block at $symfile:$line: block not sorted\n"; - print "Move $groupfile block before $lastgroup block\n"; - print "\n"; - $ret =3D 1; - } - if (! -e "$srcdir/$groupfile") { - print "Symbol block at $symfile:$line: $groupfile not found\n"; - print "\n"; - $ret =3D 1; - } - $lastgroup =3D $groupfile; - - # Check that symbols within a group are in order - for (my $i =3D 0 ; $i <=3D $#sorted ; $i++) { - if ($sorted[$i] ne $group[$i]) { - $first =3D $i unless defined $first; - $last =3D $i; - $sorted =3D 0; - } - } - if (!$sorted) { - @group =3D splice @group, $first, ($last-$first+1); - @sorted =3D splice @sorted, $first, ($last-$first+1); - print "Symbol block at $symfile:$line: symbols not sorted\n"; - print map { " " . $_ . "\n" } @group; - print "Correct ordering\n"; - print map { " " . $_ . "\n" } @sorted; - print "\n"; - $ret =3D 1; - } -} - -exit $ret; diff --git a/src/check-symsorting.py b/src/check-symsorting.py new file mode 100755 index 0000000000..a1d16a4c43 --- /dev/null +++ b/src/check-symsorting.py @@ -0,0 +1,112 @@ +#!/usr/bin/env python + +# Copyright (C) 2012-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 os.path +import re +import sys + +if len(sys.argv) < 3: + print("syntax: %s SRCDIR SYMFILE..." % sys.argv[0], file=3Dsys.stderr) + sys.exit(1) + +def check_sorting(group, symfile, line, groupfile, lastgroup): + sortedgroup =3D sorted(group, key=3Dstr.lower) + issorted =3D True + first =3D None + last =3D None + + err =3D False + # Check that groups are in order and groupfile exists + if lastgroup is not None and lastgroup.lower() > groupfile.lower(): + print("Symbol block at %s:%s: block not sorted" % (symfile, line),= file=3Dsys.stderr) + print("Move %s block before %s block" % (groupfile, lastgroup), fi= le=3Dsys.stderr) + print("", file=3Dsys.stderr) + err =3D True + + if not os.path.exists(os.path.join(srcdir, groupfile)): + print("Symbol block at %s:%s: %s not found" % (symfile, line, grou= pfile), file=3Dsys.stderr) + print("", file=3Dsys.stderr) + err =3D True + + # Check that symbols within a group are in order + for i in range(len(group)): + if sortedgroup[i] !=3D group[i]: + if first is None: + first =3D i + + last =3D i + issorted =3D False + + if not issorted: + actual =3D group[first:(last-first+1)] + expect =3D sortedgroup[first:(last-first+1)] + print("Symbol block at %s:%s: symbols not sorted" % (symfile, line= ), file=3Dsys.stderr) + for g in actual: + print(" %s" % g, file=3Dsys.stderr) + print("Correct ordering", file=3Dsys.stderr) + for g in expect: + print(" %s" % g, file=3Dsys.stderr) + print("", file=3Dsys.stderr) + err =3D True + + return err + + +ret =3D 0 +srcdir =3D sys.argv[1] +lastgroup =3D None +for symfile in sys.argv[2:]: + with open(symfile, "r") as fh: + lineno =3D 0 + groupfile =3D "" + group =3D [] + thisline =3D 0 + + filenameprog =3D re.compile(r'''^#\s*((\w+\/)*(\w+\.h))\s*$''') + + for line in fh: + thisline =3D thisline + 1 + line =3D line.strip() + + filenamematch =3D filenameprog.match(line) + if filenamematch is not None: + groupfile =3D filenamematch.group(1) + elif line =3D=3D "": + if len(group) > 0: + if check_sorting(group, symfile, lineno, groupfile, la= stgroup): + ret =3D 1 + + group =3D [] + lineno =3D thisline + lastgroup =3D groupfile + elif line[0] =3D=3D '#': + # Ignore comments + pass + else: + line =3D line.strip(";") + group.append(line) + + if len(group) > 0: + if check_sorting(group, symfile, lineno, groupfile, lastgroup): + ret =3D 1 + + lastgroup =3D None + +sys.exit(ret) --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list