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))
def _extractDictForTag(e, target, dict): # $(value) expands to the thing passed as tag's text value: try: dict2 = {'value': mk.evalExpr(e.value, target=target, add_dict=dict)} except Exception, err: raise errors.Error("incorrect argument value '%s': %s" % (e.value, err))
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)
def getOutputFileAbsPath(): """ Returns the absolute path of the output file using the os.sep for currently-running OS """ outputFile = mk.evalExpr(config.output_file, use_options=0) finalmakefile = os.path.abspath( os.path.split(currentosPaths(outputFile))[0]) return finalmakefile
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)
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) elif e.name == 'echo': handleEcho(e, target=target, add_dict=dict) elif e.name == 'fragment': handleFragment(e, target=target, add_dict=dict) elif e.name in globalTags: handleGlobalTag(e) return 0 return 1
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
def isconst(expr): try: mk.evalExpr(expr, use_options=0) return True except NameError: return False
def _extractDictForTag(e, target, dict): # $(value) expands to the thing passed as tag's text value: try: dict2 = {'value' : mk.evalExpr(e.value, target=target, add_dict=dict)} except Exception, err: raise errors.Error("incorrect argument value '%s': %s" % (e.value, err)) # tag's attributes are available as $(attributes['foo']): if len(e.props) > 0: attr = {} for a in e.props: try: attr[a] = mk.evalExpr(e.props[a], target=target, add_dict=dict) except Exception, err: raise errors.Error("incorrect value '%s' of attribute '%s': %s" % (e.props[a], a, err)) dict2['attributes'] = attr return dict2 def _processTargetNodes(node, target, tags, dict): 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 = {}
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()
def _extractDictForTag(e, target, dict): # $(value) expands to the thing passed as tag's text value: try: dict2 = {'value': mk.evalExpr(e.value, target=target, add_dict=dict)} except Exception, err: raise errors.Error("incorrect argument value '%s': %s" % (e.value, err)) # tag's attributes are available as $(attributes['foo']): if len(e.props) > 0: attr = {} for a in e.props: try: attr[a] = mk.evalExpr(e.props[a], target=target, add_dict=dict) except Exception, err: raise errors.Error( "incorrect value '%s' of attribute '%s': %s" % (e.props[a], a, err)) dict2['attributes'] = attr return dict2 def _processTargetNodes(node, target, tags, dict): def processCmd(e, target, dict): if e.name == 'set': handleSet(e, target=target, add_dict=dict) elif e.name == 'modify-target': if dict != None:
def _extractDictForTag(e, target, dict): # $(value) expands to the thing passed as tag's text value: try: dict2 = {'value' : mk.evalExpr(e.value, target=target, add_dict=dict)} except Exception, err: raise errors.Error("incorrect argument value '%s': %s" % (e.value, err))
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)
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()