Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 1 | # |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 2 | # Copyright OpenEmbedded Contributors |
| 3 | # |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 4 | # SPDX-License-Identifier: GPL-2.0-only |
| 5 | # |
| 6 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 7 | import itertools |
| 8 | |
| 9 | def is_optional(feature, d): |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 10 | return bool(d.getVarFlag("FEATURE_PACKAGES_%s" % feature, "optional")) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 11 | |
| 12 | def packages(features, d): |
| 13 | for feature in features: |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 14 | packages = d.getVar("FEATURE_PACKAGES_%s" % feature) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 15 | for pkg in (packages or "").split(): |
| 16 | yield pkg |
| 17 | |
| 18 | def required_packages(features, d): |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 19 | req = [feature for feature in features if not is_optional(feature, d)] |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 20 | return packages(req, d) |
| 21 | |
| 22 | def optional_packages(features, d): |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 23 | opt = [feature for feature in features if is_optional(feature, d)] |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 24 | return packages(opt, d) |
| 25 | |
| 26 | def active_packages(features, d): |
| 27 | return itertools.chain(required_packages(features, d), |
| 28 | optional_packages(features, d)) |
| 29 | |
| 30 | def active_recipes(features, d): |
| 31 | import oe.packagedata |
| 32 | |
| 33 | for pkg in active_packages(features, d): |
| 34 | recipe = oe.packagedata.recipename(pkg, d) |
| 35 | if recipe: |
| 36 | yield recipe |