Traceflags: Add SCons function to created a traceflag instead of having one file with them all.
--HG-- extra : convert_revision : 427f6bd8f050861ace3bc0d354a1afa5fc8319e6
This commit is contained in:
@@ -336,3 +336,194 @@ class Generate(object):
|
||||
arcname = py_compiled[zipname].arcname
|
||||
zf.write(zipname, arcname)
|
||||
zf.close()
|
||||
|
||||
def traceFlagsPy(self, target, source, env):
|
||||
assert(len(target) == 1)
|
||||
|
||||
f = file(str(target[0]), 'w')
|
||||
|
||||
allFlags = []
|
||||
for s in source:
|
||||
val = eval(s.get_contents())
|
||||
allFlags.append(val)
|
||||
|
||||
print >>f, 'baseFlags = ['
|
||||
for flag, compound, desc in allFlags:
|
||||
if not compound:
|
||||
print >>f, " '%s'," % flag
|
||||
print >>f, " ]"
|
||||
print >>f
|
||||
|
||||
print >>f, 'compoundFlags = ['
|
||||
print >>f, " 'All',"
|
||||
for flag, compound, desc in allFlags:
|
||||
if compound:
|
||||
print >>f, " '%s'," % flag
|
||||
print >>f, " ]"
|
||||
print >>f
|
||||
|
||||
print >>f, "allFlags = frozenset(baseFlags + compoundFlags)"
|
||||
print >>f
|
||||
|
||||
print >>f, 'compoundFlagMap = {'
|
||||
all = tuple([flag for flag,compound,desc in allFlags if not compound])
|
||||
print >>f, " 'All' : %s," % (all, )
|
||||
for flag, compound, desc in allFlags:
|
||||
if compound:
|
||||
print >>f, " '%s' : %s," % (flag, compound)
|
||||
print >>f, " }"
|
||||
print >>f
|
||||
|
||||
print >>f, 'flagDescriptions = {'
|
||||
print >>f, " 'All' : 'All flags',"
|
||||
for flag, compound, desc in allFlags:
|
||||
print >>f, " '%s' : '%s'," % (flag, desc)
|
||||
print >>f, " }"
|
||||
|
||||
f.close()
|
||||
|
||||
def traceFlagsCC(self, target, source, env):
|
||||
assert(len(target) == 1)
|
||||
|
||||
f = file(str(target[0]), 'w')
|
||||
|
||||
allFlags = []
|
||||
for s in source:
|
||||
val = eval(s.get_contents())
|
||||
allFlags.append(val)
|
||||
|
||||
# file header
|
||||
print >>f, '''
|
||||
/*
|
||||
* DO NOT EDIT THIS FILE! Automatically generated
|
||||
*/
|
||||
|
||||
#include "base/traceflags.hh"
|
||||
|
||||
using namespace Trace;
|
||||
|
||||
const char *Trace::flagStrings[] =
|
||||
{'''
|
||||
|
||||
# The string array is used by SimpleEnumParam to map the strings
|
||||
# provided by the user to enum values.
|
||||
for flag, compound, desc in allFlags:
|
||||
if not compound:
|
||||
print >>f, ' "%s",' % flag
|
||||
|
||||
print >>f, ' "All",'
|
||||
for flag, compound, desc in allFlags:
|
||||
if compound:
|
||||
print >>f, ' "%s",' % flag
|
||||
|
||||
print >>f, '};'
|
||||
print >>f
|
||||
print >>f, 'const int Trace::numFlagStrings = %d;' % len(allFlags)
|
||||
print >>f
|
||||
|
||||
#
|
||||
# Now define the individual compound flag arrays. There is an array
|
||||
# for each compound flag listing the component base flags.
|
||||
#
|
||||
all = tuple([flag for flag,compound,desc in allFlags if not compound])
|
||||
print >>f, 'static const Flags AllMap[] = {'
|
||||
for flag, compound, desc in allFlags:
|
||||
if not compound:
|
||||
print >>f, " %s," % flag
|
||||
print >>f, '};'
|
||||
print >>f
|
||||
|
||||
for flag, compound, desc in allFlags:
|
||||
if not compound:
|
||||
continue
|
||||
print >>f, 'static const Flags %sMap[] = {' % flag
|
||||
for flag in compound:
|
||||
print >>f, " %s," % flag
|
||||
print >>f, " (Flags)-1"
|
||||
print >>f, '};'
|
||||
print >>f
|
||||
|
||||
#
|
||||
# Finally the compoundFlags[] array maps the compound flags
|
||||
# to their individual arrays/
|
||||
#
|
||||
print >>f, 'const Flags *Trace::compoundFlags[] ='
|
||||
print >>f, '{'
|
||||
print >>f, ' AllMap,'
|
||||
for flag, compound, desc in allFlags:
|
||||
if compound:
|
||||
print >>f, ' %sMap,' % flag
|
||||
# file trailer
|
||||
print >>f, '};'
|
||||
|
||||
f.close()
|
||||
|
||||
def traceFlagsHH(self, target, source, env):
|
||||
assert(len(target) == 1)
|
||||
|
||||
f = file(str(target[0]), 'w')
|
||||
|
||||
allFlags = []
|
||||
for s in source:
|
||||
val = eval(s.get_contents())
|
||||
allFlags.append(val)
|
||||
|
||||
# file header boilerplate
|
||||
print >>f, '''
|
||||
/*
|
||||
* DO NOT EDIT THIS FILE!
|
||||
*
|
||||
* Automatically generated from traceflags.py
|
||||
*/
|
||||
|
||||
#ifndef __BASE_TRACE_FLAGS_HH__
|
||||
#define __BASE_TRACE_FLAGS_HH__
|
||||
|
||||
namespace Trace {
|
||||
|
||||
enum Flags {'''
|
||||
|
||||
# Generate the enum. Base flags come first, then compound flags.
|
||||
idx = 0
|
||||
for flag, compound, desc in allFlags:
|
||||
if not compound:
|
||||
print >>f, ' %s = %d,' % (flag, idx)
|
||||
idx += 1
|
||||
|
||||
numBaseFlags = idx
|
||||
print >>f, ' NumFlags = %d,' % idx
|
||||
|
||||
# put a comment in here to separate base from compound flags
|
||||
print >>f, '''
|
||||
// The remaining enum values are *not* valid indices for Trace::flags.
|
||||
// They are "compound" flags, which correspond to sets of base
|
||||
// flags, and are used by changeFlag.'''
|
||||
|
||||
print >>f, ' All = %d,' % idx
|
||||
idx += 1
|
||||
for flag, compound, desc in allFlags:
|
||||
if compound:
|
||||
print >>f, ' %s = %d,' % (flag, idx)
|
||||
idx += 1
|
||||
|
||||
numCompoundFlags = idx - numBaseFlags
|
||||
print >>f, ' NumCompoundFlags = %d' % numCompoundFlags
|
||||
|
||||
# trailer boilerplate
|
||||
print >>f, '''\
|
||||
}; // enum Flags
|
||||
|
||||
// Array of strings for SimpleEnumParam
|
||||
extern const char *flagStrings[];
|
||||
extern const int numFlagStrings;
|
||||
|
||||
// Array of arraay pointers: for each compound flag, gives the list of
|
||||
// base flags to set. Inidividual flag arrays are terminated by -1.
|
||||
extern const Flags *compoundFlags[];
|
||||
|
||||
/* namespace Trace */ }
|
||||
|
||||
#endif // __BASE_TRACE_FLAGS_HH__
|
||||
'''
|
||||
|
||||
f.close()
|
||||
|
||||
Reference in New Issue
Block a user