new file mode 100644
@@ -0,0 +1,81 @@
+# This class is meant to help in tracking recipe's dependencies
+# on certain Linux Kernel's compile time options, by making them
+# explicit.
+#
+# Usage.
+# 1. Inherit this class.
+# 2. If the Linux Kernel MUST have certain compile time options
+# enabled, add them to KERNEL_OPTIONS_REQUIRED variable.
+# Multiple options can be added, separated by whitespace.
+# If the kernel built with the image does not have these
+# options enabled, the build will fail.
+# 3. If some options are simply recommended, but not mandatory,
+# they can be added to KERNEL_OPTIONS_RECOMMENDED variable.
+# If the kernel built with the image does not have these
+# options enabled, warning will be produced, but the build
+# will succeed.
+# 4. If some options has alternatives, i.e. if only one of the
+# options has to be enabled to pass the check, separate
+# the alternatives with '|' with no spaces, like so:
+# DECOMPRESS_GZIP|DECOMPRESS_BZIP2
+
+
+KERNEL_OPTIONS_REQUIRED ??= ""
+KERNEL_OPTIONS_RECOMMENDED ??= ""
+
+def report_opt_warn(pn, opt):
+ if len(opt_alt_list) > 1:
+ bb.warn("%s recommends one of the following Linux Kernel"
+ " options to be enabled: %s"
+ % (pn, ",".join(opt_alt_list)))
+ else:
+ bb.warn("%s recommends Linux Kernel option %s to be enabled"
+ % (pn, opt_alt_list[0]))
+
+
+def report_opt_fatal(pn, opt_alt_list):
+ if len(opt_alt_list) > 1:
+ bb.fatal("%s requires one of the following Linux Kernel"
+ " options to be enabled: %s"
+ % (pn, ",".join(opt_alt_list)))
+ else:
+ bb.fatal("%s requires Linux Kernel option %s to be enabled"
+ % (pn, opt_alt_list[0]))
+
+
+def check_kernel_option(pn, opt_expr, opt_map, report_f):
+ alt_list = opt_expr.split("|")
+ alt_list_full = []
+ for opt in alt_list:
+ if not opt.startswith("CONFIG_"):
+ alt_list_full.append("CONFIG_" + opt)
+ else:
+ alt_list_full.append(opt)
+
+ if not any(opt_map.get(o) == "y" for o in alt_list_full):
+ report_f(pn, alt_list_full)
+
+
+python do_package:qa:append () {
+ kconfig_path = os.path.join(d.getVar("STAGING_KERNEL_BUILDDIR"), ".config")
+
+ kconfig_map = dict()
+ with open(kconfig_path, "r") as kconfig:
+ for line in kconfig:
+ if not line.startswith("CONFIG"):
+ continue
+
+ cfg_chunks = line.strip().split("=")
+ kconfig_map[cfg_chunks[0]] = cfg_chunks[1]
+
+ pn = d.getVar("PN")
+ for opt in d.getVar("KERNEL_OPTIONS_REQUIRED", "").split():
+ check_kernel_option(pn, opt, kconfig_map, report_opt_fatal)
+
+ for opt in d.getVar("KERNEL_OPTIONS_RECOMMENDED", "").split():
+ check_kernel_option(pn, opt, kconfig_map, report_opt_warn)
+}
+
+# do_shared_workdir moves kernel's .config to STAGING_KERNEL_BUILDDIR,
+# so it must complete before we can run the qa checks above.
+do_package:qa[depends] = "virtual/kernel:do_shared_workdir"