From: "chris.larson via isar-users" <isar-users@googlegroups.com>
To: isar-users@googlegroups.com
Cc: Cedric Hombourger <cedric.hombourger@siemens.com>,
Christopher Larson <chris.larson@siemens.com>
Subject: [PATCH] features_check: add bbclass from oe-core 1a2afcd0
Date: Fri, 28 Mar 2025 13:25:32 -0700 [thread overview]
Message-ID: <20250328202532.15607-1-chris.larson@siemens.com> (raw)
From: Christopher Larson <chris.larson@siemens.com>
Allow checking of required and conflicting features.
xxx = [DISTRO,MACHINE,COMBINED,IMAGE,BSP,ROOTFS]
ANY_OF_xxx_FEATURES: ensure at least one item on this list is included
in xxx_FEATURES.
REQUIRED_xxx_FEATURES: ensure every item on this list is included
in xxx_FEATURES.
CONFLICT_xxx_FEATURES: ensure no item in this list is included in
xxx_FEATURES.
This allows one to easily specify that a given feature is required for a
recipe. By using this with the new features variables, we can ensure
that features are set correctly for a given recipe.
We can use simple checks like this:
REQUIRED_BSP_FEATURES += "some-bsp-feature"
In combination with inline python, we can implement behaviors and checks
like this:
# Enable the 'wayland' image feature if the machine feature is enabled.
IMAGE_FEATURES:append = " ${@bb.utils.filter('MACHINE_FEATURES', 'wayland', d)}"
# Require the 'wayland' machine feature when the image feature is enabled.
REQUIRED_MACHINE_FEATURES += "${@bb.utils.filter('IMAGE_FEATURES', 'wayland', d)}"
Signed-off-by: Christopher Larson <chris.larson@siemens.com>
---
meta/classes/features_check.bbclass | 57 +++++++++++++++++++++++++++++
1 file changed, 57 insertions(+)
create mode 100644 meta/classes/features_check.bbclass
diff --git a/meta/classes/features_check.bbclass b/meta/classes/features_check.bbclass
new file mode 100644
index 00000000..304501b0
--- /dev/null
+++ b/meta/classes/features_check.bbclass
@@ -0,0 +1,57 @@
+# Allow checking of required and conflicting features
+#
+# xxx = [DISTRO,MACHINE,COMBINED,IMAGE,BSP,ROOTFS]
+#
+# ANY_OF_xxx_FEATURES: ensure at least one item on this list is included
+# in xxx_FEATURES.
+# REQUIRED_xxx_FEATURES: ensure every item on this list is included
+# in xxx_FEATURES.
+# CONFLICT_xxx_FEATURES: ensure no item in this list is included in
+# xxx_FEATURES.
+#
+# Copyright 2019 (C) Texas Instruments Inc.
+# Copyright 2013 (C) O.S. Systems Software LTDA.
+#
+# SPDX-License-Identifier: MIT
+
+
+python () {
+ if bb.utils.to_boolean(d.getVar('PARSE_ALL_RECIPES', False)):
+ return
+
+ unused = True
+
+ for kind in ['DISTRO', 'MACHINE', 'COMBINED', 'IMAGE', 'BSP', 'ROOTFS']:
+ if d.getVar('ANY_OF_' + kind + '_FEATURES') is None and not d.hasOverrides('ANY_OF_' + kind + '_FEATURES') and \
+ d.getVar('REQUIRED_' + kind + '_FEATURES') is None and not d.hasOverrides('REQUIRED_' + kind + '_FEATURES') and \
+ d.getVar('CONFLICT_' + kind + '_FEATURES') is None and not d.hasOverrides('CONFLICT_' + kind + '_FEATURES'):
+ continue
+
+ unused = False
+
+ # Assume at least one var is set.
+ features = set((d.getVar(kind + '_FEATURES') or '').split())
+
+ any_of_features = set((d.getVar('ANY_OF_' + kind + '_FEATURES') or '').split())
+ if any_of_features:
+ if set.isdisjoint(any_of_features, features):
+ raise bb.parse.SkipRecipe("one of '%s' needs to be in %s_FEATURES"
+ % (' '.join(any_of_features), kind))
+
+ required_features = set((d.getVar('REQUIRED_' + kind + '_FEATURES') or '').split())
+ if required_features:
+ missing = set.difference(required_features, features)
+ if missing:
+ raise bb.parse.SkipRecipe("missing required %s feature%s '%s' (not in %s_FEATURES)"
+ % (kind.lower(), 's' if len(missing) > 1 else '', ' '.join(missing), kind))
+
+ conflict_features = set((d.getVar('CONFLICT_' + kind + '_FEATURES') or '').split())
+ if conflict_features:
+ conflicts = set.intersection(conflict_features, features)
+ if conflicts:
+ raise bb.parse.SkipRecipe("conflicting %s feature%s '%s' (in %s_FEATURES)"
+ % (kind.lower(), 's' if len(conflicts) > 1 else '', ' '.join(conflicts), kind))
+
+ if unused:
+ bb.warn("Recipe inherits features_check but doesn't use it")
+}
--
2.47.2
--
You received this message because you are subscribed to the Google Groups "isar-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to isar-users+unsubscribe@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/isar-users/20250328202532.15607-1-chris.larson%40siemens.com.
next reply other threads:[~2025-03-28 20:25 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-28 20:25 chris.larson via isar-users [this message]
2025-04-29 9:42 ` Anton Mikanovich
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250328202532.15607-1-chris.larson@siemens.com \
--to=isar-users@googlegroups.com \
--cc=cedric.hombourger@siemens.com \
--cc=chris.larson@siemens.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox