1*c342db35SBrad Bishop# 2*c342db35SBrad Bishop# SPDX-License-Identifier: GPL-2.0-only 3*c342db35SBrad Bishop# 4*c342db35SBrad Bishop 5eb8dc403SDave Cobbleyimport itertools 6eb8dc403SDave Cobbley 7eb8dc403SDave Cobbleydef is_optional(feature, d): 8eb8dc403SDave Cobbley packages = d.getVar("FEATURE_PACKAGES_%s" % feature) 9eb8dc403SDave Cobbley if packages: 10eb8dc403SDave Cobbley return bool(d.getVarFlag("FEATURE_PACKAGES_%s" % feature, "optional")) 11eb8dc403SDave Cobbley else: 12eb8dc403SDave Cobbley return bool(d.getVarFlag("PACKAGE_GROUP_%s" % feature, "optional")) 13eb8dc403SDave Cobbley 14eb8dc403SDave Cobbleydef packages(features, d): 15eb8dc403SDave Cobbley for feature in features: 16eb8dc403SDave Cobbley packages = d.getVar("FEATURE_PACKAGES_%s" % feature) 17eb8dc403SDave Cobbley if not packages: 18eb8dc403SDave Cobbley packages = d.getVar("PACKAGE_GROUP_%s" % feature) 19eb8dc403SDave Cobbley for pkg in (packages or "").split(): 20eb8dc403SDave Cobbley yield pkg 21eb8dc403SDave Cobbley 22eb8dc403SDave Cobbleydef required_packages(features, d): 23eb8dc403SDave Cobbley req = [feature for feature in features if not is_optional(feature, d)] 24eb8dc403SDave Cobbley return packages(req, d) 25eb8dc403SDave Cobbley 26eb8dc403SDave Cobbleydef optional_packages(features, d): 27eb8dc403SDave Cobbley opt = [feature for feature in features if is_optional(feature, d)] 28eb8dc403SDave Cobbley return packages(opt, d) 29eb8dc403SDave Cobbley 30eb8dc403SDave Cobbleydef active_packages(features, d): 31eb8dc403SDave Cobbley return itertools.chain(required_packages(features, d), 32eb8dc403SDave Cobbley optional_packages(features, d)) 33eb8dc403SDave Cobbley 34eb8dc403SDave Cobbleydef active_recipes(features, d): 35eb8dc403SDave Cobbley import oe.packagedata 36eb8dc403SDave Cobbley 37eb8dc403SDave Cobbley for pkg in active_packages(features, d): 38eb8dc403SDave Cobbley recipe = oe.packagedata.recipename(pkg, d) 39eb8dc403SDave Cobbley if recipe: 40eb8dc403SDave Cobbley yield recipe 41