#!/usr/bin/python
Import('env')
import sys, os, glob

def scanFiles(pattern, paths) :
	files = []
	for path in paths :
		files+=glob.glob(os.path.join(path,pattern))
	return files

def recursiveDirs(root) :
	return filter( (lambda a : a.rfind( "CVS")==-1 ),  [ a[0] for a in os.walk(root)]  )

def unique(list) :
	return dict.fromkeys(list).keys()

folders = [
	os.path.join('UnitTests'),
	os.path.join('UnitTests','CommonHelpers'),
	os.path.join('UnitTests','ControlsTests'),
	os.path.join('UnitTests','DescriptorsTests'),
	os.path.join('UnitTests','DynamicTypeTests'),
	os.path.join('UnitTests','FactoryTest'),
	os.path.join('UnitTests','FlowControlTests'),
	os.path.join('UnitTests','NonComponentData'),
	os.path.join('UnitTests','PortsTest'),
	os.path.join('UnitTests','ProcessingBaseTests'),
	os.path.join('UnitTests','ProcessingDataTests'),
	os.path.join('UnitTests','ProcessingsTests'),
	os.path.join('UnitTests','StandardTests'),
	os.path.join('UnitTests','ToolsTests'),
	os.path.join('UnitTests','XMLAdaptersTests'),
	os.path.join('UnitTests','VisualizationTests'),
	]
blacklist = [
	os.path.join('UnitTests','TestRunnerQt.cxx'),
	os.path.join('UnitTests','FactoryTest','PolymorphicTest.cxx'),
	os.path.join('UnitTests','ProcessingsTests','AudioMixerTest.cxx'),
	# TODO see for libxml?
	os.path.join('UnitTests','XMLAdaptersTests','LibXmlDomDocumentHandlerTest.cxx'),
	os.path.join('UnitTests','XMLAdaptersTests','LibXmlDomReaderTest.cxx'),
	os.path.join('UnitTests','XMLAdaptersTests','LibXmlDomReadingContextTest.cxx'),
	os.path.join('UnitTests','XMLAdaptersTests','LibXmlDomWriterTest.cxx'),
	os.path.join('UnitTests','DescriptorsTests','ProofOfConceptTest.cxx'),
	]


folders = [ os.path.join('..','..','..','test', folder) for folder in folders ]
blacklist = [ os.path.join('..','..','..','test', blacksheep) for blacksheep in blacklist ]
sources = scanFiles('*.cxx', folders)
headers = scanFiles('*.hxx', folders)
for blacksheep in blacklist :
	sources.remove(blacksheep) 


if sys.platform != 'win32'  :
	env.Append( CPPPATH=['include'] )
else :
	env.Append( CCFLAGS = ['/EHsc'] )
	env.Append( LINKFLAGS = ['/subsystem:console','/machine:x86'] )	

unit_tests = env.Program( 'UnitTests', sources )

test_alias = Alias( 'run_unit_tests', [unit_tests], unit_tests[0].abspath )

AlwaysBuild( test_alias )

