#!/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( ".svn")==-1 ),  [ a[0] for a in os.walk(root)]  )

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

folders = [
	os.path.join('.'),
	os.path.join('CommonHelpers'),
	os.path.join('ControlsTests'),
	os.path.join('DescriptorsTests'),
	os.path.join('DynamicTypeTests'),
	os.path.join('FactoryTest'),
	os.path.join('FlowControlTests'),
	os.path.join('NonComponentData'),
	os.path.join('PortsTest'),
	os.path.join('ProcessingBaseTests'),
	os.path.join('ProcessingDataTests'),
	os.path.join('ProcessingsTests'),
	os.path.join('StandardTests'),
	os.path.join('TonalAnalysis'),
	os.path.join('ToolsTests'),
	os.path.join('XMLAdaptersTests'),
	os.path.join('VisualizationTests'),
	]
blacklist = [
	os.path.join('.','TestRunnerQt.cxx'),
	os.path.join('FactoryTest','PolymorphicTest.cxx'),
	os.path.join('ProcessingsTests','AudioMixerTest.cxx'),
	os.path.join('TonalAnalysis','ChordCorrelatorTest.cxx'), # recognized labels not the current ones
	os.path.join('TonalAnalysis','ChordExtractorTest.cxx'), # last too long
	# TODO see for libxml?
	os.path.join('XMLAdaptersTests','LibXmlDomDocumentHandlerTest.cxx'),
	os.path.join('XMLAdaptersTests','LibXmlDomReaderTest.cxx'),
	os.path.join('XMLAdaptersTests','LibXmlDomReadingContextTest.cxx'),
	os.path.join('XMLAdaptersTests','LibXmlDomWriterTest.cxx'),
	os.path.join('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 )

