From patchwork Mon Dec 16 20:16:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "chris.larson" X-Patchwork-Id: 3986 Return-Path: Received: from shymkent.ilbers.de ([unix socket]) by shymkent (Cyrus 2.5.10-Debian-2.5.10-3+deb9u2) with LMTPA; Mon, 16 Dec 2024 21:16:44 +0100 X-Sieve: CMU Sieve 2.4 Received: from mail-pg1-f186.google.com (mail-pg1-f186.google.com [209.85.215.186]) by shymkent.ilbers.de (8.15.2/8.15.2/Debian-8+deb9u1) with ESMTPS id 4BGKGfP5027015 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Mon, 16 Dec 2024 21:16:43 +0100 Received: by mail-pg1-f186.google.com with SMTP id 41be03b00d2f7-7fd5777a6aasf3243427a12.0 for ; Mon, 16 Dec 2024 12:16:43 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1734380196; cv=pass; d=google.com; s=arc-20240605; b=j9vjdkLqH0ljVeZqZWbzM2Pk5ozyDoHElRjcHVn5Ugws0mGD5TAsiHsnkOxX9f8/V8 nxPxsWd8mKkPJopi5ONGC+bCIbTEwdQAQUyboJH1jK2zQ7k9n2QOVdNCywGm9Xh+DHDM K897MBSIuujWfz5oPV6r+ahlyyDUdT1GJkjehbmlsLW/kXAEj7oLId5EBRNOSibgOzDr XI3Ul+iOsqcmneCpVgDRpDs6sDE+R9czaKP/kFPttHh1TOGE9xFhmDwZg34jjQL7MudV 6UIckV4CEC8k4hK0sbuH7SG/wqiZzOMDeWcpi65/YIYsffMQfC1jjAMLMFvE0oeaBhDC J3Xg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post :list-id:mailing-list:precedence:reply-to:feedback-id:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=qpOzt7gB2Tu+3ntA7Hjx6iYpMTYMt0/lKnrx4+F7J1w=; fh=v33+/34iqneMa8zYNZemNgC9pQfN82Mx+mGoDL9p0t8=; b=kXNmFBhE/rKWK/7G8YhthxEjx8AaY8o5+tsNbhtx+vOTaVZMXAXV3Rnf6XpO4ucCMD Zbrw6KaAF8byASrvkfoZQUCIO4vYWtXVuJdXNwiJLZV7rmsjtSd0mCXXzGDW66oxkMfe YsW7jIMApmSQJ0FbEvf3ol0uOGVb+C7JXZOICQubnwpb5/MUwcNunMgBAT+vUWMntVM9 zezyIe0G7EyPoGuJwSNrSYzrgcfkeklHbr0Eyg7e5pKCERe5H7LDPCL5ZKxXddvSq00y lx0rhXlMFnJbiQmdJNEL0ia+tV5as14HgY30cCQUCvOGIveKPPy+U67KULP5D8fkZUgB tWbA==; darn=isar-build.org ARC-Authentication-Results: i=2; gmr-mx.google.com; dkim=pass header.i=@siemens.com header.s=fm2 header.b=PqOqOFWt; spf=pass (google.com: domain of fm-1325773-202412162016327a143311339a96d68f-vbpd9o@rts-flowmailer.siemens.com designates 185.136.65.228 as permitted sender) smtp.mailfrom=fm-1325773-202412162016327a143311339a96d68f-vbpD9O@rts-flowmailer.siemens.com; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=siemens.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20230601; t=1734380196; x=1734984996; darn=isar-build.org; h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post :list-id:mailing-list:precedence:reply-to :x-original-authentication-results:x-original-sender:feedback-id :mime-version:message-id:date:subject:cc:to:from:from:to:cc:subject :date:message-id:reply-to; bh=qpOzt7gB2Tu+3ntA7Hjx6iYpMTYMt0/lKnrx4+F7J1w=; b=MIo/HFnHxzCbHnoW8OYOJ8jEsSfcqlys0z+BJPOgfQREZqz+bEAMjPrN3/AbuXdpls 9kmvq9S2uBJ1byzzeI1PTV2M2QCLr3aaQcHOZFJFgKvdV73ZqvYXx7ar5XRCOV1tYMDO 4Q2jYlTiMLnwbNn+RECZz5QA2kNGjEyya3r9NqZ90ipjm0p4G0LZ1FxI8bPe+Fjc4hCZ UZJMm6Z7bB+PXNaLRvA0bIUnUvEyvXZDIkd7MsBOtkMCgvOXJGb2TQiM7hzubQS117O3 wmGWEn0ygWf8moNk48EeODpJiELsqc/sHjTbNCl32H9rKVSF21n9nXlQYstAnaenwQKP mKSg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734380196; x=1734984996; h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post :x-spam-checked-in-group:list-id:mailing-list:precedence:reply-to :x-original-authentication-results:x-original-sender:feedback-id :mime-version:message-id:date:subject:cc:to:from:x-beenthere :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=qpOzt7gB2Tu+3ntA7Hjx6iYpMTYMt0/lKnrx4+F7J1w=; b=i3G3DSBqcJc2jqC9ANn0a7jJZjqAP0+aZg7awlY+Q30QnWxqLZfpE5gqU0WiWyfHCh bRSkn2I38kXUg+DfwJJPxlKWZUlJxfbajJ8orZWaNGxEErjdydiUai0u8fcT6C5Cjkbu x51AAVuG3AFTu342GPAc1qahssH+CpdjqWHbDqpDDNIHxPXan+FbyTlD7drp6kTTvGEp I/Sx8VlBIVp5h8Jj6UnXbq4lh5y0mBPwBE14M75JhG6HYyszqBl7NIHvoan8HtMHCjZm 9xkpHRwZ1/TVjqchHxIMMI6IpdKVVjQPYrmbfcqGBTHzyA34zh3qMw7l7mZlEXpP14Ag iZbw== X-Forwarded-Encrypted: i=2; AJvYcCWHx6OsH+GXL9JSJSxYuU73+daVwB86vRZm5x1cJCAMdmeuJg0pAAz4hMZDMZNh33dcs/JNxIU=@isar-build.org X-Gm-Message-State: AOJu0Yy+hNzRD3DPrN34U1ZVZcM9SUxVffpiDKCUWSwgNxSKBvKP0dFM JlqZoTw6+XV67NJvdFOL1/H9DqRvnLdxbdXsW1i8KLvkinLVIYEx X-Google-Smtp-Source: AGHT+IGwLE8yC/mIdX6axDbb6f6fEhfJ5hZMj6HPvgGUKO/r4ObAyWPdTYNnbojfsfJOJ5xXr4hYVg== X-Received: by 2002:a17:90b:1b07:b0:2ef:cbcc:768b with SMTP id 98e67ed59e1d1-2f2d87bd428mr955204a91.6.1734380195747; Mon, 16 Dec 2024 12:16:35 -0800 (PST) X-BeenThere: isar-users@googlegroups.com Received: by 2002:a17:90b:1dc3:b0:2f1:2e10:8152 with SMTP id 98e67ed59e1d1-2f291b3296fls362495a91.2.-pod-prod-00-us; Mon, 16 Dec 2024 12:16:34 -0800 (PST) X-Received: by 2002:a17:90b:38ca:b0:2ef:9dbc:38d1 with SMTP id 98e67ed59e1d1-2f2d87bd3d7mr896549a91.5.1734380194314; Mon, 16 Dec 2024 12:16:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1734380194; cv=none; d=google.com; s=arc-20240605; b=LixCZj0Uhv0H/X2oAYqC6vFHCNeoWR35Xk91Sjz+U+AUzv9nAdxaoaw2f+Lf7Ggkwr XXtZHpwktkeyPcc1dNq2U6tQfZufHCY7AKcLRYacKjcJUf5bIT140db7kw6Wovkvwk8N NoepUML0fTuBVOGWsT0VWJsMwMim/m5WSawHsun8dAZaeitNBHC0nUDeDUP+85JSF6Qn 6Cwbi8p5TgnJ/Yv7MEXL8JzZydhNml6YY55QQzOheXFJ6yTVZqJupnglRcIBfOgMKRDJ tvuocfOZ+RPFA5g1OYWWDr3mYoMXMFBLG8YhzQMNukbdipPAurV6YZ6r3IyJ2iHvZ1KK moHg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=feedback-id:content-transfer-encoding:mime-version:message-id:date :subject:cc:to:from:dkim-signature; bh=Z2qdRMPJ22d2U/THtGBae9wCwVydSgylrFswtrQbZFA=; fh=driaQgy5ky1wrDv6HWsujA4dQyOYnFdmRvvxQJrALr8=; b=UHvLp3h6Tw6j9y5P2WCX5PfeYs0cs/a9+PuHjfEGr6qmZtU5FXJ1eRCvjNsfELee5+ B/qfnBFc9jqLwfP92QHv404h2RDEyd0tkeQOHlNDD6kcojdRD3EESvXNcY2AIL6BUx7t pgI58zgh7Z5HZXswuO3hJ8rkoDOLqaA7p+DKtXjpXPlOR1kYL1IM/AHFWo3tEopsjqqm N1XyUMhjBRJ+TOk9a8qJWlkWtonRwETXapOCQ/Qbv6pAOs9J6NzPvVA0Vmw4JW3Lsj7Y mv6Km6Qki8bel1CrNlTqiZNrBuxlOHXJ4+LORYSuZtrlbrZLcLobhL3PCQg7/7m7zP2V G/1Q==; dara=google.com ARC-Authentication-Results: i=1; gmr-mx.google.com; dkim=pass header.i=@siemens.com header.s=fm2 header.b=PqOqOFWt; spf=pass (google.com: domain of fm-1325773-202412162016327a143311339a96d68f-vbpd9o@rts-flowmailer.siemens.com designates 185.136.65.228 as permitted sender) smtp.mailfrom=fm-1325773-202412162016327a143311339a96d68f-vbpD9O@rts-flowmailer.siemens.com; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=siemens.com Received: from mta-65-228.siemens.flowmailer.net (mta-65-228.siemens.flowmailer.net. [185.136.65.228]) by gmr-mx.google.com with ESMTPS id 98e67ed59e1d1-2f142f8f025si357995a91.3.2024.12.16.12.16.34 for (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 16 Dec 2024 12:16:34 -0800 (PST) Received-SPF: pass (google.com: domain of fm-1325773-202412162016327a143311339a96d68f-vbpd9o@rts-flowmailer.siemens.com designates 185.136.65.228 as permitted sender) client-ip=185.136.65.228; Received: by mta-65-228.siemens.flowmailer.net with ESMTPSA id 202412162016327a143311339a96d68f for ; Mon, 16 Dec 2024 21:16:32 +0100 X-Patchwork-Original-From: "chris.larson via isar-users" From: "chris.larson" To: isar-users@googlegroups.com Cc: Christopher Larson Subject: [PATCH] lists.bbclass,bitbake.conf: use features lists Date: Mon, 16 Dec 2024 13:16:01 -0700 Message-ID: <20241216201602.619-1-chris.larson@siemens.com> MIME-Version: 1.0 X-Flowmailer-Platform: Siemens Feedback-ID: 519:519-1325773:519-21489:flowmailer X-Original-Sender: chris.larson@siemens.com X-Original-Authentication-Results: gmr-mx.google.com; dkim=pass header.i=@siemens.com header.s=fm2 header.b=PqOqOFWt; spf=pass (google.com: domain of fm-1325773-202412162016327a143311339a96d68f-vbpd9o@rts-flowmailer.siemens.com designates 185.136.65.228 as permitted sender) smtp.mailfrom=fm-1325773-202412162016327a143311339a96d68f-vbpD9O@rts-flowmailer.siemens.com; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=siemens.com X-Original-From: chris.larson@siemens.com Reply-To: chris.larson@siemens.com Precedence: list Mailing-list: list isar-users@googlegroups.com; contact isar-users+owners@googlegroups.com List-ID: X-Spam-Checked-In-Group: isar-users@googlegroups.com X-Google-Group-Id: 914930254986 List-Post: , List-Help: , List-Archive: , List-Unsubscribe: , X-Spam-Status: No, score=-4.9 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL, RCVD_IN_RP_CERTIFIED,RCVD_IN_RP_RNBL,RCVD_IN_RP_SAFE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on shymkent.ilbers.de X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= From: Christopher Larson The intention behind this commit is to ease and encourage the use of Yocto-style features variables, beyond our current usage: - Add a bbclass to ease the handling of list variables in general - Add default values for the features variables - Add the features variables to the list variables - Add a combined features variable The intention is that a downstream layer will use `bb.utils.contains` or `bb.utils.contains_any` to enable or disable functionality based on the presence of defined features, rather than adding new variables in each case. Signed-off-by: Christopher Larson Signed-off-by: Christopher Larson Signed-off-by: Christopher Larson --- meta/classes/lists.bbclass | 97 ++++++++++++++++++++++++++++++++++++++ meta/conf/bitbake.conf | 19 ++++++++ 2 files changed, 116 insertions(+) create mode 100644 meta/classes/lists.bbclass diff --git a/meta/classes/lists.bbclass b/meta/classes/lists.bbclass new file mode 100644 index 00000000..c872f4bd --- /dev/null +++ b/meta/classes/lists.bbclass @@ -0,0 +1,97 @@ +# Functions to improve the functionality of bitbake list variables. +# +# - Add the ability to remove items from a list variable without using :remove. +# - Add the ability for a list item to imply the addition of other list items. +# + +# Usage requires either adding the variable name to LIST_VARIABLES, or manually +# adding a :remove and a :prepend to each fully supported list variable. +# +# To remove items from a configured list, simply append the item to be removed +# to the variable with a '-' or '~' prefix. For example, to remove 'alpha' from +# IMAGE_FEATURES, add '-alpha' to IMAGE_FEATURES. +# +# To support implied list items, create a mapping of items to be appended to +# the variable when a specific item is present. For example, to append 'beta' +# to IMAGE_FEATURES when 'alpha' is present, configure IMAGE_FEATURES as such, +# then set IMPLIED_IMAGE_FEATURES[alpha] = "beta". +# +# Boilerplate example: +# +# # Either this: +# LIST_VARIABLES += "IMAGE_FEATURES" +# +# # Or this: +# IMAGE_FEATURES:remove = "${@remove_prefixed_items('IMAGE_FEATURES', d)}" +# IMAGE_FEATURES:prepend = "${@add_implied_items('IMAGE_FEATURES', 'IMPLIED_IMAGE_FEATURES', d)} " +# +# Usage example: +# +# # IMAGE_FEATURES will be "beta alpha" if the following configuration is used: +# IMPLIED_IMAGE_FEATURES[alpha] = "beta" +# IMAGE_FEATURES += "alpha" +# +# # IMAGE_FEATURES will be "first" if the following configuration is used: +# IMAGE_FEATURES = "first second" +# IMAGE_FEATURES += "-second" + + +def remove_prefixed_items(var, d): + """Return the items to be removed from var with :remove. + + This function is intended to be used in a :remove handler to remove + items from a variable. It will interpret items prefixed with a '-' + or '~' as items to be removed. + """ + # Use a flag to avoid infinite recursion. + if d.getVarFlag(var, 'remove_prefixed_items_internal') == '1': + return '' + + from collections import Counter + + d.setVarFlag(var, 'remove_prefixed_items_internal', '1') + try: + value = d.getVar(var) + counter = Counter() + for v in value.split(): + if v.startswith('-') or v.startswith('~'): + counter[v[1:]] -= 1 + counter[v] -= 1 + else: + counter[v] += 1 + return ' '.join(v for v, c in counter.items() if c < 1) + finally: + d.delVarFlag(var, 'remove_prefixed_items_internal') + + +def add_implied_items(var, implied_var, d): + """Return the items to be appended due to the presence of other items in var. + + This function is intended to be used in a :append handler to append + items from a variable. It will rely on the supplied mapping of implied items + to append the corresponding items. + """ + # Use a flag to avoid infinite recursion. + if d.getVarFlag(var, 'add_implied_items_internal') == '1': + return '' + + def implied_items(item, implied_mapping, d, seen=None): + """Return the implied items for a given item.""" + if seen is None: + seen = set() + if item in seen: + return '' + seen.add(item) + implied = implied_mapping.get(item, '').split() + return ' '.join(implied + [implied_items(f, implied_mapping, d, seen) for f in implied]) + + d.setVarFlag(var, 'add_implied_items_internal', '1') + try: + value = d.getVar(var) + implied_mapping = d.getVarFlags(implied_var) + if implied_mapping is None: + return '' + + return ' '.join(implied_items(f, implied_mapping, d) for f in value.split()) + finally: + d.delVarFlag(var, 'add_implied_items_internal') diff --git a/meta/conf/bitbake.conf b/meta/conf/bitbake.conf index ef408faa..5ab8ced7 100644 --- a/meta/conf/bitbake.conf +++ b/meta/conf/bitbake.conf @@ -175,6 +175,25 @@ BBINCLUDELOGS ??= "yes" # Add event handlers for bitbake INHERIT += "isar-events sstate" +# Make features variables available +INHERIT += "lists" + +LIST_VARIABLES += "BASE_REPO_FEATURES MACHINE_FEATURES DISTRO_FEATURES ROOTFS_FEATURES" + +BASE_REPO_FEATURES ??= "" +BASE_REPO_FEATURES[doc] = "Specifies the list of features for the base-apt repository." + +MACHINE_FEATURES ??= "" +MACHINE_FEATURES[doc] = "Specifies the list of hardware features the MACHINE is capable of supporting." + +DISTRO_FEATURES ??= "" +DISTRO_FEATURES[doc] = "The software support you want in your distribution for various features." + +COMBINED_FEATURES = "${@oe.utils.set_intersect('DISTRO_FEATURES', 'MACHINE_FEATURES', d)}" + +ROOTFS_FEATURES ??= "" +ROOTFS_FEATURES[doc] = "The list of features to be included in a root filesystem. Typically, you configure this variable in an image recipe or class." + # Buildstats requires IMAGE_ROOTFS to be always defined IMAGE_ROOTFS ??= "${WORKDIR}/rootfs" INHERIT += "${@'buildstats' if bb.utils.to_boolean(d.getVar('USE_BUILDSTATS')) else ''}"