Skip to content

Commit

Permalink
Refactor trivial_tests build
Browse files Browse the repository at this point in the history
Have the testing build build the trivial_tests as well
Add a 'run_tests' alias which builds and runs all the tests, trivial &
otherwise.
  • Loading branch information
jaredhoberock committed Mar 19, 2012
1 parent 0c4a9c7 commit bc4b1d6
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 91 deletions.
9 changes: 9 additions & 0 deletions testing/SConscript
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,12 @@ sources = filter(test_filter, sources)

tester = my_env.Program('tester', sources)

# add the tester to the 'run_tests' alias
tester_alias = my_env.Alias('run_tests', [tester], tester[0].abspath)

# always build the 'run_tests' target whether or not it needs it
my_env.AlwaysBuild(tester_alias)

# build children
SConscript('trivial_tests/SConscript', 'my_env')

3 changes: 3 additions & 0 deletions testing/trivial_tests/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*.cu
*.cpp

77 changes: 77 additions & 0 deletions testing/trivial_tests/SConscript
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import os
from warnings import warn

Import('env')
my_env = env.Clone()

thrust_abspath = os.path.abspath("../../thrust/")

# this function builds a trivial source file from a Thrust header
def trivial_source_from_header(source, target, env):
target_filename = str(target[0])
fid = open(target_filename, 'w')

# make sure we don't trip over <windows.h> when compiling with cl.exe
if my_env.subst('$CXX') == 'cl':
fid.write('#include <windows.h>\n')

for src in source:
src_abspath = str(src)
src_relpath = os.path.relpath(src_abspath, thrust_abspath)
include = os.path.join('thrust', src_relpath)

fid.write('#include <' + include + '>\n')
fid.close()


# CUFile builds a trivial .cu file from a Thrust header
cu_from_header_builder = Builder(action = trivial_source_from_header,
suffix = '.cu',
src_suffix = '.h')
my_env.Append(BUILDERS = {'CUFile' : cu_from_header_builder})

# CPPFile builds a trivial .cpp file from a Thrust header
cpp_from_header_builder = Builder(action = trivial_source_from_header,
suffix = '.cpp',
src_suffix = '.h')
my_env.Append(BUILDERS = {'CPPFile' : cpp_from_header_builder})

# gather all public thrust headers
public_thrust_headers = my_env.RecursiveGlob('*.h', '#thrust', exclude='detail')

sources = []

for hdr in public_thrust_headers:
rel_path = Dir('#thrust').rel_path(hdr)

# replace slashes with '_slash_'
src_filename = rel_path.replace('/', '_slash_').replace('\\', '_slash_')

cu = my_env.CUFile(src_filename.replace('.h', '.cu'), hdr)
cpp = my_env.CPPFile(src_filename.replace('.h', '_cpp.cpp'), hdr)

sources.extend([cu,cpp])

# ensure that all files #include <thrust/detail/config.h>
if '#include <thrust/detail/config.h>' not in hdr.get_contents():
warn('Header ' + str(hdr) + ' does not include <thrust/detail/config.h>')

# generate source files which #include all headers
all_headers_cu = my_env.CUFile('all_headers.cu', public_thrust_headers)
all_headers_cpp = my_env.CUFile('all_headers_cpp.cpp', public_thrust_headers)

sources.append(all_headers_cu)
sources.append(all_headers_cpp)

# and the file with main()
sources.append('main.cu')

# build the tester
tester = my_env.Program('tester', sources)

# add the tester to the 'run_tests' alias
tester_alias = my_env.Alias('run_tests', [tester], tester[0].abspath)

# always build the 'run_tests' target whether or not it needs it
my_env.AlwaysBuild(tester_alias)

91 changes: 0 additions & 91 deletions testing/trivial_tests/SConstruct

This file was deleted.

0 comments on commit bc4b1d6

Please sign in to comment.