2007-11-04 04:09:22 +00:00
|
|
|
# -*- mode: python -*-
|
2012-05-28 00:06:21 +00:00
|
|
|
# GtkRadiant build scripts
|
|
|
|
# TTimo <ttimo@ttimo.net>
|
|
|
|
# http://scons.org/
|
2007-11-04 04:09:22 +00:00
|
|
|
|
2021-04-25 20:30:41 +00:00
|
|
|
|
2021-04-25 20:28:39 +00:00
|
|
|
|
2020-06-12 06:16:09 +00:00
|
|
|
import os, subprocess, platform, xml.sax, re, string, platform
|
2007-11-04 04:09:22 +00:00
|
|
|
|
2017-01-01 15:07:33 +00:00
|
|
|
class vcxproj( xml.sax.handler.ContentHandler ):
|
2007-11-04 04:09:22 +00:00
|
|
|
def __init__( self, filepath ):
|
|
|
|
self.source_files = []
|
|
|
|
self.misc_files = []
|
|
|
|
self._files = []
|
2020-06-12 06:16:09 +00:00
|
|
|
print( 'parse %s' % filepath )
|
2007-11-04 04:09:22 +00:00
|
|
|
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 ):
|
2017-01-01 15:07:33 +00:00
|
|
|
if ( name == 'ClCompile' ):
|
2020-06-12 06:16:09 +00:00
|
|
|
if ( 'Include' in attrs.getNames() ):
|
|
|
|
self._files.append( attrs.getValue('Include') )
|
2007-11-04 04:09:22 +00:00
|
|
|
|
|
|
|
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' ):
|
2020-06-12 06:16:09 +00:00
|
|
|
self.source_files.append( f )
|
2007-11-04 04:09:22 +00:00
|
|
|
else:
|
|
|
|
self.misc_files.append( f )
|
2020-06-12 06:16:09 +00:00
|
|
|
print( '%d source files' % len( self.source_files ) )
|
2007-11-04 04:09:22 +00:00
|
|
|
|
|
|
|
# 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
|
2020-06-12 06:16:09 +00:00
|
|
|
# TODO: implement this for FreeBSD
|
|
|
|
if ( platform.system() == 'FreeBSD' ):
|
|
|
|
return None
|
|
|
|
print( 'CheckUnresolved %s' % target[0].abspath )
|
2007-11-04 04:09:22 +00:00
|
|
|
if ( not os.path.isfile( target[0].abspath ) ):
|
2020-06-12 06:16:09 +00:00
|
|
|
print( 'CheckUnresolved: %s does not exist' % target[0] )
|
2007-11-04 04:09:22 +00:00
|
|
|
return 1 # fail
|
2020-06-12 06:16:09 +00:00
|
|
|
try:
|
|
|
|
stdout = subprocess.check_output( ['ldd', '-r', str(target[0])] ).decode( 'utf-8' )
|
|
|
|
except subprocess.CalledProcessError as cpe:
|
|
|
|
print( 'CheckUnresolved: ldd command failed (exit code {})'.format( cpe.returncode ) )
|
|
|
|
os.system( 'rm %s' % target[ 0 ] )
|
|
|
|
return 1 # fail
|
|
|
|
lines = stdout.split( '\n' )
|
2007-11-04 04:09:22 +00:00
|
|
|
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 ):
|
2020-06-12 06:16:09 +00:00
|
|
|
print( output )
|
|
|
|
print( "CheckUnresolved: undefined symbols" )
|
2007-11-04 04:09:22 +00:00
|
|
|
os.system('rm %s' % target[0])
|
|
|
|
return 1
|
|
|
|
|
|
|
|
# http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/413486
|
2012-10-07 18:37:16 +00:00
|
|
|
# OH_GOD, I used to think code like that was cool and useful
|
2007-11-04 04:09:22 +00:00
|
|
|
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]
|
2021-04-25 20:30:41 +00:00
|
|
|
def __bool__(self): return bool(self.__value)
|
2007-11-04 04:09:22 +00:00
|
|
|
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
|