diff mbox series

[v4,5/6] wic: extra-partitions: move extra-files WicError to do_prepare_partition

Message ID 20260115101432.162696-5-adam.duskett@amarulasolutions.com
State New
Headers show
Series [v4,1/6] wic: extra-partition: Small code cleanup | expand

Commit Message

Adam Duskett Jan. 15, 2026, 10:14 a.m. UTC
For organizational purposes, move the raised WicError if extra files isn't
provided by a user to the do_prepare_partition method and rewrite the message
to be more clear if a user wishes to create an empty partition.

The original error is changed to a warning in the event a user has a typo
in the variable. For example:

IMAGE_EXTRA_PARTITION_FILES_label-fooo = "bar.conf"
part --source extra-partition --fstype=ext4 --label foo

Signed-off-by: Adam Duskett <adam.duskett@amarulasolutions.com>
---
v1 -> v2: If the list is blank, print a warning instead of an info.
v2 -> v4: Raise an error in do_prepare_partition instead of making
          extra files optional. Extend error message.

 .../lib/wic/plugins/source/extra_partition.py | 26 ++++++++++++-------
 1 file changed, 17 insertions(+), 9 deletions(-)
diff mbox series

Patch

diff --git a/scripts/lib/wic/plugins/source/extra_partition.py b/scripts/lib/wic/plugins/source/extra_partition.py
index 25aab06c52..62a7b4b1d3 100644
--- a/scripts/lib/wic/plugins/source/extra_partition.py
+++ b/scripts/lib/wic/plugins/source/extra_partition.py
@@ -55,11 +55,13 @@  class ExtraPartitionPlugin(SourcePlugin):
         """
         Parse the files of which to copy.
         """
+        cls.extra_files_task = []
         deploy_files = []
 
         extra_files = cls._get_extra_vars(part, cls.image_extra_partition_files_var_name)
         if extra_files is None:
-            raise WicError('No extra files defined, %s unset for entry #%d' % (cls.image_extra_partition_files_var_name, part.lineno))
+            logger.warning('No extra files defined, %s unset for entry #%d' % (cls.image_extra_partition_files_var_name, part.lineno))
+            return
 
         logger.info('Extra files: %s', extra_files)
         for src_entry in re.findall(r'[\w;\-./*]+', extra_files):
@@ -73,7 +75,6 @@  class ExtraPartitionPlugin(SourcePlugin):
             logger.debug('Destination entry: %r', dst_entry)
             deploy_files.append(dst_entry)
 
-        cls.extra_files_task = []
         for deploy_entry in deploy_files:
             src, dst = deploy_entry
             if '*' in src:
@@ -125,18 +126,25 @@  class ExtraPartitionPlugin(SourcePlugin):
         """
         extradir = "%s/extra.%d" % (cr_workdir, part.lineno)
 
+        if not cls.extra_files_task:
+            raise WicError("Entry #%d does not have a corresponding %s variable set!"
+                           "If you wish to create an empty partition, remove "
+                           "--source extra-partition from the wks file"
+                           % (part.lineno, cls.image_extra_partition_dirs_var_name))
+
         if not kernel_dir:
             kernel_dir = get_bitbake_var("DEPLOY_DIR_IMAGE")
             if not kernel_dir:
                 raise WicError("Couldn't find DEPLOY_DIR_IMAGE, exiting")
 
-        for task in cls.extra_files_task:
-            src_path, dst_path = task
-            logger.debug('Install %s as %s', src_path, dst_path)
-            install_cmd = "install -m 0644 -D %s %s" \
-                          % (os.path.join(kernel_dir, src_path),
-                             os.path.join(extradir, dst_path))
-            exec_cmd(install_cmd)
+        if cls.extra_files_task:
+            for task in cls.extra_files_task:
+                src_path, dst_path = task
+                logger.debug('Install %s as %s', src_path, dst_path)
+                install_cmd = "install -m 0644 -D %s %s" \
+                              % (os.path.join(kernel_dir, src_path),
+                                 os.path.join(extradir, dst_path))
+                exec_cmd(install_cmd)
 
         logger.debug('Prepare extra partition using rootfs in %s', extradir)
         part.prepare_rootfs(cr_workdir, oe_builddir, extradir,