Beispiel #1
0
def createMakeVar(target, var, makevar, hints=''):
    """Creates make variable called 'makevar' with same value as 'var' and
       returns reference to it in the form of $(makevar)."""
    tg = mk.targets[target]
    mk.setVar('%s_%s' % (safeMakefileValue(target.upper()), makevar),
              "$(ref('%s','%s'))" % (var, target),
              target=tg, makevar=1, hints=hints)
    return '$(%s_%s)' % (safeMakefileValue(target.upper()), makevar)
Beispiel #2
0
def purgeConstantCondVars():
    """Removes conditional variables that have same value regardless of the
       condition."""
    # NB: We can't simply remove cond vars that have all their values same
    #     because there is always implicit value '' if none of the conditions
    #     is met. So we can only remove conditional variable in one of these
    #     two cases:
    #        1) All values are same and equal to ''.
    #        2) All values are same and disjunction of the conditions is
    #           tautology. This is not easy to detect and probably not worth
    #           the effort, so we don't do it (yet?) [FIXME]
    
    if config.verbose:
        sys.stdout.write('purging empty conditional variables')
        sys.stdout.flush()
    
    toDel = []
    for c in mk.cond_vars:
        cv = mk.cond_vars[c]
        if len(cv.values) == 0:
            toDel.append((c, ''))
        else:
            val = cv.values[0].value
            if val != '': continue
            purge = 1
            for v in cv.values[1:]:
                if v.value != val:
                    purge = 0
                    break
            if purge: toDel.append((c,val))
    
    if config.verbose:
        sys.stdout.write(': %i of %i\n' % (len(toDel), len(mk.cond_vars)))    
    for c, val in toDel:
        t = mk.cond_vars[c].target
        del mk.cond_vars[c]
        mk.setVar(c, val, target=t)
    return len(toDel) > 0
Beispiel #3
0
def purgeConstantCondVars():
    """Removes conditional variables that have same value regardless of the
       condition."""
    # NB: We can't simply remove cond vars that have all their values same
    #     because there is always implicit value '' if none of the conditions
    #     is met. So we can only remove conditional variable in one of these
    #     two cases:
    #        1) All values are same and equal to ''.
    #        2) All values are same and disjunction of the conditions is
    #           tautology. This is not easy to detect and probably not worth
    #           the effort, so we don't do it (yet?) [FIXME]
    
    if config.verbose:
        sys.stdout.write('purging empty conditional variables')
        sys.stdout.flush()
    
    toDel = []
    for c in mk.cond_vars:
        cv = mk.cond_vars[c]
        if len(cv.values) == 0:
            toDel.append((c, ''))
        else:
            val = cv.values[0].value
            if val != '': continue
            purge = 1
            for v in cv.values[1:]:
                if v.value != val:
                    purge = 0
                    break
            if purge: toDel.append((c,val))
    
    if config.verbose:
        sys.stdout.write(': %i of %i\n' % (len(toDel), len(mk.cond_vars)))    
    for c, val in toDel:
        t = mk.cond_vars[c].target
        del mk.cond_vars[c]
        mk.setVar(c, val, target=t)
    return len(toDel) > 0
Beispiel #4
0
def loadModule(m):
    if m in loadedModules:
        return
    if config.verbose: print "loading module '%s'..." % m
    loadedModules.append(m)

    # set USING_<MODULENAME> variable:
    mk.setVar('USING_%s' % m.upper(), '1')

    # import module's py utilities:
    imported = mk.importPyModule(m)

    # include module-specific makefiles:
    global availableFiles
    for f in availableFiles:
        if m in f.modules:
            f.modules.remove(m)
            if len(f.modules) == 0:
                processFile(f.file)
                imported = True
    availableFiles = [f for f in availableFiles if len(f.modules)>0]

    if not imported:
        raise ReaderError(None, "unknown module '%s'" % m)
Beispiel #5
0
def loadModule(m):
    if m in loadedModules:
        return
    if config.verbose: print "loading module '%s'..." % m
    loadedModules.append(m)

    # set USING_<MODULENAME> variable:
    mk.setVar('USING_%s' % m.upper(), '1')

    # import module's py utilities:
    imported = mk.importPyModule(m)

    # include module-specific makefiles:
    global availableFiles
    for f in availableFiles:
        if m in f.modules:
            f.modules.remove(m)
            if len(f.modules) == 0:
                processFile(f.file)
                imported = True
    availableFiles = [f for f in availableFiles if len(f.modules) > 0]

    if not imported:
        raise ReaderError(None, "unknown module '%s'" % m)
Beispiel #6
0
def handleSet(e, target=None, add_dict=None):
    try:
        errors.pushCtx("in <set> at %s" % e.location())

        name = basename = evalConstExpr(e, e.props['var'], target)
        if (name in mk.override_vars) and target == None:
            return # can't change value of variable overriden with -D=xxx
        
        doEval = not ('eval' in e.props and e.props['eval'] == '0')
        overwrite = not ('overwrite' in e.props and e.props['overwrite'] == '0')
        isCond = (len(e.children) > 0)
        isMakeVar = 'make_var' in e.props and e.props['make_var'] == '1'
        value = e.value
        if 'hints' in e.props:
            hints = e.props['hints']
        else:
            hints = ''

        # Handle conditions:
        if isCond:

            if e.value:
                raise ReaderError(e, "cannot set unconditional value when <if> is used")

            noValueSet = 1
            for e_if in e.children:
                try:
                    errors.pushCtx(e_if)

                    if e_if.name != 'if':
                        raise ReaderError(e_if, "malformed <set> 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)

                    noValueSet = 0
                    
                    # Real conditions:

                    checkConditionsSupport(e)
                    
                    if 'scope' in e.props:
                        raise ReaderError(e, "conditional variable can't have nondefault scope ('%s')" % e.props['scope'])

                    if target != None:
                        if (not overwrite) and (name in target.vars):
                            return
                        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':
            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()
Beispiel #7
0
def setOverrideVars():
    for v in config.defines:
        mk.setVar(v, config.defines[v])
        mk.override_vars[v] = config.defines[v]
Beispiel #8
0
def setStdVars(filename):
    mk.setVar('LF', '\n')
    mk.setVar('TAB', '\t')
    mk.setVar('SPACE', '$(" ")', eval=0)
    mk.setVar('DOLLAR', '&dollar;')
    
    mk.setVar('INPUT_FILE', os.path.abspath(filename))
    mk.setVar('INPUT_FILE_ARG', filename)
    mk.setVar('OUTPUT_FILE', config.output_file)
    mk.setVar('FORMAT', config.format)    
Beispiel #9
0
def handleSet(e, target=None, add_dict=None):
    try:
        errors.pushCtx("in <set> at %s" % e.location())

        name = basename = evalConstExpr(e, e.props['var'], target)
        if (name in mk.override_vars) and target == None:
            return  # can't change value of variable overriden with -D=xxx

        doEval = not ('eval' in e.props and e.props['eval'] == '0')
        overwrite = not ('overwrite' in e.props
                         and e.props['overwrite'] == '0')
        isCond = (len(e.children) > 0)
        isMakeVar = 'make_var' in e.props and e.props['make_var'] == '1'
        value = e.value
        if 'hints' in e.props:
            hints = e.props['hints']
        else:
            hints = ''

        # Handle conditions:
        if isCond:

            if e.value:
                raise ReaderError(
                    e, "cannot set unconditional value when <if> is used")

            noValueSet = 1
            for e_if in e.children:
                try:
                    errors.pushCtx(e_if)

                    if e_if.name != 'if':
                        raise ReaderError(e_if, "malformed <set> 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)

                    noValueSet = 0

                    # Real conditions:

                    checkConditionsSupport(e)

                    if 'scope' in e.props:
                        raise ReaderError(
                            e,
                            "conditional variable can't have nondefault scope ('%s')"
                            % e.props['scope'])

                    if target != None:
                        if (not overwrite) and (name in target.vars):
                            return
                        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':
            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()
Beispiel #10
0
def setOverrideVars():
    for v in config.defines:
        mk.setVar(v, config.defines[v])
        mk.override_vars[v] = config.defines[v]
Beispiel #11
0
def setStdVars(filename):
    mk.setVar('LF', '\n')
    mk.setVar('TAB', '\t')
    mk.setVar('SPACE', '$(" ")', eval=0)
    mk.setVar('DOLLAR', '&dollar;')

    mk.setVar('INPUT_FILE', os.path.abspath(filename))
    mk.setVar('INPUT_FILE_ARG', filename)
    mk.setVar('OUTPUT_FILE', config.output_file)
    mk.setVar('FORMAT', config.format)