From patchwork Tue Nov 23 06:37:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Juerg Haefliger X-Patchwork-Id: 1558359 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=canonical.com header.i=@canonical.com header.a=rsa-sha256 header.s=20210705 header.b=q7pi6JKZ; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=) Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4HyvZh2PJ2z9sRK for ; Tue, 23 Nov 2021 17:37:30 +1100 (AEDT) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1mpPQX-00029p-Sl; Tue, 23 Nov 2021 06:37:13 +0000 Received: from smtp-relay-internal-0.internal ([10.131.114.225] helo=smtp-relay-internal-0.canonical.com) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1mpPQV-00029c-JX for kernel-team@lists.ubuntu.com; Tue, 23 Nov 2021 06:37:11 +0000 Received: from mail-ed1-f70.google.com (mail-ed1-f70.google.com [209.85.208.70]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-0.canonical.com (Postfix) with ESMTPS id 584443F19E for ; Tue, 23 Nov 2021 06:37:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1637649431; bh=IpSn0y2LFyrka1QYrTPbeUAEoFU2mEKOv2A2vd4sbQ0=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=q7pi6JKZZyLvKXNp5c5rfY+tzO+N59vWVd9CqYEBONvy/eXvrCVDVvcotaLr0Hz7q 5hXdoJ4YI6SDiVcwjZEakUaiUbFhxLNoHpRrn7HELt+OCTsqfqCgTTdH0Lmsu1jS3A Wen/eJ/Ui+nbVnhPoHP7YDSFDQY1Z7JgyzKqBo14ePx1IOAv2p3WmsO+H2qfeoOQ/N V+zA9xmSDaDj7pPqSKq5xOJfl/sioy2gOKjoKU4XMZM24GWTEemnTykv0SamIxGIHm aud4RMjKotMstI3I+aZOpmB+lIcGs4+PsO4Kia8eeVqOo7s+3+/N7oG531qgytSW7R zCQzjhF3UebSA== Received: by mail-ed1-f70.google.com with SMTP id v10-20020aa7d9ca000000b003e7bed57968so16904222eds.23 for ; Mon, 22 Nov 2021 22:37:11 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=IpSn0y2LFyrka1QYrTPbeUAEoFU2mEKOv2A2vd4sbQ0=; b=nuJf3RsmV/KKOQX4lJaJCpQbqKvTKnb7JCO23FwyI9cI44NC2Qsd3CiD+pTZh+2KOX AFyUNa0XoYNQvS1iqCCS9uqtIzXFED8aGXyLpc66CRaoLu3r7D8Lyk+K2UmSZXunDX7P L+9+j5/0asFNfP8C8+FeW5sbGvDAMiydoNDFMa6+64MEB19ioElV92dFu0n/X/HJ7F4P sfS8kqenxqTk96/q6MaQSQb7eocYQtzVnyEOOq4OeE8aitr8VOom01K7Af1GZivnGTR7 Lk8csIr9PbZ1kLbh+7xte6Un091DfHLFJ4/YdgWeOcQqneATgal241P4qQ3KbiPyzQES kuIA== X-Gm-Message-State: AOAM530FwBxfzA4uWfBZ50qin593vKi3zf7ganfe5K92xgJ9ZmT28Eop TOy9KoCesVB/kam+qtHWQShBNfNWqfxBaWuqGCnf0h55ZvOOM0M3cNmFYuPT0bKhXzbqve5/UJz Y5GfG8M+sn4/mMLpkmOSKWJ8m+lEvoM+SjiNRbOzbvQ== X-Received: by 2002:a17:906:54d:: with SMTP id k13mr4403473eja.545.1637649431008; Mon, 22 Nov 2021 22:37:11 -0800 (PST) X-Google-Smtp-Source: ABdhPJzpmJdILGMB2yolAoO4R1e76+ThMVTRmYsEfiMkPxVB4p1KUxMuXe5E6lDGxLhkVTQ7Ef6r6g== X-Received: by 2002:a17:906:54d:: with SMTP id k13mr4403440eja.545.1637649430762; Mon, 22 Nov 2021 22:37:10 -0800 (PST) Received: from gollum.fritz.box ([194.191.244.86]) by smtp.gmail.com with ESMTPSA id sc27sm4929886ejc.125.2021.11.22.22.37.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Nov 2021 22:37:10 -0800 (PST) From: Juerg Haefliger X-Google-Original-From: Juerg Haefliger To: kernel-team@lists.ubuntu.com Subject: [J][PATCH] UBUNTU: [Packaging] Rewrite debian/scripts/module-check in Python Date: Tue, 23 Nov 2021 07:37:09 +0100 Message-Id: <20211123063709.835425-1-juergh@canonical.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" Rewrite the module-check script in Python to get us one step closer to dropping Perl as an Ubuntu kernel build dependency. While at it, remove some of the rather 'interesting' comments printed to the console. Signed-off-by: Juerg Haefliger --- debian/rules.d/4-checks.mk | 2 +- debian/scripts/module-check | 190 +++++++++++++++++------------------- 2 files changed, 89 insertions(+), 103 deletions(-) diff --git a/debian/rules.d/4-checks.mk b/debian/rules.d/4-checks.mk index d513bc7aa481..d85de43adffc 100644 --- a/debian/rules.d/4-checks.mk +++ b/debian/rules.d/4-checks.mk @@ -7,7 +7,7 @@ abi-check-%: $(stampdir)/stamp-install-% # Check the module list against the last release (always) module-check-%: $(stampdir)/stamp-install-% @echo Debug: $@ - @perl -f $(DROOT)/scripts/module-check "$*" \ + $(DROOT)/scripts/module-check "$*" \ "$(prev_abidir)" "$(abidir)" $(skipmodule) # Check the reptoline jmp/call functions against the last release. diff --git a/debian/scripts/module-check b/debian/scripts/module-check index c754ea368cfb..ef616f23ca5a 100755 --- a/debian/scripts/module-check +++ b/debian/scripts/module-check @@ -1,120 +1,106 @@ -#!/usr/bin/perl -w +#!/usr/bin/python3 -$flavour = shift; -$prev_abidir = shift; -$abidir = shift; -$skipmodule = shift; +import os +import sys -print "II: Checking modules for $flavour..."; +if len(sys.argv) < 4 or len(sys.argv) > 5: + print('Usage: module-check []') + sys.exit(2) -if (-f "$prev_abidir/ignore.modules" - or -f "$prev_abidir/$flavour.ignore.modules") { - print "explicitly ignoring modules\n"; - exit(0); -} +flavor, prev_abidir, abidir = sys.argv[1:4] # pylint: disable=W0632 +if len(sys.argv) > 4: + skipmodule = sys.argv[4] +else: + skipmodule = '' -if (not -f "$abidir/$flavour.modules" or not -f - "$prev_abidir/$flavour.modules") { - print "previous or current modules file missing!\n"; - print " $abidir/$flavour.modules\n"; - print " $prev_abidir/$flavour.modules\n"; - if (defined($skipmodule)) { - exit(0); - } else { - exit(1); - } -} +print('II: Checking modules for {}...'.format(flavor), end='') -print "\n"; +if ((os.path.exists('{}/ignore.modules'.format(prev_abidir)) or + os.path.exists('{}/{}.ignore.modules'.format(prev_abidir, flavor)))): + print('explicitly ignoring modules') + sys.exit(0) -my %modules; -my %modules_ignore; -my $missing = 0; -my $new = 0; -my $errors = 0; +curr_modules = '{}/{}.modules'.format(abidir, flavor) +prev_modules = '{}/{}.modules'.format(prev_abidir, flavor) +if not os.path.exists(curr_modules) or not os.path.exists(prev_modules): + print('previous or current modules file missing!') + print(' {}'.format(curr_modules)) + print(' {}'.format(prev_modules)) + sys.exit(0 if skipmodule else 1) + +print() + +modules = {} +modules_ignore = {} +missing = 0 +new = 0 +errors = 0 # See if we have any ignores -if (-f "$prev_abidir/../modules.ignore") { - my $ignore = 0; - open(IGNORE, "< $prev_abidir/../modules.ignore") or - die "Could not open $prev_abidir/../modules.ignore"; - print " reading modules to ignore..."; - while () { - chomp; - next if /\s*#/; - $modules_ignore{$_} = 1; - $ignore++; - } - close(IGNORE); - print "read $ignore modules.\n"; -} +prev_modules_ignore = '{}/../modules.ignore'.format(prev_abidir) +if os.path.exists(prev_modules_ignore): + ignore = 0 + with open(prev_modules_ignore) as fh: + for mod in fh: + mod = mod.strip() + if mod.startswith('#'): + continue + modules_ignore[mod] = 1 + ignore += 1 + print('read {} modules.'.format(ignore)) # Read new modules first -print " reading new modules..."; -$new_count = 0; -open(NEW, "< $abidir/$flavour.modules") or - die "Could not open $abidir/$flavour.modules"; -while () { - chomp; - $modules{$_} = 1; - $new_count++; -} -close(NEW); -print "read $new_count modules.\n"; +print(' reading new modules...', end='') +new_count = 0 +with open(curr_modules) as fh: + for mod in fh: + mod = mod.strip() + modules[mod] = 1 + new_count += 1 +print('read {} modules.'.format(new_count)) # Now the old modules, checking for missing ones -print " reading old modules..."; -$old_count = 0; -open(OLD, "< $prev_abidir/$flavour.modules") or - die "Could not open $prev_abidir/$flavour.modules"; -while () { - chomp; - if (not defined($modules{$_})) { - print "\n" if not $missing; - $missing++; - if (not defined($modules_ignore{$_})) { - print " MISS: $_\n"; - $errors++; - } else { - print " MISS: $_ (ignored)\n"; - } - } else { - $modules{$_}++; - } - $old_count++; -} -close(OLD); +print(' reading old modules...', end='') +old_count = 0 +with open(prev_modules) as fh: + for mod in fh: + mod = mod.strip() + if mod not in modules: + if not missing: + print() + missing += 1 + if mod not in modules_ignore: + print(' MISS: {}'.format(mod)) + errors += 1 + else: + print(' MISS: {} (ignored)'.format(mod)) + else: + modules[mod] += 1 # Check for new modules -foreach $mod (keys(%modules)) { - if ($modules{$mod} < 2) { - print "\n" if not $missing and not $new; - print " NEW : $mod\n"; - $new++; - } -} -if ($new or $missing) { - print " read $old_count modules : new($new) missing($missing)\n"; -} else { - print "read $old_count modules.\n"; -} - +for mod, cnt in modules.items(): + if cnt < 2: + if not missing and not new: + print() + print(' NEW: {}'.format(mod)) + new += 1 +if new or missing: + print(' read {} modules : new({}) missing({})'.format(old_count, new, missing)) +else: + print('read {} modules.'.format(old_count)) # Let's see where we stand... -if ($errors) { - if (defined($skipmodule)) { - print "WW: Explicitly asked to ignore failures (probably not good)\n"; - } else { - print "EE: Missing modules (start begging for mercy)\n"; - exit 1 - } -} +if errors: + if skipmodule: + print('WW: Explicitly asked to ignore failures') + else: + print('EE: Missing modules') + sys.exit(1) -if ($new) { - print "II: New modules (you've been busy, wipe the poop off your nose)\n"; -} else { - print "II: No new modules (hope you're happy, slacker)\n"; -} +if new: + print('II: New modules') +else: + print('II: No new modules') -print "II: Done\n"; +print('II: Done') -exit(0); +sys.exit(0)