How to use the mk.vars 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 / flatten.py View on Github external
def flattenConfig(cfg):
    # make copy of mk.vars, we'll need to restore it later:
    orig_vars = mk.vars
    mk.vars = copy.deepcopy(mk.vars)
    orig_targets = mk.targets
    mk.targets = copy.deepcopy(mk.targets)
    orig_make_vars = mk.make_vars
    mk.make_vars = {}
    orig_cond_vars = mk.cond_vars
    mk.cond_vars = {}

    if 'configs' in mk.vars: del mk.vars['configs']
    for t in mk.targets.values():
        if 'configs' in t.vars: del t.vars['configs']
    
    # add option values in this configuration:
    for opt in cfg:
        mk.vars[opt] = cfg[opt]

    # add conditional variables:
github vslavik / bakefile / src / mk_dump.py View on Github external
def dumpMakefile():
    print '\nVariables:'
    for v in mk.vars:
        print '  %-30s = %s' % (v, mk.vars[v])

    print '\nOptions:'
    for o in mk.options.values():
        print '  %-30s (default:%s,values:%s)' % (o.name, o.default, o.values)

    print '\nConditions:'
    for c in mk.conditions.values():
        print '  %-30s (%s)' % (c.name,c.exprs)

    print '\nConditional variables:'
    for v in mk.cond_vars.values():
        print '  %-30s' % v.name
        for vv in v.values:
            print '    if %-25s = %s' % (vv.cond.name, vv.value)

    print '\nTargets:'
github vslavik / bakefile / src / writer.py View on Github external
def __copyMkToVars():
    dict = {}

    # Copy variables:
    for v in mk.vars:
        if v == 'targets': continue
        if type(mk.vars[v]) is StringType:
            dict[v] = mk.vars[v].strip()
        else:
            dict[v] = mk.vars[v]

    # Copy targets information:
    targets = Container()

    for tar in mk.targets.values():
        t = Struct()
        for v in tar.vars:
            if v == 'configs':
                t.configs = {}
                for x in tar.vars[v]:
                    st = Struct()
                    t.configs[x] = st
                    for y in tar.vars[v][x]:
                        setattr(st, y, tar.vars[v][x][y].strip())
            elif v == 'distinctConfigs':
                t.distinctConfigs = tar.vars['distinctConfigs']
github vslavik / bakefile / src / reader.py View on Github external
def checkConditionsSupport(e):
    """Raises exception of the output format does not support some form
       of conditions (e.g. DigitalMars)."""
    if mk.vars['FORMAT_SUPPORTS_CONDITIONS'] != '1' and \
       mk.vars['FORMAT_SUPPORTS_CONFIGURATIONS'] != '1':
           raise ReaderError(e, 
                       'output format does not support conditional processing')
github vslavik / bakefile / src / utils.py View on Github external
def nativePaths(filenames):
    """Translates filenames from Unix to native filenames."""
    if mk.vars['TOOLSET'] == 'unix':
        return filenames
    else:
        return substitute(filenames,
                          lambda x: x.replace('/', mk.vars['DIRSEP']),
                          'FILENAMES',
                          caller='nativePaths')
github vslavik / bakefile / src / finalize.py View on Github external
def replaceEscapeSequences():
    # Replace all occurences of $ with $:

    def _repl(s):
        return s.replace('$', '$')

    if config.verbose:
        print 'replacing escape sequences'
    for v in mk.vars:
        if type(mk.vars[v]) is StringType:
            mk.vars[v] = _repl(mk.vars[v])
    for v in mk.make_vars:
        mk.make_vars[v] = _repl(mk.make_vars[v])
    for t in mk.targets.values():
        for v in t.vars:
            if type(t.vars[v]) is StringType:
                t.vars[v] = _repl(t.vars[v])
    for o in mk.options.values():
        if o.default != None:
            o.default = _repl(o.default)
        if o.values != None:
            o.values = [_repl(x) for x in o.values]

    for c in mk.cond_vars.values():
        for v in c.values:
github vslavik / bakefile / src / writer.py View on Github external
def __copyMkToVars():
    dict = {}

    # Copy variables:
    for v in mk.vars:
        if v == 'targets': continue
        if type(mk.vars[v]) is StringType:
            dict[v] = mk.vars[v].strip()
        else:
            dict[v] = mk.vars[v]

    # Copy targets information:
    targets = Container()

    for tar in mk.targets.values():
        t = Struct()
        for v in tar.vars:
            if v == 'configs':
                t.configs = {}
                for x in tar.vars[v]:
                    st = Struct()
github vslavik / bakefile / src / reader.py View on Github external
if value == None: value = ''
        if 'append' in e.props and e.props['append'] == '1':
            doAppend = 1
        else:
            doAppend = 0
        if 'prepend' in e.props and e.props['prepend'] == '1':
            doPrepend = 1
        else:
            doPrepend = 0
        store_in = None
        if 'scope' in e.props:
            sc = evalConstExpr(e, e.props['scope'], target=target)
            if sc == 'local':
                pass
            elif sc == 'global':
                store_in = mk.vars
            else:
                if sc in mk.targets:
                    store_in = mk.targets[sc].vars
                else:
                    raise ReaderError(e, "invalid scope '%s': must be 'global', 'local' or target name" % sc)

        if isMakeVar:
            if doAppend or store_in != None or not doEval:
                raise ReaderError(e, "make variable (%s) can't be appended or stored in nondefault scope or not evaluated" % name)
     
        mk.setVar(name, value, eval=doEval, target=target,
                  add_dict=add_dict, store_in=store_in,
                  append=doAppend, prepend=doPrepend, overwrite=overwrite,
                  makevar=isMakeVar, hints=hints)
    finally:
        errors.popCtx()