How to use the mk.evalExpr 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 handleModifyTarget(e, dict=None):
    tg = mk.evalExpr(e.props['target'], use_options=0, add_dict=dict)
    if tg not in mk.targets:
        raise ReaderError(e, "unknown target '%s'" % tg)
    target = mk.targets[tg]
    tags = rules[target.type].getTagsDict()
    _processTargetNodes(e, target, tags, dict)
github vslavik / bakefile / src / reader.py View on Github external
def evalConstExpr(e, str, target=None, add_dict=None):
    try:
        return mk.evalExpr(str, use_options=0, target=target, add_dict=add_dict)
    except NameError, err:
        raise ReaderError(e, "can't use options or conditional variables in this context (%s)" % err)
github vslavik / bakefile / src / reader.py View on Github external
def processCmd(e, target, dict):
        if e.name == 'set':
            handleSet(e, target=target, add_dict=dict)
        elif e.name == 'modify-target':
            if dict != None:
                v = {}
                v.update(target.vars)
                v.update(dict)
                handleModifyTarget(e, v)
            else:
                handleModifyTarget(e, target.vars)
        elif e.name == 'add-target':
            e2 = copy.deepcopy(e)
            e2.props['id'] = mk.evalExpr(e2.props['target'],
                                         target=target, add_dict=dict)
            del e2.props['target']
            e2.name = e2.props['type']
            if 'cond' in e2.props and e2.props['cond'].startswith('target'):
                condstr = evalConstExpr(e2, e2.props['cond'],
                                        target=target, add_dict=dict)
                condstr = translateSpecialCondition(e2, condstr, target)
                if condstr == '1':
                    del e2.props['cond']
                else:
                    e2.props['cond'] = condstr
            handleTarget(e2)
        elif e.name == 'error':
            handleError(e, target=target, add_dict=dict)
        elif e.name == 'warning':
            handleWarning(e, target=target, add_dict=dict)
github vslavik / bakefile / src / finalize.py View on Github external
def iterateModifications(list):
        while len(list) > 0:
            newList = []
            if config.verbose:
                sys.stdout.write('[%i]' % len(list))
                sys.stdout.flush()
            for dict, obj, target in list:
                if dict == None:
                    expr = obj.value
                else:
                    expr = dict[obj]
                mk.__resetUsageTracker(reset_coverage=0)
                try:
                    new = mk.evalExpr(expr, target=target)
                except Exception, e:
                    raise errors.Error("failed to set variable '%s' to value '%s': %s" % (obj, expr, e))
                if expr != new:
                    if dict == None: obj.value = new
                    else: dict[obj] = new
                if (mk.__usageTracker.vars + 
                    mk.__usageTracker.pyexprs - mk.__usageTracker.refs > 0) \
                           and ('$' in new):
                    newList.append((dict,obj,target))
            list = newList
github vslavik / bakefile / src / reader.py View on Github external
name = '__%s_%s' % (target.id.replace('-','_').replace('.','_').replace('/','_'),
                                            basename)
                        mk.setVar(e.props['var'], '$(%s)' % name,
                                     eval=0, target=target,
                                     add_dict=add_dict, hints=hints)
                    if cond == None:
                        raise ReaderError(e, "malformed condition: '%s': must be constant expression, equality test or conjunction of them" % condstr)
                    if name in mk.cond_vars:
                        if not overwrite:
                            return
                        var = mk.cond_vars[name]
                    else:
                        var = mk.CondVar(name, target)
                        mk.addCondVar(var, hints)
                    if doEval:
                        value = mk.evalExpr(e_if.value,target=target,add_dict=add_dict)
                    else:
                        value = e_if.value
                    var.add(cond, value)
                finally:
                    errors.popCtx()
            
            if noValueSet:
                isCond = 0
                value = ''
            
            if isCond: 
                return

        # Non-conditional variables:
        if value == None: value = ''
        if 'append' in e.props and e.props['append'] == '1':
github vslavik / bakefile / src / reader.py View on Github external
def handleOutput(e):
    file = mk.evalExpr(e.props['file'], use_options=0)
    writer = mk.evalExpr(e.props['writer'], use_options=0)
    if 'method' in e.props:
        method = mk.evalExpr(e.props['method'], use_options=0)
    else:
        method = 'replace'
    config.to_output.append((file, writer, method))