Andrew Geissler | 5a43b43 | 2020-06-13 10:46:56 -0500 | [diff] [blame] | 1 | # Allow checking of required and conflicting features |
Brad Bishop | 6dbb316 | 2019-11-25 09:41:34 -0500 | [diff] [blame] | 2 | # |
Andrew Geissler | d159c7f | 2021-09-02 21:05:58 -0500 | [diff] [blame] | 3 | # xxx = [DISTRO,MACHINE,COMBINED,IMAGE] |
Andrew Geissler | 5a43b43 | 2020-06-13 10:46:56 -0500 | [diff] [blame] | 4 | # |
| 5 | # ANY_OF_xxx_FEATURES: ensure at least one item on this list is included |
| 6 | # in xxx_FEATURES. |
| 7 | # REQUIRED_xxx_FEATURES: ensure every item on this list is included |
| 8 | # in xxx_FEATURES. |
| 9 | # CONFLICT_xxx_FEATURES: ensure no item in this list is included in |
| 10 | # xxx_FEATURES. |
Brad Bishop | 6dbb316 | 2019-11-25 09:41:34 -0500 | [diff] [blame] | 11 | # |
| 12 | # Copyright 2019 (C) Texas Instruments Inc. |
| 13 | # Copyright 2013 (C) O.S. Systems Software LTDA. |
| 14 | |
| 15 | python () { |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 16 | if d.getVar('PARSE_ALL_RECIPES', False): |
| 17 | return |
| 18 | |
Andrew Geissler | 5a43b43 | 2020-06-13 10:46:56 -0500 | [diff] [blame] | 19 | unused = True |
Brad Bishop | 6dbb316 | 2019-11-25 09:41:34 -0500 | [diff] [blame] | 20 | |
Andrew Geissler | d159c7f | 2021-09-02 21:05:58 -0500 | [diff] [blame] | 21 | for kind in ['DISTRO', 'MACHINE', 'COMBINED', 'IMAGE']: |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 22 | if d.getVar('ANY_OF_' + kind + '_FEATURES') is None and not d.hasOverrides('ANY_OF_' + kind + '_FEATURES') and \ |
| 23 | d.getVar('REQUIRED_' + kind + '_FEATURES') is None and not d.hasOverrides('REQUIRED_' + kind + '_FEATURES') and \ |
| 24 | d.getVar('CONFLICT_' + kind + '_FEATURES') is None and not d.hasOverrides('CONFLICT_' + kind + '_FEATURES'): |
Andrew Geissler | 5a43b43 | 2020-06-13 10:46:56 -0500 | [diff] [blame] | 25 | continue |
Brad Bishop | 6dbb316 | 2019-11-25 09:41:34 -0500 | [diff] [blame] | 26 | |
Andrew Geissler | 5a43b43 | 2020-06-13 10:46:56 -0500 | [diff] [blame] | 27 | unused = False |
Brad Bishop | 6dbb316 | 2019-11-25 09:41:34 -0500 | [diff] [blame] | 28 | |
Andrew Geissler | 5a43b43 | 2020-06-13 10:46:56 -0500 | [diff] [blame] | 29 | # Assume at least one var is set. |
| 30 | features = set((d.getVar(kind + '_FEATURES') or '').split()) |
Brad Bishop | 6dbb316 | 2019-11-25 09:41:34 -0500 | [diff] [blame] | 31 | |
Andrew Geissler | 5a43b43 | 2020-06-13 10:46:56 -0500 | [diff] [blame] | 32 | any_of_features = set((d.getVar('ANY_OF_' + kind + '_FEATURES') or '').split()) |
| 33 | if any_of_features: |
| 34 | if set.isdisjoint(any_of_features, features): |
| 35 | raise bb.parse.SkipRecipe("one of '%s' needs to be in %s_FEATURES" |
| 36 | % (' '.join(any_of_features), kind)) |
Brad Bishop | 6dbb316 | 2019-11-25 09:41:34 -0500 | [diff] [blame] | 37 | |
Andrew Geissler | 5a43b43 | 2020-06-13 10:46:56 -0500 | [diff] [blame] | 38 | required_features = set((d.getVar('REQUIRED_' + kind + '_FEATURES') or '').split()) |
| 39 | if required_features: |
| 40 | missing = set.difference(required_features, features) |
| 41 | if missing: |
| 42 | raise bb.parse.SkipRecipe("missing required %s feature%s '%s' (not in %s_FEATURES)" |
| 43 | % (kind.lower(), 's' if len(missing) > 1 else '', ' '.join(missing), kind)) |
Brad Bishop | 6dbb316 | 2019-11-25 09:41:34 -0500 | [diff] [blame] | 44 | |
Andrew Geissler | 5a43b43 | 2020-06-13 10:46:56 -0500 | [diff] [blame] | 45 | conflict_features = set((d.getVar('CONFLICT_' + kind + '_FEATURES') or '').split()) |
| 46 | if conflict_features: |
| 47 | conflicts = set.intersection(conflict_features, features) |
| 48 | if conflicts: |
| 49 | raise bb.parse.SkipRecipe("conflicting %s feature%s '%s' (in %s_FEATURES)" |
| 50 | % (kind.lower(), 's' if len(conflicts) > 1 else '', ' '.join(conflicts), kind)) |
Brad Bishop | 6dbb316 | 2019-11-25 09:41:34 -0500 | [diff] [blame] | 51 | |
Andrew Geissler | 5a43b43 | 2020-06-13 10:46:56 -0500 | [diff] [blame] | 52 | if unused: |
| 53 | bb.warn("Recipe inherits features_check but doesn't use it") |
Brad Bishop | 6dbb316 | 2019-11-25 09:41:34 -0500 | [diff] [blame] | 54 | } |