2 # QuakeZero build scripts
3 # TTimo <ttimo@idsoftware.com>
4 # http://scons.sourceforge.net
6 import os, commands, platform, xml.sax, re, string, platform
8 class vcproj( xml.sax.handler.ContentHandler ):
9 def __init__( self, filepath ):
10 self.source_files = []
13 print 'parse %s' % filepath
14 xml.sax.parse( filepath, self )
16 def getSourceFiles( self ):
17 return self.source_files
19 def filterSource( self, expression, filelist = None ):
20 if ( filelist is None ):
21 filelist = self.source_files
25 if ( re.match( expression, s ) ):
29 return ( match, nomatch )
31 def startElement( self, name, attrs ):
32 if ( name == 'File' ):
33 self._files.append( attrs.getValue('RelativePath') )
35 def endDocument( self ):
36 # split into source and headers, remap path seperator to the platform
38 if ( platform.system() != 'Windows' ):
39 f = f.replace( '\\', '/' )
40 if ( f[-2:] == '.c' or f[-4:] == '.cpp' ):
41 self.source_files.append( f.encode('ascii') )
43 self.misc_files.append( f )
44 print '%d source files' % len( self.source_files )
46 # action uses LDD to verify that the source doesn't hold unresolved symbols
47 # setup as an AddPostAction of a regular SharedLibrary call
48 def CheckUnresolved( source, target, env ):
49 # TODO: implement this for OSX
50 if ( platform.system() == 'Darwin' ):
52 print 'CheckUnresolved %s' % target[0].abspath
53 if ( not os.path.isfile( target[0].abspath ) ):
54 print 'CheckUnresolved: %s does not exist' % target[0]
56 ( status, output ) = commands.getstatusoutput( 'ldd -r %s' % target[0] )
58 print 'CheckUnresolved: ldd command failed (exit code %d)' % status
59 os.system( 'rm %s' % target[ 0 ] )
61 lines = string.split( output, '\n' )
64 regex = re.compile('undefined symbol: (.*)\t\\((.*)\\)')
65 if ( regex.match( i_line ) ):
66 symbol = regex.sub( '\\1', i_line )
68 env['ALLOWED_SYMBOLS'].index( symbol )
73 print "CheckUnresolved: undefined symbols"
74 os.system('rm %s' % target[0])
77 # http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/413486
80 ##assert names, "Empty enums are not supported" # <- Don't like empty enums? Uncomment!
82 class EnumClass(object):
84 def __iter__(self): return iter(constants)
85 def __len__(self): return len(constants)
86 def __getitem__(self, i): return constants[i]
87 def __repr__(self): return 'Enum' + str(names)
88 def __str__(self): return 'enum ' + str(constants)
90 class EnumValue(object):
91 __slots__ = ('__value')
92 def __init__(self, value): self.__value = value
93 Value = property(lambda self: self.__value)
94 EnumType = property(lambda self: EnumType)
95 def __hash__(self): return hash(self.__value)
96 def __cmp__(self, other):
97 # C fans might want to remove the following assertion
98 # to make all enums comparable by ordinal value {;))
99 assert self.EnumType is other.EnumType, "Only values from the same enum are comparable"
100 return cmp(self.__value, other.__value)
101 def __invert__(self): return constants[maximum - self.__value]
102 def __nonzero__(self): return bool(self.__value)
103 def __repr__(self): return str(names[self.__value])
105 maximum = len(names) - 1
106 constants = [None] * len(names)
107 for i, each in enumerate(names):
109 setattr(EnumClass, each, val)
111 constants = tuple(constants)
112 EnumType = EnumClass()
115 #if __name__ == '__main__':
116 # print '\n*** Enum Demo ***'
117 # print '--- Days of week ---'
118 # Days = Enum('Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa', 'Su')
122 # print Days.Mo < Days.Fr
126 # print '--- Yes/No ---'
127 # Confirmation = Enum('No', 'Yes')
128 # answer = Confirmation.No
129 # print 'Your answer is not', ~answer