Message ID | 20240525085023.6042-2-marcus.folkesson@gmail.com |
---|---|
State | Superseded |
Headers | show |
Series | image-bootfiles: new class | expand |
Hi Marcus, On 5/25/24 10:50 AM, Marcus Folkesson wrote: > Break out the code that parse IMAGE_BOOT_FILES to a common library. > > Signed-off-by: Marcus Folkesson <marcus.folkesson@gmail.com> > --- > meta/lib/oe/bootfiles.py | 56 +++++++++++++++++++ > .../wic/plugins/source/bootimg-partition.py | 39 +------------ > 2 files changed, 59 insertions(+), 36 deletions(-) > create mode 100644 meta/lib/oe/bootfiles.py > > diff --git a/meta/lib/oe/bootfiles.py b/meta/lib/oe/bootfiles.py > new file mode 100644 > index 0000000000..81e09f138e > --- /dev/null > +++ b/meta/lib/oe/bootfiles.py > @@ -0,0 +1,56 @@ > +# > +# SPDX-License-Identifier: MIT > +# > +# Copyright (C) 2024 Marcus Folkesson > +# Author: Marcus Folkesson <marcus.folkesson@gmail.com> > +# > +# Utility functions handling boot files > + > +# Look into deploy_dir and search for boot_files. > +# Returns a list with files to copy. > +# It returns a list of tuples with (original filepath relative to deploy_dir, desired filepath renaming) if I read the code properly, I think this is really important information. > +# Heavily inspired of bootimg-partition.py > +# > +def get_boot_files(deploy_dir, boot_files): > + import re > + import os > + from glob import glob > + > + if boot_files is None: > + return None > + > + # list of tuples (src_name, dst_name) > + deploy_files = [] > + for src_entry in re.findall(r'[\w;\-\./\*]+', boot_files): > + if ';' in src_entry: > + dst_entry = tuple(src_entry.split(';')) > + if not dst_entry[0] or not dst_entry[1]: > + raise ValueError('Malformed boot file entry: %s' % src_entry) > + else: > + dst_entry = (src_entry, src_entry) > + > + deploy_files.append(dst_entry) > + > + install_files = [] > + for deploy_entry in deploy_files: > + src, dst = deploy_entry > + if '*' in src: > + # by default install files under their basename > + entry_name_fn = os.path.basename > + if dst != src: > + # unless a target name was given, then treat name > + # as a directory and append a basename > + entry_name_fn = lambda name: \ > + os.path.join(dst, > + os.path.basename(name)) > + > + srcs = glob(os.path.join(deploy_dir, src)) > + > + for entry in srcs: > + src = os.path.relpath(entry, deploy_dir) > + entry_dst_name = entry_name_fn(entry) > + install_files.append((src, entry_dst_name)) > + else: > + install_files.append((src, dst)) > + > + return install_files > diff --git a/scripts/lib/wic/plugins/source/bootimg-partition.py b/scripts/lib/wic/plugins/source/bootimg-partition.py > index 1071d1af3f..b22a448b65 100644 > --- a/scripts/lib/wic/plugins/source/bootimg-partition.py > +++ b/scripts/lib/wic/plugins/source/bootimg-partition.py > @@ -18,6 +18,8 @@ import re > > from glob import glob > You should be able to remove this import as it was only used in the code that is now moved to the lib. Otherwise looks good to me, so Reviewed-by: Quentin Schulz <quentin.schulz@cherry.de> Thanks, Quentin
Hi Quentin, On Mon, May 27, 2024 at 05:20:53PM +0200, Quentin Schulz wrote: > Hi Marcus, [...] > > > --- /dev/null > > +++ b/meta/lib/oe/bootfiles.py > > @@ -0,0 +1,56 @@ > > +# > > +# SPDX-License-Identifier: MIT > > +# > > +# Copyright (C) 2024 Marcus Folkesson > > +# Author: Marcus Folkesson <marcus.folkesson@gmail.com> > > +# > > +# Utility functions handling boot files > > + > > +# Look into deploy_dir and search for boot_files. > > +# Returns a list with files to copy. > > +# > > It returns a list of tuples with (original filepath relative to deploy_dir, > desired filepath renaming) if I read the code properly, I think this is > really important information. Agree. I will add that to the comment. [...] > > from glob import glob > > You should be able to remove this import as it was only used in the code > that is now moved to the lib. True, I will remove the import. > > Otherwise looks good to me, so > > Reviewed-by: Quentin Schulz <quentin.schulz@cherry.de> > > Thanks, > Quentin Best regards, Marcus Folkesson
diff --git a/meta/lib/oe/bootfiles.py b/meta/lib/oe/bootfiles.py new file mode 100644 index 0000000000..81e09f138e --- /dev/null +++ b/meta/lib/oe/bootfiles.py @@ -0,0 +1,56 @@ +# +# SPDX-License-Identifier: MIT +# +# Copyright (C) 2024 Marcus Folkesson +# Author: Marcus Folkesson <marcus.folkesson@gmail.com> +# +# Utility functions handling boot files + +# Look into deploy_dir and search for boot_files. +# Returns a list with files to copy. +# +# Heavily inspired of bootimg-partition.py +# +def get_boot_files(deploy_dir, boot_files): + import re + import os + from glob import glob + + if boot_files is None: + return None + + # list of tuples (src_name, dst_name) + deploy_files = [] + for src_entry in re.findall(r'[\w;\-\./\*]+', boot_files): + if ';' in src_entry: + dst_entry = tuple(src_entry.split(';')) + if not dst_entry[0] or not dst_entry[1]: + raise ValueError('Malformed boot file entry: %s' % src_entry) + else: + dst_entry = (src_entry, src_entry) + + deploy_files.append(dst_entry) + + install_files = [] + for deploy_entry in deploy_files: + src, dst = deploy_entry + if '*' in src: + # by default install files under their basename + entry_name_fn = os.path.basename + if dst != src: + # unless a target name was given, then treat name + # as a directory and append a basename + entry_name_fn = lambda name: \ + os.path.join(dst, + os.path.basename(name)) + + srcs = glob(os.path.join(deploy_dir, src)) + + for entry in srcs: + src = os.path.relpath(entry, deploy_dir) + entry_dst_name = entry_name_fn(entry) + install_files.append((src, entry_dst_name)) + else: + install_files.append((src, dst)) + + return install_files diff --git a/scripts/lib/wic/plugins/source/bootimg-partition.py b/scripts/lib/wic/plugins/source/bootimg-partition.py index 1071d1af3f..b22a448b65 100644 --- a/scripts/lib/wic/plugins/source/bootimg-partition.py +++ b/scripts/lib/wic/plugins/source/bootimg-partition.py @@ -18,6 +18,8 @@ import re from glob import glob +from oe.bootfiles import get_boot_files + from wic import WicError from wic.engine import get_custom_config from wic.pluginbase import SourcePlugin @@ -66,42 +68,7 @@ class BootimgPartitionPlugin(SourcePlugin): logger.debug('Boot files: %s', boot_files) - # list of tuples (src_name, dst_name) - deploy_files = [] - for src_entry in re.findall(r'[\w;\-\./\*]+', boot_files): - if ';' in src_entry: - dst_entry = tuple(src_entry.split(';')) - if not dst_entry[0] or not dst_entry[1]: - raise WicError('Malformed boot file entry: %s' % src_entry) - else: - dst_entry = (src_entry, src_entry) - - logger.debug('Destination entry: %r', dst_entry) - deploy_files.append(dst_entry) - - cls.install_task = []; - for deploy_entry in deploy_files: - src, dst = deploy_entry - if '*' in src: - # by default install files under their basename - entry_name_fn = os.path.basename - if dst != src: - # unless a target name was given, then treat name - # as a directory and append a basename - entry_name_fn = lambda name: \ - os.path.join(dst, - os.path.basename(name)) - - srcs = glob(os.path.join(kernel_dir, src)) - - logger.debug('Globbed sources: %s', ', '.join(srcs)) - for entry in srcs: - src = os.path.relpath(entry, kernel_dir) - entry_dst_name = entry_name_fn(entry) - cls.install_task.append((src, entry_dst_name)) - else: - cls.install_task.append((src, dst)) - + cls.install_task = get_boot_files(kernel_dir, boot_files) if source_params.get('loader') != "u-boot": return
Break out the code that parse IMAGE_BOOT_FILES to a common library. Signed-off-by: Marcus Folkesson <marcus.folkesson@gmail.com> --- meta/lib/oe/bootfiles.py | 56 +++++++++++++++++++ .../wic/plugins/source/bootimg-partition.py | 39 +------------ 2 files changed, 59 insertions(+), 36 deletions(-) create mode 100644 meta/lib/oe/bootfiles.py