How to use the mk.evalCondition function in mk

To help you get started, we’ve selected a few mk examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github vslavik / bakefile / src / reader.py View on Github external
def evalWeakConditionDontRaise(e, target=None, add_dict=None):
    """Same as evalWeakCondition() but returns None instead of raising
       an exception."""
    try:
        errors.pushCtx(e)

        if 'cond' not in e.props:
            return 1
        condstr = e.props['cond']
        typ = mk.evalCondition(condstr, target=target, add_dict=add_dict)
        # Condition never met when generating this target:
        if typ == '0':
            return 0
        # Condition always met:
        elif typ == '1':
            return 1
        else:
            return None
    finally:
        errors.popCtx()
github vslavik / bakefile / src / flatten.py View on Github external
ok = 0
                    break
            if not ok: continue
            mk.vars[cv.name] = val.value
            break

    finalize.finalEvaluation()

    # Remove targets that are not part of this configuration:
    toDel = []
    for t in mk.targets:
        tar = mk.targets[t]
        if tar.cond == None:
            use = '1'
        else:
            use = mk.evalCondition(tar.cond.tostr())
        assert use != None
        if use == '0':
            toDel.append(t)
        else:
            orig_targets[t].vars['configs'][__cfg2str(cfg)] = tar.vars

    for t in toDel:
        del mk.targets[t]

    finalize.replaceEscapeSequences()

    myvars = mk.vars
    mytgt = mk.targets
    
    mk.vars = orig_vars
    mk.targets = orig_targets
github vslavik / bakefile / src / reader.py View on Github external
noValueSet = 1
            for e_if in e.children:
                try:
                    errors.pushCtx(e_if)

                    if e_if.name != 'if':
                        raise ReaderError(e_if, "malformed  command")
                
                    # Preprocess always true or always false conditions:

                    condstr = evalConstExpr(e_if, e_if.props['cond'],
                                            target=target, add_dict=add_dict)
                    condstr = translateSpecialCondition(e_if, condstr, target)
                     
                    typ = mk.evalCondition(condstr)
                    # Condition never met when generating this target:
                    if typ == '0':
                        if config.debug:
                            print "[dbg] removing never-met condition '%s' for variable '%s'" % (condstr, name)
                        continue
                    # Condition always met:
                    elif typ == '1':
                        if config.debug:
                            print "[dbg] condition '%s' for variable '%s' is always met" % (condstr, name)
                        noValueSet = 0
                        isCond = 0
                        value = e_if.value
                        break
                    elif typ != None:
                        raise ReaderError(e, "malformed condition '%s': doesn't evaluate to boolean value" % condstr)
                    cond = mk.makeCondition(condstr)
github vslavik / bakefile / src / reader.py View on Github external
rule = rules[e.name]
    if rule.pseudo and 'id' not in e.props:
        global _pseudoTargetLastID
        id = 'pseudotgt%i' % _pseudoTargetLastID
        _pseudoTargetLastID += 1
    else:
        if 'id' not in e.props:
            raise ReaderError(e, "target doesn't have id")
        id = e.props['id']

    cond = None
    if 'cond' in e.props:
        isCond = 1
        # Handle conditional targets:
        condstr = evalConstExpr(e, e.props['cond'])
        typ = mk.evalCondition(condstr)
        # Condition never met, ignore the target:
        if typ == '0':
            utils.deadTargets.append(id)
            return
        # Condition always met:
        elif typ == '1':
            isCond = 0
        elif typ != None:
            raise ReaderError(e, "malformed condition: '%s'" % condstr)

        if isCond:
            checkConditionsSupport(e)
            cond = mk.makeCondition(condstr)
            if cond == None:
                raise ReaderError(e, "malformed condition: '%s'" % condstr)