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