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): |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 8 | packages = d.getVar("FEATURE_PACKAGES_%s" % feature) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 9 | if packages: |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -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 | else: |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 12 | return bool(d.getVarFlag("PACKAGE_GROUP_%s" % feature, "optional")) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 13 | |
| 14 | def packages(features, d): |
| 15 | for feature in features: |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 16 | packages = d.getVar("FEATURE_PACKAGES_%s" % feature) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 17 | if not packages: |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 18 | packages = d.getVar("PACKAGE_GROUP_%s" % feature) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 19 | for pkg in (packages or "").split(): |
| 20 | yield pkg |
| 21 | |
| 22 | def required_packages(features, d): |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 23 | req = [feature for feature in features if not is_optional(feature, d)] |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 24 | return packages(req, d) |
| 25 | |
| 26 | def optional_packages(features, d): |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 27 | opt = [feature for feature in features if is_optional(feature, d)] |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 28 | return packages(opt, d) |
| 29 | |
| 30 | def active_packages(features, d): |
| 31 | return itertools.chain(required_packages(features, d), |
| 32 | optional_packages(features, d)) |
| 33 | |
| 34 | def active_recipes(features, d): |
| 35 | import oe.packagedata |
| 36 | |
| 37 | for pkg in active_packages(features, d): |
| 38 | recipe = oe.packagedata.recipename(pkg, d) |
| 39 | if recipe: |
| 40 | yield recipe |