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