Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
relies on previous call to finalEvaluation() that fills usage maps
in mk.__usageTracker.map!"""
if config.verbose:
sys.stdout.write('purging unused variables')
sys.stdout.flush()
toKill = []
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))
def dumpMakefile():
print '\nVariables:'
for v in mk.vars:
print ' %-30s = %s' % (v, mk.vars[v])
print '\nOptions:'
for o in mk.options.values():
print ' %-30s (default:%s,values:%s)' % (o.name, o.default, o.values)
print '\nConditions:'
for c in mk.conditions.values():
print ' %-30s (%s)' % (c.name,c.exprs)
print '\nConditional variables:'
for v in mk.cond_vars.values():
print ' %-30s' % v.name
for vv in v.values:
print ' if %-25s = %s' % (vv.cond.name, vv.value)
print '\nTargets:'
for t in mk.targets.values():
print ' %s %s' % (t.type, t.id)
for v in t.vars:
print ' %-28s = %s' % (v, t.vars[v])
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():
c = Struct()
c.name = cond.name
c.exprs = cond.exprs
conditions.append(c.name, c)
setattr(conditions, c.name, c)
dict['conditions'] = conditions
# Copy conditional variables:
cond_vars = Container()
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