Example #1
0
def handleGlobalTag(e):
    errors.pushCtx("when processing global tag '%s' at %s" %
                   (e.name, e.location()))

    dict = _extractDictForTag(e, target=None, dict=None)

    if dict:
        # FIXME: This is hack, it would be better to pass the dict to
        #        __doProcess(). But we don't have an easy way of doing it,
        #        so we modify the main variables dictionary mk.vars instead
        #        and then restore its original content.
        old_vars = {}
        for key in dict:
            if key in mk.vars:
                old_vars[key] = mk.vars[key]
            mk.vars[key] = dict[key]

    # execute the tag's commands now:
    __doProcess(xmldata=globalTags[e.name])

    if dict:
        # restore the original content of mk.vars:
        for key in dict:
            if key in old_vars:
                mk.vars[key] = old_vars[key]
            else:
                del mk.vars[key]

    errors.popCtx()
Example #2
0
def handleGlobalTag(e):
    errors.pushCtx("when processing global tag '%s' at %s" %
                   (e.name, e.location()))

    dict = _extractDictForTag(e, target=None, dict=None)

    if dict:
        # FIXME: This is hack, it would be better to pass the dict to
        #        __doProcess(). But we don't have an easy way of doing it,
        #        so we modify the main variables dictionary mk.vars instead
        #        and then restore its original content.
        old_vars = {}
        for key in dict:
            if key in mk.vars:
                old_vars[key] = mk.vars[key]
            mk.vars[key] = dict[key]

    # execute the tag's commands now:
    __doProcess(xmldata=globalTags[e.name])

    if dict:
        # restore the original content of mk.vars:
        for key in dict:
            if key in old_vars:
                mk.vars[key] = old_vars[key]
            else:
                del mk.vars[key]

    errors.popCtx()
Example #3
0
def handleUsing(e):
    try:
        errors.pushCtx(e)
        modules = e.props['module'].split(',')
        for m in modules:
            loadModule(m)
    finally:
        errors.popCtx()
Example #4
0
def handleUsing(e):
    try:
        errors.pushCtx(e)
        modules = e.props['module'].split(',')
        for m in modules:
            loadModule(m)
    finally:
        errors.popCtx()
Example #5
0
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':
            desc = c.value
        elif c.name == 'values':
            values = evalConstExpr(e, c.value.replace('\n', '')).split(',')
            for i in range(len(values)):
                values[i] = values[i].strip()
        elif c.name == 'values-description':
            values_desc = evalConstExpr(e, c.value).split(',')

    o = mk.Option(name, default, force_default, desc, values, values_desc,
                  errors.getCtx())
    mk.addOption(o)

    if 'never_empty' in e.props and e.props['never_empty'] == '1':
        o.neverEmpty = 1

    if 'category' in e.props:
        category = evalConstExpr(e, e.props['category'])
        if category == mk.Option.CATEGORY_PATH:
            o.category = category
            o.neverEmpty = 1

            def __pathOptionCallb(var, func, caller):
                if caller == 'nativePaths':
                    return '$(%s)' % var
                else:
                    return None

            utils.addSubstituteCallback(o.name, __pathOptionCallb)
        else:
            raise ReaderError(e, "unknown category '%s'" % category)

    errors.popCtx()
Example #6
0
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':
            desc = c.value
        elif c.name == 'values':
            values = evalConstExpr(e, c.value.replace('\n','')).split(',')
            for i in range(len(values)):
                values[i] = values[i].strip()
        elif c.name == 'values-description':
            values_desc = evalConstExpr(e, c.value).split(',')

    o = mk.Option(name, default, force_default, desc, values, values_desc,
                  errors.getCtx())
    mk.addOption(o)
    
    if 'never_empty' in e.props and e.props['never_empty'] == '1':
        o.neverEmpty = 1

    if 'category' in e.props:
        category = evalConstExpr(e, e.props['category'])
        if category == mk.Option.CATEGORY_PATH:
            o.category = category
            o.neverEmpty = 1
            def __pathOptionCallb(var, func, caller):
                if caller == 'nativePaths':
                    return '$(%s)' % var
                else:
                    return None
            utils.addSubstituteCallback(o.name, __pathOptionCallb)
        else:
            raise ReaderError(e, "unknown category '%s'" % category)

    errors.popCtx()
Example #7
0
def handleInclude(e):
    file = evalConstExpr(e, e.props['file'])
    canIgnore = 'ignore_missing' in e.props and e.props['ignore_missing'] == '1'
    justOnce = 'once' in e.props and e.props['once'] == '1'
    lookup = [os.path.dirname(e.filename)] + config.searchPath
    errors.pushCtx("included from %s" % e.location())
    for dir in lookup:
        if processFileIfExists(os.path.join(dir, file), justOnce):
            errors.popCtx()
            return
    if not canIgnore:
        raise ReaderError(e, "can't find file '%s' in %s" % (file,
                              string.join(lookup, ':')))
    errors.popCtx()
Example #8
0
def handleInclude(e):
    file = evalConstExpr(e, e.props['file'])
    canIgnore = 'ignore_missing' in e.props and e.props['ignore_missing'] == '1'
    justOnce = 'once' in e.props and e.props['once'] == '1'
    lookup = [os.path.dirname(e.filename)] + config.searchPath
    errors.pushCtx("included from %s" % e.location())
    for dir in lookup:
        if processFileIfExists(os.path.join(dir, file), justOnce):
            errors.popCtx()
            return
    if not canIgnore:
        raise ReaderError(
            e, "can't find file '%s' in %s" % (file, string.join(lookup, ':')))
    errors.popCtx()
Example #9
0
 def _processEntry(entry, target, dict):
     errors.pushCtx("when in <%s> at %s" %
                    (entry.node.name, entry.node.location()))
     if entry.type == TgtCmdNode.COMMAND:
         processCmd(entry.node, target, dict)
     elif entry.type == TgtCmdNode.IF:
         if evalWeakCondition(entry.node, target=target, add_dict=dict):
             for c in entry.children:
                 _processEntry(c, target, dict)
     else:
         if entry.type == TgtCmdNode.TAG:
             dict2 = _extractDictForTag(entry.node, target, dict)
         else:
             dict2 = dict
         for c in entry.children:
             _processEntry(c, target, dict2)
     errors.popCtx()
Example #10
0
 def _processEntry(entry, target, dict):
     errors.pushCtx("when in <%s> at %s" %
                    (entry.node.name, entry.node.location()))
     if entry.type == TgtCmdNode.COMMAND:
         processCmd(entry.node, target, dict)
     elif entry.type == TgtCmdNode.IF:
         if evalWeakCondition(entry.node, target=target, add_dict=dict):
             for c in entry.children:
                 _processEntry(c, target, dict)
     else:
         if entry.type == TgtCmdNode.TAG:
             dict2 = _extractDictForTag(entry.node, target, dict)
         else:
             dict2 = dict
         for c in entry.children:
             _processEntry(c, target, dict2)
     errors.popCtx()
Example #11
0
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()
Example #12
0
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()
Example #13
0
def handleTarget(e):
    if e.name not in rules:
        raise ReaderError(e, "unknown target type")

    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)
        
    tags = rule.getTagsDict()
    e = applyTemplates(e, rule.getTemplates() + extractTemplates(e, post=0),
                          extractTemplates(e, post=1))

    if id in mk.targets:
        raise ReaderError(e, "duplicate target name '%s'" % id)

    if 'category' in e.props:
        try:
            cats = {
                'all'       : mk.Target.CATEG_ALL,
                'normal'    : mk.Target.CATEG_NORMAL,
                'automatic' : mk.Target.CATEG_AUTOMATIC
                }
            category = cats[e.props['category']]
        except KeyError:
            raise ReaderError(e, "unknown category '%s'" % e.props['category'])
    else:
        category = mk.Target.CATEG_NORMAL
    
    target = mk.Target(e.name, id, cond, rule.pseudo, category)
    mk.addTarget(target)

    errors.pushCtx("when processing target '%s' at %s" %
                   (target.id, e.location()))
    _processTargetNodes(e, target, tags, None)
    errors.popCtx()
Example #14
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()
Example #15
0
def handleTarget(e):
    if e.name not in rules:
        raise ReaderError(e, "unknown target type")

    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)

    tags = rule.getTagsDict()
    e = applyTemplates(e,
                       rule.getTemplates() + extractTemplates(e, post=0),
                       extractTemplates(e, post=1))

    if id in mk.targets:
        raise ReaderError(e, "duplicate target name '%s'" % id)

    if 'category' in e.props:
        try:
            cats = {
                'all': mk.Target.CATEG_ALL,
                'normal': mk.Target.CATEG_NORMAL,
                'automatic': mk.Target.CATEG_AUTOMATIC
            }
            category = cats[e.props['category']]
        except KeyError:
            raise ReaderError(e, "unknown category '%s'" % e.props['category'])
    else:
        category = mk.Target.CATEG_NORMAL

    target = mk.Target(e.name, id, cond, rule.pseudo, category)
    mk.addTarget(target)

    errors.pushCtx("when processing target '%s' at %s" %
                   (target.id, e.location()))
    _processTargetNodes(e, target, tags, None)
    errors.popCtx()
Example #16
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()