diff options
Diffstat (limited to 'meta/lib/oe/bootfiles.py')
-rw-r--r-- | meta/lib/oe/bootfiles.py | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/meta/lib/oe/bootfiles.py b/meta/lib/oe/bootfiles.py new file mode 100644 index 0000000000..7ee148c4e2 --- /dev/null +++ b/meta/lib/oe/bootfiles.py | |||
@@ -0,0 +1,57 @@ | |||
1 | # | ||
2 | # SPDX-License-Identifier: MIT | ||
3 | # | ||
4 | # Copyright (C) 2024 Marcus Folkesson | ||
5 | # Author: Marcus Folkesson <marcus.folkesson@gmail.com> | ||
6 | # | ||
7 | # Utility functions handling boot files | ||
8 | # | ||
9 | # Look into deploy_dir and search for boot_files. | ||
10 | # Returns a list of tuples with (original filepath relative to | ||
11 | # deploy_dir, desired filepath renaming) | ||
12 | # | ||
13 | # Heavily inspired of bootimg_partition.py | ||
14 | # | ||
15 | def get_boot_files(deploy_dir, boot_files): | ||
16 | import re | ||
17 | import os | ||
18 | from glob import glob | ||
19 | |||
20 | if boot_files is None: | ||
21 | return None | ||
22 | |||
23 | # list of tuples (src_name, dst_name) | ||
24 | deploy_files = [] | ||
25 | for src_entry in re.findall(r'[\w;\-\./\*]+', boot_files): | ||
26 | if ';' in src_entry: | ||
27 | dst_entry = tuple(src_entry.split(';')) | ||
28 | if not dst_entry[0] or not dst_entry[1]: | ||
29 | raise ValueError('Malformed boot file entry: %s' % src_entry) | ||
30 | else: | ||
31 | dst_entry = (src_entry, src_entry) | ||
32 | |||
33 | deploy_files.append(dst_entry) | ||
34 | |||
35 | install_files = [] | ||
36 | for deploy_entry in deploy_files: | ||
37 | src, dst = deploy_entry | ||
38 | if '*' in src: | ||
39 | # by default install files under their basename | ||
40 | entry_name_fn = os.path.basename | ||
41 | if dst != src: | ||
42 | # unless a target name was given, then treat name | ||
43 | # as a directory and append a basename | ||
44 | entry_name_fn = lambda name: \ | ||
45 | os.path.join(dst, | ||
46 | os.path.basename(name)) | ||
47 | |||
48 | srcs = glob(os.path.join(deploy_dir, src)) | ||
49 | |||
50 | for entry in srcs: | ||
51 | src = os.path.relpath(entry, deploy_dir) | ||
52 | entry_dst_name = entry_name_fn(entry) | ||
53 | install_files.append((src, entry_dst_name)) | ||
54 | else: | ||
55 | install_files.append((src, dst)) | ||
56 | |||
57 | return install_files | ||