#!/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('FunctionalTests','CommonHelpers'),
	os.path.join('FunctionalTests','FlowControlTests'),
	os.path.join('FunctionalTests','ProcessingTests'),
	]
blacklist = [
	os.path.join('UnitTests','TestRunnerQt.cxx'),
	os.path.join('FunctionalTests','ProcessingTests','TestMIDIIO.cxx'),
	os.path.join('FunctionalTests','ProcessingTests','TestOnsetDetector.cxx'),
	os.path.join('FunctionalTests','ProcessingTests','TestSpectralPeakDetect.cxx'),
	os.path.join('FunctionalTests','ProcessingTests','TestSMSAnalysis.cxx'),
#	'TestAudioFileIn',
	]

if sys.platform == 'win32' :
	blacklist += [
		os.path.join('FunctionalTests','FlowControlTests','OSCEnabledNetworkTest.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)
print sources
for blacksheep in blacklist :
	sources.remove(blacksheep) 

print headers
print sources

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

functional_tests = env.Program( 'FunctionalTests', sources )

test_alias = Alias( 'run_functional_tests', [functional_tests], functional_tests[0].abspath )

AlwaysBuild( test_alias )

