annotations: check: catch options that are removed from the .config
authorAndrea Righi <andrea.righi@canonical.com>
Mon, 14 Nov 2022 22:09:07 +0000 (23:09 +0100)
committerAndrea Righi <andrea.righi@canonical.com>
Mon, 14 Nov 2022 22:09:07 +0000 (23:09 +0100)
Signed-off-by: Andrea Righi <andrea.righi@canonical.com>
annotations
kconfig/annotations.py

index 4e66a296172b6a16540c5197b24d7326d022a7b5..e5aac6f2c8e5dca7b3b62da99847d9c2b40228e3 100755 (executable)
@@ -76,30 +76,38 @@ def do_check(args):
     if args.arch is None:
         arg_fail('error: --arch is required with --check')
 
-    # Parse target .config
-    c = KConfig(args.check_file)
+    print(f"check-config: loading annotations from {args.file}")
+    total = good = ret = 0
 
     # Load annotations settings
     a = Annotation(args.file)
+    a_configs = a.search_config(arch=args.arch, flavour=args.flavour).keys()
+
+    # Parse target .config
+    c = KConfig(args.check_file)
+    c_configs = c.config.keys()
 
     # Validate .config against annotations
-    print(f"check-config: loading annotations from {args.file}")
-    total = good = ret = 0
-    for conf in c.config:
+    SKIP_CONFIGS = (
         # CONFIG_VERSION_SIGNATURE is dynamically set during the build
-        if conf == 'CONFIG_VERSION_SIGNATURE':
-            continue
+        'CONFIG_VERSION_SIGNATURE',
         # Allow to use a different version of gcc
-        if conf == 'CONFIG_CC_VERSION_TEXT':
+        'CONFIG_CC_VERSION_TEXT',
+    )
+    for conf in a_configs | c_configs:
+        if conf in SKIP_CONFIGS:
             continue
-        policy = a.config[conf] if conf in a.config else None
-        expected = a.search_config(config=conf, arch=args.arch, flavour=args.flavour)[conf]
-        if expected != c.config[conf]:
-            print(f"check-config: FAIL: ({c.config[conf]} != {expected}): {conf} {policy})")
+        entry = a.search_config(config=conf, arch=args.arch, flavour=args.flavour)
+        expected = entry[conf] if entry else '-'
+        value = c.config[conf] if conf in c.config else '-'
+        if value != expected:
+            policy = a.config[conf] if conf in a.config else 'undefined'
+            print(f"check-config: FAIL: ({value} != {expected}): {conf} {policy})")
             ret = 1
         else:
             good += 1
         total += 1
+
     print(f"check-config: {good}/{total} checks passed -- exit {ret}")
     exit(ret)
 
index c3eb457a16d164a696b72c0e403b2cc17bb5705b..699aed7fc9c301cdb198787570deb5e130186f7e 100644 (file)
@@ -219,11 +219,12 @@ class Annotation(Config):
             return self.config[config]
         elif config is not None and arch is not None:
             # Get a specific config option for a specific architecture
-            if 'policy' in self.config[config]:
-                if flavour in self.config[config]['policy']:
-                    return {config: self.config[config]['policy'][flavour]}
-                elif arch in self.config[config]['policy']:
-                    return {config: self.config[config]['policy'][arch]}
+            if config in self.config:
+                if 'policy' in self.config[config]:
+                    if flavour in self.config[config]['policy']:
+                        return {config: self.config[config]['policy'][flavour]}
+                    elif arch in self.config[config]['policy']:
+                        return {config: self.config[config]['policy'][arch]}
         return None
 
     @staticmethod