Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
mk.__trackUsage = 1
mk.__resetUsageTracker(reset_coverage=1)
list = []
if outputVarsOnly:
interestingVars = mk.vars['FORMAT_OUTPUT_VARIABLES'].strip()
if interestingVars != '':
interestingVars = interestingVars.split()
optimizeVars = len(interestingVars) > 0
else:
optimizeVars = 0
else:
optimizeVars = 0
for v in mk.make_vars:
if '$' in mk.make_vars[v]:
list.append((mk.make_vars,v,None))
for c in mk.cond_vars.values():
for v in c.values:
if '$' in v.value:
list.append((None,v,c.target))
if optimizeVars:
for v in interestingVars:
if v in mk.vars and '$' in mk.vars[v]:
list.append((mk.vars,v,None))
else:
for v in mk.vars:
if type(mk.vars[v]) is StringType:
if '$' in mk.vars[v]:
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]
del dict2[key]
return len(toKill) > 0
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]
del dict2[key]
return len(toKill) > 0
condname = value[2:-1]
if condname in mk.options:
if mk.options[condname].isNeverEmpty():
return fmt % value
else:
raise errors.Error("formatIfNotEmpty failed: option '%s' may be empty" % condname)
if condname in mk.cond_vars:
cond = mk.cond_vars[condname]
var = mk.CondVar(makeUniqueCondVarName('%s_p' % cond.name))
mk.addCondVar(var)
for v in cond.values:
var.add(v.cond, formatIfNotEmpty(fmt, v.value))
return '$(%s)' % var.name
if condname in mk.make_vars:
form = formatIfNotEmpty(fmt, mk.make_vars[condname])
if form == '': return ''
return fmt % value
if condname in mk.vars:
form = formatIfNotEmpty(fmt, mk.vars[condname])
if form == '': return ''
return fmt % value
raise errors.Error("formatIfNotEmpty failed: '%s' too complicated" % value)
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:
for cv in orig_cond_vars.values():
mk.vars[cv.name] = ''
for val in cv.values:
ok = 1
c.values = []
for v in cv.values:
vv = Struct()
vv.value = v.value
vv.cond = conditions[v.cond.name]
c.values.append(vv)
cond_vars.append(c.name, c)
setattr(cond_vars, c.name, c)
dict['cond_vars'] = cond_vars
# Copy "make variables":
make_vars = Container()
for mv in mk.make_vars:
mvv = Struct()
mvv.name = mv
mvv.value = mk.make_vars[mv]
make_vars.append(mv, mvv)
dict['make_vars'] = make_vars
# Copy fragments:
dict['fragments'] = mk.fragments
return dict
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:
for cv in orig_cond_vars.values():
mk.vars[cv.name] = ''
for val in cv.values:
for cv in mk.cond_vars.values():
c = Struct()
c.name = cv.name
c.values = []
for v in cv.values:
vv = Struct()
vv.value = v.value
vv.cond = conditions[v.cond.name]
c.values.append(vv)
cond_vars.append(c.name, c)
setattr(cond_vars, c.name, c)
dict['cond_vars'] = cond_vars
# Copy "make variables":
make_vars = Container()
for mv in mk.make_vars:
mvv = Struct()
mvv.name = mv
mvv.value = mk.make_vars[mv]
make_vars.append(mv, mvv)
dict['make_vars'] = make_vars
# Copy fragments:
dict['fragments'] = mk.fragments
return dict
toDel.append(t)
else:
orig_targets[t].vars['configs'][__cfg2str(cfg)] = tar.vars
for t in toDel:
del mk.targets[t]
finalize.replaceEscapeSequences()
myvars = mk.vars
mytgt = mk.targets
mk.vars = orig_vars
mk.targets = orig_targets
mk.cond_vars = orig_cond_vars
mk.make_vars = orig_make_vars
return (myvars, mytgt)