diff mbox series

[Unstable,3/4] UBUNTU: [Packaging] Clean up debian/scripts/module-check

Message ID 20221208071728.193067-4-juerg.haefliger@canonical.com
State New
Headers show
Series Rewrite abi-check in Python plus cleanups | expand

Commit Message

Juerg Haefliger Dec. 8, 2022, 7:17 a.m. UTC
Various cleanups to match the new abi-check script:
 - Comment header
 - Skipmodule argument parsing
 - Script output

Signed-off-by: Juerg Haefliger <juerg.haefliger@canonical.com>
---
 debian/scripts/module-check | 68 ++++++++++++++++++++++---------------
 1 file changed, 41 insertions(+), 27 deletions(-)
diff mbox series

Patch

diff --git a/debian/scripts/module-check b/debian/scripts/module-check
index 5c1f341d5313..dcad1b33b45f 100755
--- a/debian/scripts/module-check
+++ b/debian/scripts/module-check
@@ -1,4 +1,15 @@ 
 #!/usr/bin/python3
+#
+# Check modules changes
+#
+# To skip the modules check, add a file
+#   debian.<foo>/abi/<arch>/ignore.modules
+# or
+#   debian.<foo>/abi/<arch>/<flavor>.ignore.modules
+#
+# To ignore a list of modules, add the modules to the file
+#   debian.<foo>/abi/modules.ignore
+#
 
 import os
 import sys
@@ -9,37 +20,41 @@  if len(sys.argv) < 4 or len(sys.argv) > 5:
 
 flavor, prev_abidir, abidir = sys.argv[1:4]  # pylint: disable=W0632
 if len(sys.argv) > 4:
-    skipmodule = sys.argv[4]
+    skipmodule = sys.argv[4].lower() in ['1', 'true', 'yes']
 else:
-    skipmodule = ''
+    skipmodule = False
 
 print('II: Checking modules for {}...'.format(flavor), end='')
 
 if ((os.path.exists('{}/ignore.modules'.format(prev_abidir)) or
      os.path.exists('{}/{}.ignore.modules'.format(prev_abidir, flavor)))):
-    print('explicitly ignoring modules')
+    print('WW: Explicitly ignoring modules')
+    print('II: Done')
     sys.exit(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('II: Previous or current modules file missing!')
+    print('    {}'.format(curr_modules))
+    print('    {}'.format(prev_modules))
+    if skipmodule:
+        print('WW: Explicitly asked to ignore failures')
+        print('II: Done')
+        sys.exit(0)
+    print('EE: Missing modules file')
+    sys.exit(1)
 
 print()
 
 modules = {}
 modules_ignore = {}
-missing = 0
-new = 0
-errors = 0
 
 # See if we have any ignores
+print('    Reading modules to ignore...', end='')
+ignore = 0
 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()
@@ -47,10 +62,10 @@  if os.path.exists(prev_modules_ignore):
                 continue
             modules_ignore[mod] = 1
             ignore += 1
-    print('read {} modules.'.format(ignore))
+print('read {} modules.'.format(ignore))
 
 # Read new modules first
-print('   reading new modules...', end='')
+print('    Reading new modules...', end='')
 new_count = 0
 for f in (curr_modules, curr_modules + '.builtin'):
     if not os.path.exists(f):
@@ -63,7 +78,7 @@  for f in (curr_modules, curr_modules + '.builtin'):
 print('read {} modules.'.format(new_count))
 
 # Now the old modules
-print('   reading old modules...', end='')
+print('    Reading old modules...', end='')
 old_count = 0
 for f in (prev_modules, prev_modules + '.builtin'):
     if not os.path.exists(f):
@@ -78,6 +93,10 @@  for f in (prev_modules, prev_modules + '.builtin'):
 print('read {} modules.'.format(old_count))
 
 print('II: Checking for modules changes...')
+new = 0
+missing = 0
+missing_ignored = 0
+error = False
 for mod, vals in modules.items():
     # New modules
     if 'old' not in vals:
@@ -89,29 +108,24 @@  for mod, vals in modules.items():
         missing += 0
         if mod in modules_ignore:
             ignored = ' (ignored)'
+            missing_ignored += 1
         else:
             ignored = ''
-            errors += 1
+            error = True
         print('    MISS : {}{}'.format(mod, ignored))
 
-if new or missing:
-    print('      read {} modules : new({})  missing({})'.format(old_count, new, missing))
-else:
-    print('read {} modules.'.format(old_count))
+if new > 0:
+    print('II: {} new modules'.format(new))
+
+if missing > 0:
+    print('II: {} missing modules ({} ignored)'.format(missing, missing_ignored))
 
-# Let's see where we stand...
-if errors:
+if error:
     if skipmodule:
         print('WW: Explicitly asked to ignore failures')
     else:
         print('EE: Missing modules')
         sys.exit(1)
 
-if new:
-    print('II: New modules')
-else:
-    print('II: No new modules')
-
 print('II: Done')
-
 sys.exit(0)