]> de.git.xonotic.org Git - xonotic/netradiant.git/blobdiff - utils.py
Updating Windows compile guide after the major overhaul of Windows
[xonotic/netradiant.git] / utils.py
index f88389527e0a9c3a8dbb9dc58a05e59a8904b6a4..1e9774af7c81d137097197eaf89f2e149452b8b0 100644 (file)
--- a/utils.py
+++ b/utils.py
-# -*- mode: python -*-\r
-# QuakeZero build scripts\r
-# TTimo <ttimo@idsoftware.com>\r
-# http://scons.sourceforge.net\r
-\r
-import os, commands, platform, xml.sax, re, string, platform\r
-\r
-class vcproj( xml.sax.handler.ContentHandler ):\r
-       def __init__( self, filepath ):\r
-               self.source_files = []\r
-               self.misc_files = []\r
-               self._files = []\r
-               print 'parse %s' % filepath\r
-               xml.sax.parse( filepath, self )\r
-\r
-       def getSourceFiles( self ):\r
-               return self.source_files\r
-\r
-       def filterSource( self, expression, filelist = None ):\r
-               if ( filelist is None ):\r
-                       filelist = self.source_files\r
-               match = []\r
-               nomatch = []\r
-               for s in filelist:\r
-                       if ( re.match( expression, s ) ):\r
-                               match.append( s )\r
-                       else:\r
-                               nomatch.append( s )\r
-               return ( match, nomatch )\r
-\r
-       def startElement( self, name, attrs ):\r
-               if ( name == 'File' ):\r
-                       self._files.append( attrs.getValue('RelativePath') )\r
-\r
-       def endDocument( self ):\r
-               # split into source and headers, remap path seperator to the platform\r
-               for f in self._files:\r
-                       if ( platform.system() != 'Windows' ):\r
-                               f = f.replace( '\\', '/' )\r
-                       if ( f[-2:] == '.c' or f[-4:] == '.cpp' ):\r
-                               self.source_files.append( f.encode('ascii') )\r
-                       else:\r
-                               self.misc_files.append( f )\r
-               print '%d source files' % len( self.source_files )\r
-\r
-# action uses LDD to verify that the source doesn't hold unresolved symbols\r
-# setup as an AddPostAction of a regular SharedLibrary call\r
-def CheckUnresolved( source, target, env ):\r
-       # TODO: implement this for OSX\r
-       if ( platform.system() == 'Darwin' ):\r
-               return None\r
-       print 'CheckUnresolved %s' % target[0].abspath\r
-       if ( not os.path.isfile( target[0].abspath ) ):\r
-               print 'CheckUnresolved: %s does not exist' % target[0]\r
-               return 1 # fail\r
-       ( status, output ) = commands.getstatusoutput( 'ldd -r %s' % target[0] )\r
-       if ( status != 0 ):\r
-               print 'CheckUnresolved: ldd command failed (exit code %d)' % status\r
-               os.system( 'rm %s' % target[ 0 ] )\r
-               return 1 # fail\r
-       lines = string.split( output, '\n' )\r
-       have_undef = 0\r
-       for i_line in lines:\r
-               regex = re.compile('undefined symbol: (.*)\t\\((.*)\\)')\r
-               if ( regex.match( i_line ) ):\r
-                       symbol = regex.sub( '\\1', i_line )\r
-                       try:\r
-                               env['ALLOWED_SYMBOLS'].index( symbol )\r
-                       except:\r
-                               have_undef = 1\r
-       if ( have_undef ):\r
-               print output\r
-               print "CheckUnresolved: undefined symbols"\r
-               os.system('rm %s' % target[0])\r
-               return 1\r
-\r
-# http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/413486\r
-\r
-def Enum(*names):\r
-   ##assert names, "Empty enums are not supported" # <- Don't like empty enums? Uncomment!\r
-\r
-   class EnumClass(object):\r
-      __slots__ = names\r
-      def __iter__(self):        return iter(constants)\r
-      def __len__(self):         return len(constants)\r
-      def __getitem__(self, i):  return constants[i]\r
-      def __repr__(self):        return 'Enum' + str(names)\r
-      def __str__(self):         return 'enum ' + str(constants)\r
-\r
-   class EnumValue(object):\r
-      __slots__ = ('__value')\r
-      def __init__(self, value): self.__value = value\r
-      Value = property(lambda self: self.__value)\r
-      EnumType = property(lambda self: EnumType)\r
-      def __hash__(self):        return hash(self.__value)\r
-      def __cmp__(self, other):\r
-         # C fans might want to remove the following assertion\r
-         # to make all enums comparable by ordinal value {;))\r
-         assert self.EnumType is other.EnumType, "Only values from the same enum are comparable"\r
-         return cmp(self.__value, other.__value)\r
-      def __invert__(self):      return constants[maximum - self.__value]\r
-      def __nonzero__(self):     return bool(self.__value)\r
-      def __repr__(self):        return str(names[self.__value])\r
-\r
-   maximum = len(names) - 1\r
-   constants = [None] * len(names)\r
-   for i, each in enumerate(names):\r
-      val = EnumValue(i)\r
-      setattr(EnumClass, each, val)\r
-      constants[i] = val\r
-   constants = tuple(constants)\r
-   EnumType = EnumClass()\r
-   return EnumType\r
-\r
-#if __name__ == '__main__':\r
-#   print '\n*** Enum Demo ***'\r
-#   print '--- Days of week ---'\r
-#   Days = Enum('Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa', 'Su')\r
-#   print Days\r
-#   print Days.Mo\r
-#   print Days.Fr\r
-#   print Days.Mo < Days.Fr\r
-#   print list(Days)\r
-#   for each in Days:\r
-#      print 'Day:', each\r
-#   print '--- Yes/No ---'\r
-#   Confirmation = Enum('No', 'Yes')\r
-#   answer = Confirmation.No\r
-#   print 'Your answer is not', ~answer\r
-\r
+# -*- mode: python -*-
+# QuakeZero build scripts
+# TTimo <ttimo@idsoftware.com>
+# http://scons.sourceforge.net
+
+import os, commands, platform, xml.sax, re, string, platform
+
+class vcproj( xml.sax.handler.ContentHandler ):
+       def __init__( self, filepath ):
+               self.source_files = []
+               self.misc_files = []
+               self._files = []
+               print 'parse %s' % filepath
+               xml.sax.parse( filepath, self )
+
+       def getSourceFiles( self ):
+               return self.source_files
+
+       def filterSource( self, expression, filelist = None ):
+               if ( filelist is None ):
+                       filelist = self.source_files
+               match = []
+               nomatch = []
+               for s in filelist:
+                       if ( re.match( expression, s ) ):
+                               match.append( s )
+                       else:
+                               nomatch.append( s )
+               return ( match, nomatch )
+
+       def startElement( self, name, attrs ):
+               if ( name == 'File' ):
+                       self._files.append( attrs.getValue('RelativePath') )
+
+       def endDocument( self ):
+               # split into source and headers, remap path seperator to the platform
+               for f in self._files:
+                       if ( platform.system() != 'Windows' ):
+                               f = f.replace( '\\', '/' )
+                       if ( f[-2:] == '.c' or f[-4:] == '.cpp' ):
+                               self.source_files.append( f.encode('ascii') )
+                       else:
+                               self.misc_files.append( f )
+               print '%d source files' % len( self.source_files )
+
+# action uses LDD to verify that the source doesn't hold unresolved symbols
+# setup as an AddPostAction of a regular SharedLibrary call
+def CheckUnresolved( source, target, env ):
+       # TODO: implement this for OSX
+       if ( platform.system() == 'Darwin' ):
+               return None
+       print 'CheckUnresolved %s' % target[0].abspath
+       if ( not os.path.isfile( target[0].abspath ) ):
+               print 'CheckUnresolved: %s does not exist' % target[0]
+               return 1 # fail
+       ( status, output ) = commands.getstatusoutput( 'ldd -r %s' % target[0] )
+       if ( status != 0 ):
+               print 'CheckUnresolved: ldd command failed (exit code %d)' % status
+               os.system( 'rm %s' % target[ 0 ] )
+               return 1 # fail
+       lines = string.split( output, '\n' )
+       have_undef = 0
+       for i_line in lines:
+               regex = re.compile('undefined symbol: (.*)\t\\((.*)\\)')
+               if ( regex.match( i_line ) ):
+                       symbol = regex.sub( '\\1', i_line )
+                       try:
+                               env['ALLOWED_SYMBOLS'].index( symbol )
+                       except:
+                               have_undef = 1
+       if ( have_undef ):
+               print output
+               print "CheckUnresolved: undefined symbols"
+               os.system('rm %s' % target[0])
+               return 1
+
+# http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/413486
+
+def Enum(*names):
+   ##assert names, "Empty enums are not supported" # <- Don't like empty enums? Uncomment!
+
+   class EnumClass(object):
+      __slots__ = names
+      def __iter__(self):        return iter(constants)
+      def __len__(self):         return len(constants)
+      def __getitem__(self, i):  return constants[i]
+      def __repr__(self):        return 'Enum' + str(names)
+      def __str__(self):         return 'enum ' + str(constants)
+
+   class EnumValue(object):
+      __slots__ = ('__value')
+      def __init__(self, value): self.__value = value
+      Value = property(lambda self: self.__value)
+      EnumType = property(lambda self: EnumType)
+      def __hash__(self):        return hash(self.__value)
+      def __cmp__(self, other):
+         # C fans might want to remove the following assertion
+         # to make all enums comparable by ordinal value {;))
+         assert self.EnumType is other.EnumType, "Only values from the same enum are comparable"
+         return cmp(self.__value, other.__value)
+      def __invert__(self):      return constants[maximum - self.__value]
+      def __nonzero__(self):     return bool(self.__value)
+      def __repr__(self):        return str(names[self.__value])
+
+   maximum = len(names) - 1
+   constants = [None] * len(names)
+   for i, each in enumerate(names):
+      val = EnumValue(i)
+      setattr(EnumClass, each, val)
+      constants[i] = val
+   constants = tuple(constants)
+   EnumType = EnumClass()
+   return EnumType
+
+#if __name__ == '__main__':
+#   print '\n*** Enum Demo ***'
+#   print '--- Days of week ---'
+#   Days = Enum('Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa', 'Su')
+#   print Days
+#   print Days.Mo
+#   print Days.Fr
+#   print Days.Mo < Days.Fr
+#   print list(Days)
+#   for each in Days:
+#      print 'Day:', each
+#   print '--- Yes/No ---'
+#   Confirmation = Enum('No', 'Yes')
+#   answer = Confirmation.No
+#   print 'Your answer is not', ~answer
+