How to use the mk.options 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 / writer.py View on Github external
for y in tar.vars[v][x]:
                        setattr(st, y, tar.vars[v][x][y].strip())
            elif v == 'distinctConfigs':
                t.distinctConfigs = tar.vars['distinctConfigs']
            else:
                if type(tar.vars[v]) is StringType:
                    setattr(t, v, tar.vars[v].strip())
                else:
                    setattr(t, v, tar.vars[v])
        t.cond = tar.cond
        targets.append(t.id, t)
    dict['targets'] = targets

    # Copy options:
    options = Container()
    for opt in mk.options.values():
        o = Struct()
        o.name = opt.name
        o.default = opt.default
        o.defaultStr = __stringify(o.default)
        o.desc = opt.desc
        o.descStr = __stringify(o.desc)
        o.values = opt.values
        o.values_desc = opt.values_desc
        if o.values != None: o.valuesStr = '[%s]' % ','.join(o.values)
        else: o.valuesStr = ''
        options.append(o.name, o)
    dict['options'] = options
    
    # Copy conditions:
    conditions = Container()
    for cond in mk.conditions.values():
github vslavik / bakefile / src / finalize.py View on Github external
def finalizeOptions():
    """Finalizes options by evaluating their default values."""
    for opt in mk.options.values():
        opt.evalDefault()
github vslavik / bakefile / src / flatten.py View on Github external
# default value:
                if config.verbose:
                    print "using default value '%s' for option '%s'" % \
                          (option.default, option.name)
                return cfgs
        out = []        
        name = option.name
        for c in cfgs:
            for v in option.values:
                x = copy.deepcopy(c)
                x.values[name] = v
                out.append(x)
        return out

    cfgs = []
    for o in mk.options.values():
        if len(cfgs) == 0:
            cfgs = expandCfgs([Configuration()], o)
        else:
            cfgs = expandCfgs(cfgs, o)
    return cfgs
github vslavik / bakefile / src / utils.py View on Github external
def callbackVar(nothing, expr, use_options, target, add_dict):
        ret = []
        if expr in mk.cond_vars:
            cond = mk.cond_vars[expr]
            for v in cond.values:
                if '$' in v.value:
                    ret += getPossibleValues(v.value)
                else:
                    ret.append(v.value)
            return ' '.join(ret)

        if expr in mk.options and mk.options[expr].values != None:
            opt = mk.options[expr]
            for v in opt.values:
                if '$' in v.value:
                    ret += getPossibleValues(v)
                else:
                    ret.append(v)
            return ' '.join(ret)

        # don't know what else to try, return as-is
        return expr
github vslavik / bakefile / src / flatten.py View on Github external
def __cfg2str(c):
    list = []
    for x in mk.options:
        if x in c:
            v = mk.options[x].values_desc[c[x]]
            if v != '': list.append(v)
    if len(list) == 0:
        return 'Default'
    else:
        return ' '.join(list)
github vslavik / bakefile / src / reader.py View on Github external
def handleOption(e):
    errors.pushCtx("when processing option '%s' at %s" %
                   (e.name, e.location()))

    name = evalConstExpr(e, e.props['name'])
    if name in mk.options:
        raise ReaderError(e, "option '%s' already defined" % name)

    if name in mk.override_vars:
        return # user hardcoded the value with -D=xxx

    default = None
    force_default = False
    desc = None
    values = None
    values_desc = None
    category = mk.Option.CATEGORY_UNSPECIFICED
    for c in e.children:
        if c.name == 'default-value':
            default = c.value
            force_default = 'force' in c.props and c.props['force'] == '1'
        elif c.name == 'description':
github vslavik / bakefile / src / finalize.py View on Github external
vars_to_keep = _getUneliminatableVars()

    # only purge options if we are not writing config file (if we are, an
    # option may be used by another makefile that shares same options file
    # even though the makefile used to generate the options doesn't use it):
    if (mk.vars['WRITE_OPTIONS_FILE'] != '1' or mk.vars['OPTIONS_FILE'] == ''):
        if mk.vars['FORMAT_NEEDS_OPTION_VALUES_FOR_CONDITIONS'] != '0':
            usedOpts = []
            for c in mk.conditions.values():
                usedOpts += [x.option.name for x in c.exprs]
            for o in mk.options:
                if ((o not in mk.__usageTracker.map) and (o not in usedOpts)
                    and (o not in vars_to_keep)):
                    toKill.append((mk.options, mk.__vars_opt, o))
        else:
            for o in mk.options:
                if o not in mk.__usageTracker.map and o not in vars_to_keep:
                    toKill.append((mk.options, mk.__vars_opt, o))

    for v in mk.cond_vars:
        if v not in mk.__usageTracker.map and v not in vars_to_keep:
            toKill.append((mk.cond_vars, mk.__vars_opt, v))
    for v in mk.make_vars:
        if v not in mk.__usageTracker.map and v not in vars_to_keep:
            toKill.append((mk.make_vars, mk.vars, v))
    
    if config.verbose:
        sys.stdout.write(': %i of %i\n' % (len(toKill),
                         len(mk.options)+len(mk.cond_vars)+len(mk.make_vars)))

    for dict1, dict2, key in toKill:
        del dict1[key]