|
| 1 | +# Use this class in recipes which depend on other recipes |
| 2 | +# or classes that might not be available. The class will then |
| 3 | +# will skip the current recipe with a suitable explanation. |
| 4 | +# |
| 5 | +# The expressions that define whether a component is available must |
| 6 | +# expand to something that Python considers as False (empty string, |
| 7 | +# None, etc.) or one of the values accepted by oe.types.boolean() |
| 8 | +# (0/1/True/False/Yes/No). |
| 9 | +# |
| 10 | +# Example: |
| 11 | +# |
| 12 | +# DEPENDS = "foobar" |
| 13 | +# |
| 14 | +# inherit check-available |
| 15 | +# CHECK_AVAILABLE[foobar] = "${HAVE_FOOBAR}" |
| 16 | +# |
| 17 | +# inherit ${@ check_available_class(d, 'meson', ${HAVE_MESON}) } |
| 18 | + |
| 19 | +def check_available(available): |
| 20 | + if isinstance(available, bool): |
| 21 | + return available |
| 22 | + elif isinstance(available, str) and available != '': |
| 23 | + return oe.types.boolean(available) |
| 24 | + else: |
| 25 | + return bool(available) |
| 26 | + |
| 27 | +def check_available_add_missing(d, component): |
| 28 | + missing = d.getVar('_check_available_missing') |
| 29 | + if missing is None: |
| 30 | + missing = [] |
| 31 | + missing.append(component) |
| 32 | + d.setVar('_check_available_missing', missing) |
| 33 | + |
| 34 | +def check_available_class(d, classname, available): |
| 35 | + if check_available(available): |
| 36 | + return classname |
| 37 | + else: |
| 38 | + check_available_add_missing(d, classname + '.bbclass') |
| 39 | + return '' |
| 40 | + |
| 41 | +python () { |
| 42 | + missing = d.getVar('_check_available_missing') |
| 43 | + if missing is None: |
| 44 | + missing = [] |
| 45 | + for component in (d.getVarFlags('CHECK_AVAILABLE') or []): |
| 46 | + available = d.getVarFlag('CHECK_AVAILABLE', component) |
| 47 | + try: |
| 48 | + if not check_available(available): |
| 49 | + missing.append(component) |
| 50 | + except ValueError as ex: |
| 51 | + # This typically is a user error, like setting an invalid value. |
| 52 | + # Without additional information about the exact component which |
| 53 | + # fails, the error would be hard to find as "bitbake -e" also just |
| 54 | + # throws the error. |
| 55 | + import sys |
| 56 | + tb = sys.exc_info()[2] |
| 57 | + raise ValueError('evaluating CHECK_AVAILABLE[%s] = %s = %s failed: %s' % |
| 58 | + (component, |
| 59 | + d.getVarFlag('CHECK_AVAILABLE', component, False), |
| 60 | + available, |
| 61 | + ex)).with_traceback(tb) |
| 62 | + |
| 63 | + if missing: |
| 64 | + raise bb.parse.SkipRecipe('some required components are unavailable: ' + ', '.join(missing)) |
| 65 | +} |
0 commit comments