diff mbox series

[Unstable/Lunar] UBUNTU: [Packaging] annotations: Check validity of FLAVOUR_DEP

Message ID 20230207100817.960389-1-juerg.haefliger@canonical.com
State New
Headers show
Series [Unstable/Lunar] UBUNTU: [Packaging] annotations: Check validity of FLAVOUR_DEP | expand

Commit Message

Juerg Haefliger Feb. 7, 2023, 10:08 a.m. UTC
FLAVOUR_DEP is used to map flavors from the main annotations file to
flavors from includes. Currently, there is no check that any of the
listed flavors exists or is valid so the resulting behavior is
(probably) undefined/unexpected. Add a sanity check to verify the
FLAVOUR_DEP flavors.

Signed-off-by: Juerg Haefliger <juerg.haefliger@canonical.com>
---
 debian/scripts/misc/kconfig/annotations.py | 21 +++++++++++++++++++--
 1 file changed, 19 insertions(+), 2 deletions(-)

Comments

Andrea Righi Feb. 8, 2023, 7:54 a.m. UTC | #1
On Tue, Feb 07, 2023 at 11:08:17AM +0100, Juerg Haefliger wrote:
> FLAVOUR_DEP is used to map flavors from the main annotations file to
> flavors from includes. Currently, there is no check that any of the
> listed flavors exists or is valid so the resulting behavior is
> (probably) undefined/unexpected. Add a sanity check to verify the
> FLAVOUR_DEP flavors.
> 
> Signed-off-by: Juerg Haefliger <juerg.haefliger@canonical.com>

Makes sense. Applied to lunar/linux and lunar/linux-unstable.

Thanks,
-Andrea

> ---
>  debian/scripts/misc/kconfig/annotations.py | 21 +++++++++++++++++++--
>  1 file changed, 19 insertions(+), 2 deletions(-)
> 
> diff --git a/debian/scripts/misc/kconfig/annotations.py b/debian/scripts/misc/kconfig/annotations.py
> index 113ce53eb4e0..1711257bd7ab 100644
> --- a/debian/scripts/misc/kconfig/annotations.py
> +++ b/debian/scripts/misc/kconfig/annotations.py
> @@ -57,8 +57,17 @@ class Annotation(Config):
>              line = re.sub(r' +', ' ', line)
>              line = line.strip()
>  
> -            # Ignore empty lines and comments
> -            if not line or line.startswith('#'):
> +            # Ignore empty lines
> +            if not line:
> +                continue
> +
> +            # Catpure flavors of included files
> +            if line.startswith('# FLAVOUR: '):
> +                self.include_flavour += line.split(' ')[2:]
> +                continue
> +
> +            # Ignore comments
> +            if line.startswith('#'):
>                  continue
>  
>              # Handle includes (recursively)
> @@ -112,6 +121,7 @@ class Annotation(Config):
>          self.flavour_dep = {}
>          self.include = []
>          self.header = ''
> +        self.include_flavour = []
>  
>          # Parse header (only main header will considered, headers in includes
>          # will be treated as comments)
> @@ -133,6 +143,13 @@ class Annotation(Config):
>          # Parse body (handle includes recursively)
>          self._parse_body(data)
>  
> +        # Sanity check: Verify that all FLAVOUR_DEP flavors are valid
> +        for src, tgt in self.flavour_dep.items():
> +            if src not in self.flavour:
> +                raise Exception(f'Invalid source flavour in FLAVOUR_DEP: {src}')
> +            if tgt not in self.include_flavour:
> +                raise Exception(f'Invalid target flavour in FLAVOUR_DEP: {tgt}')
> +
>      def _remove_entry(self, config: str):
>          if self.config[config]:
>              del self.config[config]
> -- 
> 2.34.1
> 
> 
> -- 
> kernel-team mailing list
> kernel-team@lists.ubuntu.com
> https://lists.ubuntu.com/mailman/listinfo/kernel-team
diff mbox series

Patch

diff --git a/debian/scripts/misc/kconfig/annotations.py b/debian/scripts/misc/kconfig/annotations.py
index 113ce53eb4e0..1711257bd7ab 100644
--- a/debian/scripts/misc/kconfig/annotations.py
+++ b/debian/scripts/misc/kconfig/annotations.py
@@ -57,8 +57,17 @@  class Annotation(Config):
             line = re.sub(r' +', ' ', line)
             line = line.strip()
 
-            # Ignore empty lines and comments
-            if not line or line.startswith('#'):
+            # Ignore empty lines
+            if not line:
+                continue
+
+            # Catpure flavors of included files
+            if line.startswith('# FLAVOUR: '):
+                self.include_flavour += line.split(' ')[2:]
+                continue
+
+            # Ignore comments
+            if line.startswith('#'):
                 continue
 
             # Handle includes (recursively)
@@ -112,6 +121,7 @@  class Annotation(Config):
         self.flavour_dep = {}
         self.include = []
         self.header = ''
+        self.include_flavour = []
 
         # Parse header (only main header will considered, headers in includes
         # will be treated as comments)
@@ -133,6 +143,13 @@  class Annotation(Config):
         # Parse body (handle includes recursively)
         self._parse_body(data)
 
+        # Sanity check: Verify that all FLAVOUR_DEP flavors are valid
+        for src, tgt in self.flavour_dep.items():
+            if src not in self.flavour:
+                raise Exception(f'Invalid source flavour in FLAVOUR_DEP: {src}')
+            if tgt not in self.include_flavour:
+                raise Exception(f'Invalid target flavour in FLAVOUR_DEP: {tgt}')
+
     def _remove_entry(self, config: str):
         if self.config[config]:
             del self.config[config]