blob: 205e1b9cd3164d97c29dc8a53c85249dda1edaa1 [file] [log] [blame]
Andrew Geissler5a43b432020-06-13 10:46:56 -05001# Allow checking of required and conflicting features
Brad Bishop6dbb3162019-11-25 09:41:34 -05002#
Andrew Geisslerd159c7f2021-09-02 21:05:58 -05003# xxx = [DISTRO,MACHINE,COMBINED,IMAGE]
Andrew Geissler5a43b432020-06-13 10:46:56 -05004#
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 Bishop6dbb3162019-11-25 09:41:34 -050011#
12# Copyright 2019 (C) Texas Instruments Inc.
13# Copyright 2013 (C) O.S. Systems Software LTDA.
14
15python () {
Andrew Geissler82c905d2020-04-13 13:39:40 -050016 if d.getVar('PARSE_ALL_RECIPES', False):
17 return
18
Andrew Geissler5a43b432020-06-13 10:46:56 -050019 unused = True
Brad Bishop6dbb3162019-11-25 09:41:34 -050020
Andrew Geisslerd159c7f2021-09-02 21:05:58 -050021 for kind in ['DISTRO', 'MACHINE', 'COMBINED', 'IMAGE']:
Andrew Geissler5a43b432020-06-13 10:46:56 -050022 if d.getVar('ANY_OF_' + kind + '_FEATURES') is None and \
23 d.overridedata.get('ANY_OF_' + kind + '_FEATURES') is None and \
24 d.getVar('REQUIRED_' + kind + '_FEATURES') is None and \
25 d.overridedata.get('REQUIRED_' + kind + '_FEATURES') is None and \
26 d.getVar('CONFLICT_' + kind + '_FEATURES') is None and \
27 d.overridedata.get('CONFLICT_' + kind + '_FEATURES') is None:
28 continue
Brad Bishop6dbb3162019-11-25 09:41:34 -050029
Andrew Geissler5a43b432020-06-13 10:46:56 -050030 unused = False
Brad Bishop6dbb3162019-11-25 09:41:34 -050031
Andrew Geissler5a43b432020-06-13 10:46:56 -050032 # Assume at least one var is set.
33 features = set((d.getVar(kind + '_FEATURES') or '').split())
Brad Bishop6dbb3162019-11-25 09:41:34 -050034
Andrew Geissler5a43b432020-06-13 10:46:56 -050035 any_of_features = set((d.getVar('ANY_OF_' + kind + '_FEATURES') or '').split())
36 if any_of_features:
37 if set.isdisjoint(any_of_features, features):
38 raise bb.parse.SkipRecipe("one of '%s' needs to be in %s_FEATURES"
39 % (' '.join(any_of_features), kind))
Brad Bishop6dbb3162019-11-25 09:41:34 -050040
Andrew Geissler5a43b432020-06-13 10:46:56 -050041 required_features = set((d.getVar('REQUIRED_' + kind + '_FEATURES') or '').split())
42 if required_features:
43 missing = set.difference(required_features, features)
44 if missing:
45 raise bb.parse.SkipRecipe("missing required %s feature%s '%s' (not in %s_FEATURES)"
46 % (kind.lower(), 's' if len(missing) > 1 else '', ' '.join(missing), kind))
Brad Bishop6dbb3162019-11-25 09:41:34 -050047
Andrew Geissler5a43b432020-06-13 10:46:56 -050048 conflict_features = set((d.getVar('CONFLICT_' + kind + '_FEATURES') or '').split())
49 if conflict_features:
50 conflicts = set.intersection(conflict_features, features)
51 if conflicts:
52 raise bb.parse.SkipRecipe("conflicting %s feature%s '%s' (in %s_FEATURES)"
53 % (kind.lower(), 's' if len(conflicts) > 1 else '', ' '.join(conflicts), kind))
Brad Bishop6dbb3162019-11-25 09:41:34 -050054
Andrew Geissler5a43b432020-06-13 10:46:56 -050055 if unused:
56 bb.warn("Recipe inherits features_check but doesn't use it")
Brad Bishop6dbb3162019-11-25 09:41:34 -050057}