[RFC,v2,2/3] utils: codegen: gen-formats: Support multiple fourcc headers
diff mbox series

Message ID 20261126091103.1843573-3-barnabas.pocze@ideasonboard.com
State New
Headers show
Series
  • include: linux: Split local changes
Related show

Commit Message

Barnabás Pőcze Nov. 26, 2026, 9:11 a.m. UTC
When the upstream and libcamera fourcc codes are split, the code generation
needs to take both into account. So add support for that.

Signed-off-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>
---
 utils/codegen/gen-formats.py | 41 ++++++++++++++++++------------------
 1 file changed, 21 insertions(+), 20 deletions(-)

Comments

Kieran Bingham Nov. 26, 2026, 9:48 a.m. UTC | #1
Quoting Barnabás Pőcze (2026-11-26 09:11:02)
> When the upstream and libcamera fourcc codes are split, the code generation
> needs to take both into account. So add support for that.
> 
> Signed-off-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>
> ---
>  utils/codegen/gen-formats.py | 41 ++++++++++++++++++------------------
>  1 file changed, 21 insertions(+), 20 deletions(-)
> 
> diff --git a/utils/codegen/gen-formats.py b/utils/codegen/gen-formats.py
> index 740790e8f1..a889063ff5 100755
> --- a/utils/codegen/gen-formats.py
> +++ b/utils/codegen/gen-formats.py
> @@ -19,29 +19,30 @@ class DRMFourCC(object):
>      mod_vendor_regex = re.compile(r"#define DRM_FORMAT_MOD_VENDOR_([A-Z0-9_]+)[ \t]+([0-9a-fA-Fx]+)")
>      mod_regex = re.compile(r"#define ([A-Za-z0-9_]+)[ \t]+fourcc_mod_code\(([A-Z0-9_]+), ([0-9a-fA-Fx]+)\)")
>  
> -    def __init__(self, file):
> +    def __init__(self, files):
>          self.formats = {}
>          self.vendors = {}
>          self.mods = {}
>  
> -        for line in file:
> -            match = DRMFourCC.format_regex.match(line)
> -            if match:
> -                format, fourcc = match.groups()
> -                self.formats[format] = fourcc
> -                continue
> -
> -            match = DRMFourCC.mod_vendor_regex.match(line)
> -            if match:
> -                vendor, value = match.groups()
> -                self.vendors[vendor] = int(value, 0)
> -                continue
> -
> -            match = DRMFourCC.mod_regex.match(line)
> -            if match:
> -                mod, vendor, value = match.groups()
> -                self.mods[mod] = (vendor, int(value, 0))
> -                continue
> +        for file in files:

Well that's an easy addition.

Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>

> +            for line in file:
> +                match = DRMFourCC.format_regex.match(line)
> +                if match:
> +                    format, fourcc = match.groups()
> +                    self.formats[format] = fourcc
> +                    continue
> +
> +                match = DRMFourCC.mod_vendor_regex.match(line)
> +                if match:
> +                    vendor, value = match.groups()
> +                    self.vendors[vendor] = int(value, 0)
> +                    continue
> +
> +                match = DRMFourCC.mod_regex.match(line)
> +                if match:
> +                    mod, vendor, value = match.groups()
> +                    self.mods[mod] = (vendor, int(value, 0))
> +                    continue
>  
>      def fourcc(self, name):
>          return self.formats[name]
> @@ -86,7 +87,7 @@ def main(argv):
>      parser.add_argument('template', type=argparse.FileType('r', encoding='utf-8'),
>                          help='Template file name.')
>      parser.add_argument('drm_fourcc', type=argparse.FileType('r', encoding='utf-8'),
> -                        help='Path to drm_fourcc.h.')
> +                        help='Path to drm_fourcc.h.', nargs='+')
>      args = parser.parse_args(argv[1:])
>  
>      formats = yaml.safe_load(args.input)['formats']
> -- 
> 2.56.1
>

Patch
diff mbox series

diff --git a/utils/codegen/gen-formats.py b/utils/codegen/gen-formats.py
index 740790e8f1..a889063ff5 100755
--- a/utils/codegen/gen-formats.py
+++ b/utils/codegen/gen-formats.py
@@ -19,29 +19,30 @@  class DRMFourCC(object):
     mod_vendor_regex = re.compile(r"#define DRM_FORMAT_MOD_VENDOR_([A-Z0-9_]+)[ \t]+([0-9a-fA-Fx]+)")
     mod_regex = re.compile(r"#define ([A-Za-z0-9_]+)[ \t]+fourcc_mod_code\(([A-Z0-9_]+), ([0-9a-fA-Fx]+)\)")
 
-    def __init__(self, file):
+    def __init__(self, files):
         self.formats = {}
         self.vendors = {}
         self.mods = {}
 
-        for line in file:
-            match = DRMFourCC.format_regex.match(line)
-            if match:
-                format, fourcc = match.groups()
-                self.formats[format] = fourcc
-                continue
-
-            match = DRMFourCC.mod_vendor_regex.match(line)
-            if match:
-                vendor, value = match.groups()
-                self.vendors[vendor] = int(value, 0)
-                continue
-
-            match = DRMFourCC.mod_regex.match(line)
-            if match:
-                mod, vendor, value = match.groups()
-                self.mods[mod] = (vendor, int(value, 0))
-                continue
+        for file in files:
+            for line in file:
+                match = DRMFourCC.format_regex.match(line)
+                if match:
+                    format, fourcc = match.groups()
+                    self.formats[format] = fourcc
+                    continue
+
+                match = DRMFourCC.mod_vendor_regex.match(line)
+                if match:
+                    vendor, value = match.groups()
+                    self.vendors[vendor] = int(value, 0)
+                    continue
+
+                match = DRMFourCC.mod_regex.match(line)
+                if match:
+                    mod, vendor, value = match.groups()
+                    self.mods[mod] = (vendor, int(value, 0))
+                    continue
 
     def fourcc(self, name):
         return self.formats[name]
@@ -86,7 +87,7 @@  def main(argv):
     parser.add_argument('template', type=argparse.FileType('r', encoding='utf-8'),
                         help='Template file name.')
     parser.add_argument('drm_fourcc', type=argparse.FileType('r', encoding='utf-8'),
-                        help='Path to drm_fourcc.h.')
+                        help='Path to drm_fourcc.h.', nargs='+')
     args = parser.parse_args(argv[1:])
 
     formats = yaml.safe_load(args.input)['formats']