Skip to content

Commit f48f48d

Browse files
committed
Add scons build flag test_installed.
When set, build unit tests for an already installed library.
1 parent 9bc6c80 commit f48f48d

4 files changed

Lines changed: 32 additions & 14 deletions

File tree

SConstruct

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ vars = Variables('sconsvars.py')
4545

4646
vars.Add('tests',
4747
'Fixed-string patterns for selecting unit test sources.', None)
48+
vars.Add(BoolVariable('test_installed',
49+
'build unit tests using the installed library.', False))
4850
vars.Add(EnumVariable('build',
4951
'compiler settings', 'fast',
5052
allowed_values=('debug', 'fast')))

conda-recipe/build.sh

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,8 @@ MYNCPU=$(( (CPU_COUNT > 8) ? 8 : CPU_COUNT ))
1212
# Apply sconscript.local customizations.
1313
cp ${RECIPE_DIR}/sconscript.local ./
1414

15-
# Build the library and unit test program.
16-
scons -j $MYNCPU lib alltests
15+
# Build and install the library.
16+
scons -j $MYNCPU lib install prefix=$PREFIX
1717

18-
# Execute unit tests.
19-
scons test
20-
21-
# Install the library.
22-
scons install prefix=$PREFIX
18+
# Execute unit tests for the installed library.
19+
scons -j $MYNCPU test prefix=$PREFIX test_installed=yes

src/SConscript

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,15 @@ env['lib_datafiles'] = []
7777

7878
# Subsidiary SConscripts -----------------------------------------------------
7979

80+
# Determine if unit tests need to be built.
81+
build_tests = set(('test', 'alltests')).intersection(COMMAND_LINE_TARGETS)
82+
83+
# Short circuit if we test an already installed library. Do not define
84+
# any further targets as they may conflict with the installed files.
85+
if build_tests and env['test_installed']:
86+
SConscript('tests/SConscript')
87+
Return()
88+
8089
# Load the version script first to resolve the majorminor tuple
8190
SConscript('diffpy/SConscript.version')
8291

@@ -104,7 +113,8 @@ Default(lib)
104113

105114
# Define targets related to testing. Do so only when testing is requested.
106115
# This enables library build on machines without cxxtest.
107-
if set(('test', 'alltests')).intersection(COMMAND_LINE_TARGETS):
116+
if build_tests:
117+
assert not env['test_installed']
108118
SConscript('tests/SConscript')
109119

110120
# Installation targets.

src/tests/SConscript

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,27 @@
11
import os
22
import re
33

4-
Import('env', 'GlobSources', 'libdiffpy')
4+
Import('env', 'GlobSources')
55

66
# Environment for building unit test driver
77
env_test = env.Clone(CXXTEST_SUFFIX='.hpp')
88
env_test.Tool('cxxtest')
9-
lib_dir = libdiffpy[0].dir.abspath
9+
10+
if env['test_installed']:
11+
# build unit tests for the installed library
12+
env_test['CPPPATH'].remove(Dir('..'))
13+
env_test.PrependUnique(CPPPATH=env['includedir'], delete_existing=1)
14+
env_test['lib_includes'] = []
15+
lib_dir = env['libdir']
16+
else:
17+
# build unit tests for this code repository
18+
Import('libdiffpy')
19+
lib_dir = libdiffpy[0].dir.abspath
20+
1021
env_test.PrependUnique(LIBS='diffpy', LIBPATH=lib_dir, delete_existing=1)
1122
env_test.PrependUnique(LINKFLAGS="-Wl,-rpath,%r" % lib_dir)
12-
# Ensure shared libraries will be found for conda-build.
13-
if os.environ.get('CONDA_BUILD'):
14-
conda_lib = os.environ['PREFIX'] + '/lib'
15-
env_test.AppendUnique(LINKFLAGS="-Wl,-rpath,%r" % conda_lib)
23+
24+
# Use only libraries needed for building the unit tests.
1625
pat = 'diffpy|boost_serialization|ObjCryst'
1726
keeplibs = lambda s: re.search(pat, str(s))
1827
env_test.Replace(LIBS=filter(keeplibs, env_test['LIBS']))

0 commit comments

Comments
 (0)