From 1a5f75dd2daa0945e53f6751e3867eeafdc724f9 Mon Sep 17 00:00:00 2001 From: Ray Speth Date: Wed, 1 Oct 2014 17:52:21 +0000 Subject: [PATCH] [Test] Use Cantera shared library for tests, when possible On Linux systems, link tests against the Cantera shared library, rather than the static library to reduce the size of the compiled test suite. This saves over 1 GB of disk space when compiling with debug symbols enabled, and also reduces the run time of the test suite. This does not work on Windows, where the shared library only exports the Cantera C interface. --- test/SConscript | 17 +++++++++++++---- test_problems/SConscript | 21 +++++++++++++++++---- 2 files changed, 30 insertions(+), 8 deletions(-) diff --git a/test/SConscript b/test/SConscript index 49c5a719d..629a00e06 100644 --- a/test/SConscript +++ b/test/SConscript @@ -5,9 +5,16 @@ from xml.etree import ElementTree Import('env','build','install') localenv = env.Clone() +# Where possible, link tests against the shared libraries to minimize the sizes +# of the resulting binaries. +if localenv['OS'] == 'Linux': + cantera_libs = localenv['cantera_shared_libs'] +else: + cantera_libs = localenv['cantera_libs'] + localenv.Prepend(CPPPATH=['#ext/gtest/include', '#include'], LIBPATH='#build/lib') -localenv.Append(LIBS=['gtest'] + localenv['cantera_libs'], +localenv.Append(LIBS=['gtest'] + cantera_libs, CCFLAGS=env['warning_flags']) # Turn of optimization to speed up compilation @@ -22,9 +29,11 @@ localenv['ENV']['CANTERA_DATA'] = Dir('#build/data').abspath PASSED_FILES = {} # Needed for Intel runtime libraries when compiling with ICC -if 'LD_LIBRARY_PATH' in os.environ: - localenv['ENV']['LD_LIBRARY_PATH'] = os.environ['LD_LIBRARY_PATH'] - +# Add build/lib in order to find Cantera shared library +if localenv['ENV'].get('LD_LIBRARY_PATH'): + localenv['ENV']['LD_LIBRARY_PATH'] += os.pathsep + Dir('#build/lib').abspath +else: + localenv['ENV']['LD_LIBRARY_PATH'] = Dir('#build/lib').abspath def addTestProgram(subdir, progName, env_vars={}): """ diff --git a/test_problems/SConscript b/test_problems/SConscript index 95134699a..e0660a6e2 100644 --- a/test_problems/SConscript +++ b/test_problems/SConscript @@ -12,6 +12,13 @@ for optimize_flag in ('-O3', '-O2', '/O2'): ccflags.remove(optimize_flag) localenv['CCFLAGS'] = ccflags +# Where possible, link tests against the shared libraries to minimize the sizes +# of the resulting binaries. +if localenv['OS'] == 'Linux': + cantera_libs = localenv['cantera_shared_libs'] +else: + cantera_libs = localenv['cantera_libs'] + if localenv['python_package'] in ('full', 'minimal'): localenv['ENV']['PYTHONPATH'] = localenv['pythonpath_build2'] localenv['ENV']['PYTHON_CMD'] = localenv.subst('$python_cmd') @@ -25,6 +32,12 @@ else: localenv['ENV']['CANTERA_DATA'] = pjoin(os.getcwd(), '..', 'build', 'data') +# Add build/lib in order to find Cantera shared library +if localenv['ENV'].get('LD_LIBRARY_PATH'): + localenv['ENV']['LD_LIBRARY_PATH'] += os.pathsep + Dir('#build/lib').abspath +else: + localenv['ENV']['LD_LIBRARY_PATH'] = Dir('#build/lib').abspath + PASSED_FILES = {} @@ -122,7 +135,7 @@ class CompileAndTest(Test): def run(self, env): prog = env.Program(pjoin(self.subdir, self.programName), mglob(env, self.subdir, *self.extensions), - LIBS=env['cantera_libs']) + LIBS=cantera_libs) source = [prog] return Test.run(self, env, *source) @@ -135,7 +148,7 @@ class CompileAndTest(Test): dhGraph = localenv.Program('cathermo/DH_graph_1/DH_graph_1', mglob(env, 'cathermo/DH_graph_1', 'cpp'), - LIBS=env['cantera_libs']) + LIBS=cantera_libs) dhGraph_name = dhGraph[0].name Test('DH_graph_dilute', @@ -255,7 +268,7 @@ CompileAndTest('cxx_ex', 'cxx_ex', 'cxx_examples', 'output_blessed.txt', diamond = localenv.Program('diamondSurf/runDiamond', 'diamondSurf/runDiamond.cpp', - LIBS=env['cantera_libs']) + LIBS=cantera_libs) diamond_name = diamond[0].name Test('diamondSurf-xml', 'diamondSurf', diamond, 'runDiamond_blessed.out', options='diamond_blessed.xml', artifacts=diamond_name) @@ -271,7 +284,7 @@ CompileAndTest('multiGasTransport', negA = localenv.Program('negATest/negATest', mglob(env, 'negATest', 'cpp'), - LIBS=env['cantera_libs']) + LIBS=cantera_libs) negA_name = negA[0].name Test('negA-xml', 'negATest', negA, 'negATest_blessed.out', options='noxNeg_blessed.xml', artifacts=negA_name)