summaryrefslogtreecommitdiffstats
path: root/meta/classes-recipe/kernel-module-split.bbclass
diff options
context:
space:
mode:
Diffstat (limited to 'meta/classes-recipe/kernel-module-split.bbclass')
-rw-r--r--meta/classes-recipe/kernel-module-split.bbclass95
1 files changed, 76 insertions, 19 deletions
diff --git a/meta/classes-recipe/kernel-module-split.bbclass b/meta/classes-recipe/kernel-module-split.bbclass
index 9487365eb7..75ed696b72 100644
--- a/meta/classes-recipe/kernel-module-split.bbclass
+++ b/meta/classes-recipe/kernel-module-split.bbclass
@@ -86,11 +86,7 @@ python split_kernel_module_packages () {
86 vals[m.group(1)] = m.group(2) 86 vals[m.group(1)] = m.group(2)
87 return vals 87 return vals
88 88
89 def frob_metadata(file, pkg, pattern, format, basename): 89 def handle_conf_files(d, basename, pkg):
90 vals = extract_modinfo(file)
91
92 dvar = d.getVar('PKGD')
93
94 # If autoloading is requested, output ${modulesloaddir}/<name>.conf and append 90 # If autoloading is requested, output ${modulesloaddir}/<name>.conf and append
95 # appropriate modprobe commands to the postinst 91 # appropriate modprobe commands to the postinst
96 autoloadlist = (d.getVar("KERNEL_MODULE_AUTOLOAD") or "").split() 92 autoloadlist = (d.getVar("KERNEL_MODULE_AUTOLOAD") or "").split()
@@ -99,9 +95,12 @@ python split_kernel_module_packages () {
99 bb.warn("module_autoload_%s was replaced by KERNEL_MODULE_AUTOLOAD for cases where basename == module name, please drop it" % basename) 95 bb.warn("module_autoload_%s was replaced by KERNEL_MODULE_AUTOLOAD for cases where basename == module name, please drop it" % basename)
100 if autoload and basename not in autoloadlist: 96 if autoload and basename not in autoloadlist:
101 bb.warn("module_autoload_%s is defined but '%s' isn't included in KERNEL_MODULE_AUTOLOAD, please add it there" % (basename, basename)) 97 bb.warn("module_autoload_%s is defined but '%s' isn't included in KERNEL_MODULE_AUTOLOAD, please add it there" % (basename, basename))
98
99 # The .conf file can either be installed by a recipe or generated from module_autoload_*
100 conf = '%s/%s.conf' % (d.getVar('modulesloaddir'), basename)
101 name = '%s%s' % (d.getVar('PKGD'), conf)
102 # If module name is in KERNEL_MODULE_AUTOLOAD, then generate the .conf file and write to `name`.
102 if basename in autoloadlist: 103 if basename in autoloadlist:
103 conf = '%s/%s.conf' % (d.getVar('modulesloaddir'), basename)
104 name = '%s%s' % (dvar, conf)
105 os.makedirs(os.path.dirname(name), exist_ok=True) 104 os.makedirs(os.path.dirname(name), exist_ok=True)
106 with open(name, 'w') as f: 105 with open(name, 'w') as f:
107 if autoload: 106 if autoload:
@@ -109,30 +108,87 @@ python split_kernel_module_packages () {
109 f.write('%s\n' % m) 108 f.write('%s\n' % m)
110 else: 109 else:
111 f.write('%s\n' % basename) 110 f.write('%s\n' % basename)
111 # If the .conf file exits, then add it to FILES:* and CONFFILES:* and add postinstall hook.
112 # It doesn't matter if it was generated from module_autoload_* or installed by the recipe.
113 if os.path.exists(name):
112 conf2append = ' %s' % conf 114 conf2append = ' %s' % conf
113 d.appendVar('FILES:%s' % pkg, conf2append) 115 d.appendVar('FILES:%s' % pkg, conf2append)
114 d.appendVar('CONFFILES:%s' % pkg, conf2append) 116 d.appendVar('CONFFILES:%s' % pkg, conf2append)
115 postinst = d.getVar('pkg_postinst:%s' % pkg) 117 postinst = d.getVar('pkg_postinst:%s' % pkg)
116 if not postinst: 118 if not postinst:
117 bb.fatal("pkg_postinst:%s not defined" % pkg) 119 postinst = d.getVar('pkg_postinst:modules')
118 postinst += d.getVar('autoload_postinst_fragment') % (autoload or basename) 120 postinst += d.getVar('autoload_postinst_fragment') % (autoload or basename)
119 d.setVar('pkg_postinst:%s' % pkg, postinst) 121 d.setVar('pkg_postinst:%s' % pkg, postinst)
120 122
121 # Write out any modconf fragment 123 # Write out any modconf fragment
122 modconflist = (d.getVar("KERNEL_MODULE_PROBECONF") or "").split() 124 modconflist = (d.getVar("KERNEL_MODULE_PROBECONF") or "").split()
123 modconf = d.getVar('module_conf_%s' % basename) 125 modconf = d.getVar('module_conf_%s' % basename)
126
127 # The .conf file can either be installed by a recipe or generated from module_conf_*
128 conf = '%s/%s.conf' % (d.getVar('modprobedir'), basename)
129 name = '%s%s' % (d.getVar('PKGD'), conf)
130 # If module name is in KERNEL_MODULE_PROBECONF, then generate the .conf file and write to `name`.
124 if modconf and basename in modconflist: 131 if modconf and basename in modconflist:
125 conf = '%s/%s.conf' % (d.getVar('modprobedir'), basename)
126 name = '%s%s' % (dvar, conf)
127 os.makedirs(os.path.dirname(name), exist_ok=True) 132 os.makedirs(os.path.dirname(name), exist_ok=True)
128 with open(name, 'w') as f: 133 with open(name, 'w') as f:
129 f.write("%s\n" % modconf) 134 f.write("%s\n" % modconf)
135 elif modconf:
136 bb.error("Please ensure module %s is listed in KERNEL_MODULE_PROBECONF since module_conf_%s is set" % (basename, basename))
137 # If the .conf file exits, then add it to FILES:* and CONFFILES:*.
138 # It doesn't matter if it was generated from module_conf_* or installed by the recipe.
139 if os.path.exists(name):
130 conf2append = ' %s' % conf 140 conf2append = ' %s' % conf
131 d.appendVar('FILES:%s' % pkg, conf2append) 141 d.appendVar('FILES:%s' % pkg, conf2append)
132 d.appendVar('CONFFILES:%s' % pkg, conf2append) 142 d.appendVar('CONFFILES:%s' % pkg, conf2append)
133 143
134 elif modconf: 144 def generate_conf_files(d, root, file_regex, output_pattern):
135 bb.error("Please ensure module %s is listed in KERNEL_MODULE_PROBECONF since module_conf_%s is set" % (basename, basename)) 145 """
146 Arguments:
147 root -- the path in which to search. Contains system lib path
148 so needs expansion.
149 file_regex -- regular expression to match searched files. Use
150 parentheses () to mark the part of this expression
151 that should be used to derive the module name (to be
152 substituted where %s is used in other function
153 arguments as noted below)
154 output_pattern -- pattern to use for the package names. Must include %s.
155 """
156 import re, stat
157
158 dvar = d.getVar('PKGD')
159 root = d.expand(root)
160
161 # if the root directory doesn't exist, it's fatal - exit from the current execution.
162 if not os.path.exists(dvar + root):
163 bb.fatal("kernel module root directory path does not exist")
164
165 # walk through kernel module directory. for each entry in the directory, check if it
166 # matches the desired regex pattern and file type. if it fullfills, process it to generate
167 # it's conf file based on its package name.
168 for walkroot, dirs, files in os.walk(dvar + root):
169 for file in files:
170 relpath = os.path.join(walkroot, file).replace(dvar + root + '/', '', 1)
171 if not relpath:
172 continue
173 m = re.match(file_regex, os.path.basename(relpath))
174 if not m:
175 continue
176 file_f = os.path.join(dvar + root, relpath)
177 mode = os.lstat(file_f).st_mode
178 if not (stat.S_ISREG(mode) or (allow_links and stat.S_ISLNK(mode)) or (allow_dirs and stat.S_ISDIR(mode))):
179 continue
180
181 basename = m.group(1)
182 on = legitimize_package_name(basename)
183 pkg = output_pattern % on
184 handle_conf_files(d, basename, pkg)
185
186
187 def frob_metadata(file, pkg, pattern, format, basename):
188 vals = extract_modinfo(file)
189 dvar = d.getVar('PKGD')
190
191 handle_conf_files(d, basename, pkg)
136 192
137 if "description" in vals: 193 if "description" in vals:
138 old_desc = d.getVar('DESCRIPTION:' + pkg) or "" 194 old_desc = d.getVar('DESCRIPTION:' + pkg) or ""
@@ -167,19 +223,20 @@ python split_kernel_module_packages () {
167 postinst = d.getVar('pkg_postinst:modules') 223 postinst = d.getVar('pkg_postinst:modules')
168 postrm = d.getVar('pkg_postrm:modules') 224 postrm = d.getVar('pkg_postrm:modules')
169 225
170 if splitmods != '1':
171 d.appendVar('FILES:' + metapkg, '%s %s %s/modules' %
172 (d.getVar('modulesloaddir'), d.getVar('modprobedir'), d.getVar("nonarch_base_libdir")))
173 d.appendVar('pkg_postinst:%s' % metapkg, postinst)
174 d.prependVar('pkg_postrm:%s' % metapkg, postrm);
175 return
176
177 module_regex = r'^(.*)\.k?o(?:\.(gz|xz|zst))?$' 226 module_regex = r'^(.*)\.k?o(?:\.(gz|xz|zst))?$'
178 227
179 module_pattern_prefix = d.getVar('KERNEL_MODULE_PACKAGE_PREFIX') 228 module_pattern_prefix = d.getVar('KERNEL_MODULE_PACKAGE_PREFIX')
180 module_pattern_suffix = d.getVar('KERNEL_MODULE_PACKAGE_SUFFIX') 229 module_pattern_suffix = d.getVar('KERNEL_MODULE_PACKAGE_SUFFIX')
181 module_pattern = module_pattern_prefix + kernel_package_name + '-module-%s' + module_pattern_suffix 230 module_pattern = module_pattern_prefix + kernel_package_name + '-module-%s' + module_pattern_suffix
182 231
232 if splitmods != '1':
233 d.appendVar('FILES:' + metapkg, '%s %s %s/modules' %
234 (d.getVar('modulesloaddir'), d.getVar('modprobedir'), d.getVar("nonarch_base_libdir")))
235 d.appendVar('pkg_postinst:%s' % metapkg, postinst)
236 d.prependVar('pkg_postrm:%s' % metapkg, postrm)
237 generate_conf_files(d, root='${nonarch_base_libdir}/modules', file_regex=module_regex, output_pattern=module_pattern)
238 return
239
183 modules = do_split_packages(d, root='${nonarch_base_libdir}/modules', file_regex=module_regex, output_pattern=module_pattern, description='%s kernel module', postinst=postinst, postrm=postrm, recursive=True, hook=frob_metadata, extra_depends='%s-%s' % (kernel_package_name, kernel_version)) 240 modules = do_split_packages(d, root='${nonarch_base_libdir}/modules', file_regex=module_regex, output_pattern=module_pattern, description='%s kernel module', postinst=postinst, postrm=postrm, recursive=True, hook=frob_metadata, extra_depends='%s-%s' % (kernel_package_name, kernel_version))
184 if modules: 241 if modules:
185 d.appendVar('RDEPENDS:' + metapkg, ' '+' '.join(modules)) 242 d.appendVar('RDEPENDS:' + metapkg, ' '+' '.join(modules))