diff mbox series

[2/2] diffconfig: add verification mode

Message ID 20250108-diffconfig-validate-v1-2-4b3d8ee489da@linutronix.de (mailing list archive)
State New
Headers show
Series diffconfig: add verification mode | expand

Commit Message

Thomas Weißschuh Jan. 8, 2025, 12:34 p.m. UTC
When creating kconfig files from defconfig files or snippets some items
from the reference config may be silently omitted when dependency
constraints are not met.
Manual validation is necessary to make sure that the expected items are
present in the new configuration. As the constraints can change over
time, this validation has to be repeated.
Extend the diffconfig script with a validation mode that can be used to
perform those validation easily and in an automated manner.

Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
---
 scripts/diffconfig | 23 ++++++++++++++++++-----
 1 file changed, 18 insertions(+), 5 deletions(-)

Comments

Nicolas Schier Jan. 15, 2025, 12:35 p.m. UTC | #1
On Wed 08 Jan 2025 13:34:29 GMT, Thomas Weißschuh wrote:
> When creating kconfig files from defconfig files or snippets some items
> from the reference config may be silently omitted when dependency
> constraints are not met.
> Manual validation is necessary to make sure that the expected items are
> present in the new configuration. As the constraints can change over
> time, this validation has to be repeated.
> Extend the diffconfig script with a validation mode that can be used to
> perform those validation easily and in an automated manner.
> 
> Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
> ---
>  scripts/diffconfig | 23 ++++++++++++++++++-----
>  1 file changed, 18 insertions(+), 5 deletions(-)
> 
> diff --git a/scripts/diffconfig b/scripts/diffconfig
> index 43f0f3d273ae7178086f03038780ba103fd9970b..95cb0282f6db2873ef32804d361ef6db8a7bc8ce 100755
> --- a/scripts/diffconfig
> +++ b/scripts/diffconfig
> @@ -24,6 +24,10 @@ Changed items show the old and new values on a single line.
>  If -m is specified, then output will be in "merge" style, which has the
>  changed and new values in kernel config option format.
>  
> +If -v is specified, then diffconfig will validate that config2 is a superset of
> +of config1. Only items from config1 not in config2 are printed.
> +If items are missing from config2 diffconfig will exit with code 2.
> +
>  If no config files are specified, .config and .config.old are used.
>  
>  Example usage:
> @@ -77,6 +81,11 @@ def show_diff():
>          merge_style = 1
>          sys.argv.remove("-m")
>  
> +    validate = 0
> +    if "-v" in sys.argv:
> +        validate = 1
> +        sys.argv.remove("-v")
> +
>      argc = len(sys.argv)
>      if not (argc==1 or argc == 3):
>          print("Error: incorrect number of arguments or unrecognized option")
> @@ -123,11 +132,15 @@ def show_diff():
>          print_config("->", config, a[config], b[config])
>          del b[config]

I think I'd move the early-exit for validate=1 here, and would leave the rest
as is.  But this is only personal preference.

Thanks for the nice idea!

Reviewed-by: Nicolas Schier <nicolas@fjasle.eu>

Kind regards,
Nicolas


>  
> -    # now print items in b but not in a
> -    # (items from b that were in a were removed above)
> -    new = sorted(b.keys())
> -    for config in new:
> -        print_config("+", config, None, b[config])
> +    if not validate:
> +        # now print items in b but not in a
> +        # (items from b that were in a were removed above)
> +        new = sorted(b.keys())
> +        for config in new:
> +            print_config("+", config, None, b[config])
> +
> +    if validate and (old or changed):
> +        sys.exit(2)

>  
>  def main():
>      try:
> 
> -- 
> 2.47.1
> 
>
diff mbox series

Patch

diff --git a/scripts/diffconfig b/scripts/diffconfig
index 43f0f3d273ae7178086f03038780ba103fd9970b..95cb0282f6db2873ef32804d361ef6db8a7bc8ce 100755
--- a/scripts/diffconfig
+++ b/scripts/diffconfig
@@ -24,6 +24,10 @@  Changed items show the old and new values on a single line.
 If -m is specified, then output will be in "merge" style, which has the
 changed and new values in kernel config option format.
 
+If -v is specified, then diffconfig will validate that config2 is a superset of
+of config1. Only items from config1 not in config2 are printed.
+If items are missing from config2 diffconfig will exit with code 2.
+
 If no config files are specified, .config and .config.old are used.
 
 Example usage:
@@ -77,6 +81,11 @@  def show_diff():
         merge_style = 1
         sys.argv.remove("-m")
 
+    validate = 0
+    if "-v" in sys.argv:
+        validate = 1
+        sys.argv.remove("-v")
+
     argc = len(sys.argv)
     if not (argc==1 or argc == 3):
         print("Error: incorrect number of arguments or unrecognized option")
@@ -123,11 +132,15 @@  def show_diff():
         print_config("->", config, a[config], b[config])
         del b[config]
 
-    # now print items in b but not in a
-    # (items from b that were in a were removed above)
-    new = sorted(b.keys())
-    for config in new:
-        print_config("+", config, None, b[config])
+    if not validate:
+        # now print items in b but not in a
+        # (items from b that were in a were removed above)
+        new = sorted(b.keys())
+        for config in new:
+            print_config("+", config, None, b[config])
+
+    if validate and (old or changed):
+        sys.exit(2)
 
 def main():
     try: