Commit 9d4d3eec authored by GILLES Sebastien's avatar GILLES Sebastien
Browse files

#618 SCons: delete all_libs, and replace it by a new environment variable....

#618 SCons: delete all_libs, and replace it by a new environment variable. Introduce a new custom function to build a givem model.
parent f3df3ee0
......@@ -138,7 +138,7 @@ def Prelink(target, source, env):
return None
def CustomStaticLibrary(env, name, source_file_list, link_libraries_list):
def CustomStaticLibrary(env, name, source_file_list):
"""Create a static library where all the objects have been prelinked in a single one.
The reason for this is that HappyHeart use a FactoryPattern which loads data in the factory before the
......@@ -156,43 +156,56 @@ def CustomStaticLibrary(env, name, source_file_list, link_libraries_list):
# Create the static library from the result of the Prelink builder.
return env.StaticLibrary(name, single_obj_file,
LIBS=link_libraries_list,
LIBS=env["LINK_LIBRARIES_LIST"],
LIBPATH=env['LIBPATH'])
def HappyHeartLibrary(env, name, source_file_list, link_libraries_list):
def HappyHeartLibrary(env, name, source_file_list, suppl_link_libraries = None):
"""Build a library from a list of sources; its nature depends on env["LIBRARY_TYPE"].
\param[in] env Environment.
\param[in] name Name of the library to build. Don't bother with extensions: SCons handles them itself.
\param[in] source_file_list List of source (or object in fact) files to include in the library.
\param[in] link_libraries_list List of libraries against which the new library must be linked. Only for shared ones.
\param[in] suppl_link_libraries List of additional libraries required by the library (env["LINK_LIBRARIES_LIST"] already covers the libraries shared by all HappyHeart libraries. Only relevant for shared libraries.
\return The Library as a SCons node object.
"""
libs = []
if suppl_link_libraries:
libs = suppl_link_libraries
libs.extend(env["LINK_LIBRARIES_LIST"])
if env["LIBRARY_TYPE"] == "static":
return CustomStaticLibrary(env, name, source_file_list, link_libraries_list)
return CustomStaticLibrary(env, name, source_file_list)
else:
return env.SharedLibrary(name, source_file_list, LIBS=link_libraries_list, LIBPATH=env['LIBPATH'])
return env.SharedLibrary(name, source_file_list, LIBS=libs, LIBPATH=env['LIBPATH'])
def HappyHeartProgram(env, name, source_file, link_libraries_list):
def HappyHeartProgram(env, name, source_file, suppl_link_libraries = None):
"""Build a program.
\param[in] env Environment.
\param[in] name Name of the program to build. Don't bother with extensions: SCons handles them itself.
A -static or -shared is added to this name in IntermediateBuild, but does not appear in final build.
\param[in] source_file The source file that include the main (and if you wish other cpp files as well in fact).
\param[in] link_libraries_list List of libraries against which the program must be linked.
\param[in] suppl_link_libraries List of additional libraries required by the program (env["LINK_LIBRARIES_LIST"] already covers the libraries shared by any HappyHeart program).
\return The Program as a SCons node object.
"""
libs = []
if suppl_link_libraries:
libs = suppl_link_libraries
libs.extend(env["LINK_LIBRARIES_LIST"])
program = env.Program('{0}-{1}'.format(name, env["LIBRARY_TYPE"]),
source_file,
LIBS=link_libraries_list,
LIBS=libs,
LIBPATH=env['LIBPATH'])
env.Alias(name, os.path.join(env["TARGET_VARIANT_DIR"], name))
......@@ -379,6 +392,20 @@ def DefineEnvironment(vars):
def BuildModel(env, model_name, all_instances_executable_list, all_instances_library_list, suppl_link_libraries = None):
"""Call the SConscript of a given Model.
\param[in] suppl_link_libraries List of additional libraries required by the program (env["LINK_LIBRARIES_LIST"] already covers the libraries shared by any HappyHeart program).
"""
if not suppl_link_libraries:
(executable_list, library_list) = env.SConscript(os.path.join(model_name, 'SConscript'), ['env'], duplicate=0)
else:
(executable_list, library_list) = env.SConscript(os.path.join(model_name, 'SConscript'), ['env', 'suppl_link_libraries'], duplicate=0)
for executable in executable_list:
all_instances_executable_list.append(executable)
for library in library_list:
all_instances_library_list.append(library)
\ No newline at end of file
......@@ -2,7 +2,7 @@ import os
import copy
import imp
Import('env', 'all_libs')
Import('env')
custom = imp.load_source('custom_scons_functions', '{0}/custom_scons_functions.py'.format(env["HAPPY_HEART_SCONS"]))
......@@ -51,6 +51,6 @@ TimeManager/TimeManagerInstance.cpp
InputParameter/Parameter/Source/AppliedPressure.cpp
''')
core_lib = custom.HappyHeartLibrary(env, 'happy_heart_core', core_src, all_libs)
core_lib = custom.HappyHeartLibrary(env, 'happy_heart_core', core_src)
Return('core_lib')
......@@ -2,7 +2,7 @@ import os
import copy
import imp
Import('env', 'all_libs')
Import('env')
custom = imp.load_source('custom_scons_functions', '{0}/custom_scons_functions.py'.format(env["HAPPY_HEART_SCONS"]))
......@@ -93,6 +93,6 @@ RefFiniteElement/Instantiation/QuadrangleQ1.cpp
RefFiniteElement/Instantiation/HexahedronQ1.cpp
''')
felt_lib = custom.HappyHeartLibrary(env, 'happy_heart_felt', felt_src, all_libs)
felt_lib = custom.HappyHeartLibrary(env, 'happy_heart_felt', felt_src)
Return('felt_lib')
......@@ -2,7 +2,7 @@ import os
import copy
import imp
Import('env', 'all_libs')
Import('env')
custom = imp.load_source('custom_scons_functions', '{0}/custom_scons_functions.py'.format(env["HAPPY_HEART_SCONS"]))
......@@ -14,6 +14,6 @@ DofSourcePolicy/DofSource.cpp
DofSourcePolicy/None.cpp
''')
local_lib = custom.HappyHeartLibrary(env, 'happy_heart_formulation_solver', local_src, all_libs)
local_lib = custom.HappyHeartLibrary(env, 'happy_heart_formulation_solver', local_src)
Return('local_lib')
......@@ -2,7 +2,7 @@ import os
import copy
import imp
Import('env', 'all_libs')
Import('env')
custom = imp.load_source('custom_scons_functions', '{0}/custom_scons_functions.py'.format(env["HAPPY_HEART_SCONS"]))
......@@ -88,7 +88,7 @@ geometry_src = Split('''
./RefGeomElt.cpp
''')
geometry_lib = custom.HappyHeartLibrary(env, 'happy_heart_geometry', geometry_src, all_libs)
geometry_lib = custom.HappyHeartLibrary(env, 'happy_heart_geometry', geometry_src)
Return('geometry_lib')
......@@ -2,7 +2,7 @@ import os
import copy
import imp
Import('env', 'all_libs')
Import('env')
custom = imp.load_source('custom_scons_functions', '{0}/custom_scons_functions.py'.format(env["HAPPY_HEART_SCONS"]))
......@@ -11,13 +11,13 @@ custom = imp.load_source('custom_scons_functions', '{0}/custom_scons_functions.p
bidomain_mitchell_schaeffer = custom.HappyHeartProgram(env,
'Bidomain_MS',
'main_MS.cpp',
[all_libs, ])
[])
bidomain_courtemanche_ramirez_nattel = custom.HappyHeartProgram(env,
'Bidomain_CRN',
'main_CRN.cpp',
[all_libs, ])
[])
......
......@@ -2,7 +2,7 @@ import os
import copy
import imp
Import('env', 'all_libs')
Import('env')
custom = imp.load_source('custom_scons_functions', '{0}/custom_scons_functions.py'.format(env["HAPPY_HEART_SCONS"]))
......@@ -13,14 +13,14 @@ elasticity_src = Split('''
''')
elasticity_lib = custom.HappyHeartLibrary(env, 'happy_heart_elasticity', elasticity_src, all_libs)
elasticity_lib = custom.HappyHeartLibrary(env, 'happy_heart_elasticity', elasticity_src)
main_elasticity_src = Split('''
main.cpp
''')
elasticity = custom.HappyHeartProgram(env, 'elasticity', main_elasticity_src, [elasticity_lib, all_libs])
elasticity = custom.HappyHeartProgram(env, 'elasticity', main_elasticity_src, [elasticity_lib])
list_exec = (elasticity, )
list_lib = (elasticity_lib, )
......
import copy
Import(['env', 'all_libs', 'fsi_requirements_lib', 'HappyHeartLibrary', 'HappyHeartProgram'])
Import(['env', 'fsi_requirements_lib', 'HappyHeartLibrary', 'HappyHeartProgram'])
fsi_ei_src = Split('''
......@@ -12,7 +12,7 @@ fsi_ei_src = Split('''
''')
fsi_ei_lib = HappyHeartLibrary(env, 'happy_heart_fsi_ei', fsi_ei_src, [all_libs, fsi_requirements_lib])
fsi_ei_lib = HappyHeartLibrary(env, 'happy_heart_fsi_ei', fsi_ei_src, [fsi_requirements_lib])
main_fsi_ei_aitken_src = Split('''
......@@ -24,8 +24,8 @@ main_fsi_ei_newton_src = Split('''
''')
fsi_ei_aitken = HappyHeartProgram(env, 'fsi_ei_aitken', main_fsi_ei_aitken_src, [all_libs, fsi_requirements_lib, fsi_ei_lib])
fsi_ei_newton = HappyHeartProgram(env, 'fsi_ei_newton', main_fsi_ei_newton_src, [all_libs, fsi_requirements_lib, fsi_ei_lib])
fsi_ei_aitken = HappyHeartProgram(env, 'fsi_ei_aitken', main_fsi_ei_aitken_src, [fsi_requirements_lib, fsi_ei_lib])
fsi_ei_newton = HappyHeartProgram(env, 'fsi_ei_newton', main_fsi_ei_newton_src, [fsi_requirements_lib, fsi_ei_lib])
list_exec = (fsi_ei_aitken, fsi_ei_newton)
list_lib = (fsi_ei_lib, )
......
......@@ -2,7 +2,7 @@ import os
import copy
import imp
Import('env', 'all_libs', 'fsi_requirements_lib')
Import('env', 'fsi_requirements_lib')
custom = imp.load_source('custom_scons_functions', '{0}/custom_scons_functions.py'.format(env["HAPPY_HEART_SCONS"]))
......@@ -18,7 +18,7 @@ fsi_ei_src = Split('''
''')
fsi_ei_lib = custom.HappyHeartLibrary(env, 'happy_heart_fsi_ei_2_meshes', fsi_ei_src, [all_libs, fsi_requirements_lib])
fsi_ei_lib = custom.HappyHeartLibrary(env, 'happy_heart_fsi_ei_2_meshes', fsi_ei_src, [fsi_requirements_lib])
main_fsi_ei_newton_src = Split('''
......@@ -26,7 +26,7 @@ main_fsi_ei_newton_src = Split('''
''')
fsi_ei_newton_2_meshes = custom.HappyHeartProgram(env, 'fsi_ei_newton_2_meshes', main_fsi_ei_newton_src, [all_libs, fsi_requirements_lib, fsi_ei_lib])
fsi_ei_newton_2_meshes = custom.HappyHeartProgram(env, 'fsi_ei_newton_2_meshes', main_fsi_ei_newton_src, [fsi_requirements_lib, fsi_ei_lib])
list_exec = (fsi_ei_newton_2_meshes, )
list_lib = (fsi_ei_lib, )
......
......@@ -2,7 +2,7 @@ import os
import copy
import imp
Import('env', 'all_libs')
Import('env')
custom = imp.load_source('custom_scons_functions', '{0}/custom_scons_functions.py'.format(env["HAPPY_HEART_SCONS"]))
......@@ -14,7 +14,7 @@ heat_src = Split('''
''')
heat_lib = custom.HappyHeartLibrary(env, 'happy_heart_heat', heat_src, all_libs)
heat_lib = custom.HappyHeartLibrary(env, 'happy_heart_heat', heat_src)
main_heat_src = Split('''
......@@ -22,7 +22,7 @@ main_heat_src = Split('''
''')
heat = custom.HappyHeartProgram(env, 'Heat', main_heat_src, [heat_lib, all_libs])
heat = custom.HappyHeartProgram(env, 'Heat', main_heat_src, [heat_lib])
list_exec = (heat, )
......
......@@ -2,7 +2,7 @@ import os
import copy
import imp
Import('env', 'all_libs')
Import('env')
custom = imp.load_source('custom_scons_functions', '{0}/custom_scons_functions.py'.format(env["HAPPY_HEART_SCONS"]))
......@@ -20,33 +20,33 @@ hyperelasticity_half_sum_src = Split('''
''')
hyperelasticity_midpoint_lib = custom.HappyHeartLibrary(env, 'happy_heart_hyperelasticity_midpoint', hyperelasticity_midpoint_src, all_libs)
hyperelasticity_midpoint_lib = custom.HappyHeartLibrary(env, 'happy_heart_hyperelasticity_midpoint', hyperelasticity_midpoint_src)
hyperelasticity_half_sum_lib = custom.HappyHeartLibrary(env, 'happy_heart_hyperelasticity_half_sum', hyperelasticity_half_sum_src, all_libs)
hyperelasticity_half_sum_lib = custom.HappyHeartLibrary(env, 'happy_heart_hyperelasticity_half_sum', hyperelasticity_half_sum_src)
hyperelasticity1 = custom.HappyHeartProgram(env,
'hyperelasticity_CG_half_sum',
'main_ciarlet_geymonat_half_sum.cpp',
[hyperelasticity_half_sum_lib, all_libs, ])
[hyperelasticity_half_sum_lib, ])
hyperelasticity2 = custom.HappyHeartProgram(env,
'hyperelasticity_CG_midpoint',
'main_ciarlet_geymonat_midpoint.cpp',
[hyperelasticity_midpoint_lib, all_libs, ])
[hyperelasticity_midpoint_lib, ])
hyperelasticity3 = custom.HappyHeartProgram(env,
'hyperelasticity_StVK_half_sum',
'main_st_venant_kirchhoff_half_sum.cpp',
[hyperelasticity_half_sum_lib, all_libs, ])
[hyperelasticity_half_sum_lib, ])
hyperelasticity4 = custom.HappyHeartProgram(env,
'hyperelasticity_StVK_midpoint',
'main_st_venant_kirchhoff_midpoint.cpp',
[hyperelasticity_midpoint_lib, all_libs, ])
[hyperelasticity_midpoint_lib, ])
......
......@@ -2,7 +2,7 @@ import os
import copy
import imp
Import('env', 'all_libs')
Import('env')
custom = imp.load_source('custom_scons_functions', '{0}/custom_scons_functions.py'.format(env["HAPPY_HEART_SCONS"]))
......@@ -21,11 +21,11 @@ main_courtemancheramireznattell_src = Split('''
''')
reaction_diffusion_fitzhughnagumo = custom.HappyHeartProgram(env, 'ReactionDiffusion_FHN', main_fitzhughnagumo_src, [all_libs])
reaction_diffusion_fitzhughnagumo = custom.HappyHeartProgram(env, 'ReactionDiffusion_FHN', main_fitzhughnagumo_src)
reaction_diffusion_mitchellschaeffer = custom.HappyHeartProgram(env, 'ReactionDiffusion_MS', main_mitchellschaeffer_src, [all_libs])
reaction_diffusion_mitchellschaeffer = custom.HappyHeartProgram(env, 'ReactionDiffusion_MS', main_mitchellschaeffer_src)
reaction_diffusion_courtemancheramireznattell = custom.HappyHeartProgram(env, 'ReactionDiffusion_CRN', main_courtemancheramireznattell_src, [all_libs])
reaction_diffusion_courtemancheramireznattell = custom.HappyHeartProgram(env, 'ReactionDiffusion_CRN', main_courtemancheramireznattell_src)
list_exec = (reaction_diffusion_fitzhughnagumo, reaction_diffusion_mitchellschaeffer, reaction_diffusion_courtemancheramireznattell)
......
......@@ -2,7 +2,7 @@ import os
import copy
import imp
Import(['env', 'all_libs'])
Import(['env'])
custom = imp.load_source('custom_scons_functions', '{0}/custom_scons_functions.py'.format(env["HAPPY_HEART_SCONS"]))
......@@ -13,7 +13,7 @@ rivlin_src = Split('''
''')
rivlin_lib = custom.HappyHeartLibrary(env, 'happy_heart_rivlin', rivlin_src, [all_libs])
rivlin_lib = custom.HappyHeartLibrary(env, 'happy_heart_rivlin', rivlin_src)
main_rivlin_src = Split('''
......@@ -21,7 +21,7 @@ main_rivlin_src = Split('''
''')
rivlin = custom.HappyHeartProgram(env, 'RivlinCube', main_rivlin_src, [all_libs, rivlin_lib])
rivlin = custom.HappyHeartProgram(env, 'RivlinCube', main_rivlin_src, [rivlin_lib])
list_exec = (rivlin, )
......
......@@ -2,7 +2,7 @@ import os
import copy
import imp
Import('env', 'all_libs')
Import('env')
custom = imp.load_source('custom_scons_functions', '{0}/custom_scons_functions.py'.format(env["HAPPY_HEART_SCONS"]))
......@@ -20,15 +20,8 @@ problems = ("Hyperelasticity", \
"RivlinCube"
)
for problem in problems:
(executable_list, library_list) = SConscript(os.path.join(problem, 'SConscript'), ['env', 'all_libs'], duplicate=0)
for executable in executable_list:
all_instances_executable_list.append(executable)
for library in library_list:
all_instances_library_list.append(library)
custom.BuildModel(env, problem, all_instances_executable_list, all_instances_library_list)
# ------------------------------------------------------------------
# Handle apart FSI case which need hyperelastic library.
......@@ -36,7 +29,7 @@ for problem in problems:
fsi_requirements_lib = [lib for lib in all_instances_library_list if str(lib)[2:].startswith('Hyperelasticity/')]
(executable_list, library_list) = SConscript(os.path.join("FSI_EI_2_meshes", 'SConscript'),
['env', 'all_libs', 'fsi_requirements_lib'],
['env', 'fsi_requirements_lib'],
duplicate=0)
for executable in executable_list:
......
......@@ -2,7 +2,7 @@ import os
import copy
import imp
Import('env', 'all_libs')
Import('env')
custom = imp.load_source('custom_scons_functions', '{0}/custom_scons_functions.py'.format(env["HAPPY_HEART_SCONS"]))
......@@ -14,13 +14,13 @@ stokes_src = Split('''
stokes_lib = custom.HappyHeartLibrary(env, 'happy_heart_stokes', stokes_src, all_libs)
stokes_lib = custom.HappyHeartLibrary(env, 'happy_heart_stokes', stokes_src)
main_stokes_src = Split('''
main.cpp
''')
stokes = custom.HappyHeartProgram(env, 'stokes', main_stokes_src, [stokes_lib, all_libs])
stokes = custom.HappyHeartProgram(env, 'stokes', main_stokes_src, [stokes_lib])
list_exec = (stokes, )
list_lib = (stokes_lib, )
......
......@@ -2,7 +2,7 @@ import os
import copy
import imp
Import('env', 'all_libs')
Import('env')
custom = imp.load_source('custom_scons_functions', '{0}/custom_scons_functions.py'.format(env["HAPPY_HEART_SCONS"]))
......@@ -11,14 +11,14 @@ custom = imp.load_source('custom_scons_functions', '{0}/custom_scons_functions.p
surfacicbidomain_courtemanche_ramirez_nattel = custom.HappyHeartProgram(env,
'SurfacicBidomain_CRN',
'main_CRN.cpp',
[all_libs, ])
[])
surfacicbidomain_mitchell_schaeffer = custom.HappyHeartProgram(env,
'SurfacicBidomain_MS',
'main_MS.cpp',
[all_libs, ])
[])
list_exec = (surfacicbidomain_courtemanche_ramirez_nattel, surfacicbidomain_mitchell_schaeffer)
......
......@@ -2,7 +2,7 @@ import os
import copy
import imp
Import('env', 'all_libs')
Import('env')
custom = imp.load_source('custom_scons_functions', '{0}/custom_scons_functions.py'.format(env["HAPPY_HEART_SCONS"]))
......@@ -57,6 +57,6 @@ src = Split('''
./NonConformInterpolator/FromVertexMatching.cpp
''')
lib = custom.HappyHeartLibrary(env, 'happy_heart_operators', src, all_libs)
lib = custom.HappyHeartLibrary(env, 'happy_heart_operators', src)
Return('lib')
......@@ -2,7 +2,7 @@ import os
import copy
import imp
Import('env', 'all_libs')
Import('env')
custom = imp.load_source('custom_scons_functions', '{0}/custom_scons_functions.py'.format(env["HAPPY_HEART_SCONS"]))
......@@ -17,7 +17,7 @@ Instances/ThreeDimensionalParameter.cpp
Policy/Private/AtDof.cpp
''')
lib = custom.HappyHeartLibrary(env, 'happy_heart_parameters', src, all_libs)
lib = custom.HappyHeartLibrary(env, 'happy_heart_parameters', src)
Return('lib')
......@@ -2,7 +2,7 @@ import os
import copy
import imp
Import('env', 'all_libs')
Import('env')
custom = imp.load_source('custom_scons_functions', '{0}/custom_scons_functions.py'.format(env["HAPPY_HEART_SCONS"]))
......@@ -20,7 +20,7 @@ Private/TimeIterationFile.cpp
Private/UnknownInformationFile.cpp
''')
post_processing_lib = custom.HappyHeartLibrary(env, 'happy_heart_post_processing', post_processing_src, all_libs)
post_processing_lib = custom.HappyHeartLibrary(env, 'happy_heart_post_processing', post_processing_src)
......@@ -30,7 +30,7 @@ main_compute_ensight_output_src = Split('''
compute_ensight_output = env.Program('compute_ensight_output-{0}'.format(env["LIBRARY_TYPE"]),
main_compute_ensight_output_src,
LIBS=[all_libs, post_processing_lib],
LIBS=[post_processing_lib],
LIBPATH=env['LIBPATH'])
executable_list = []
......
......@@ -68,11 +68,11 @@ libraries = ('Utilities', 'Core', 'Geometry', 'FiniteElement', 'Parameters', 'Op
# List of all libraries, as strings without path. For instance ['libhappy_heart_utilities.dylib', 'libhappy_heart_core.dylib'].
happy_heart_libs = []
all_libs = copy.copy(env['THIRD_PARTY_LIBRARIES'])
#
env["LINK_LIBRARIES_LIST"] = copy.copy(env['THIRD_PARTY_LIBRARIES'])
if platform == 'Linux':
all_libs.extend(link_flags)
env["LINK_LIBRARIES_LIST"].extend(link_flags)
# Iterate through the SConscript of all the libraries to build.
......@@ -84,7 +84,7 @@ for library in libraries:
variant_dir=os.path.join(env['CURRENT_BUILD_INTERMEDIATE_DIR'], library)
scons_library_object = SConscript(os.path.join(library, 'SConscript'),
exports=['env', 'all_libs'],
exports=['env'],
variant_dir=variant_dir,
duplicate=0)
......@@ -97,7 +97,7 @@ for library in libraries:
# Update the list of known libraries so far.
happy_heart_libs.append(libname)
all_libs = [libname] + all_libs
env["LINK_LIBRARIES_LIST"].insert(0, libname)
env.Alias('libraries', libs_for_alias)
......@@ -108,12 +108,12 @@ env.Alias('libraries', libs_for_alias)
# when writing a new model).
#---------------------------------------------------
(executable_list, exec_library_list) = SConscript('ModelInstances/SConscript',
exports=(['env', 'all_libs']),
exports=(['env']),
variant_dir=os.path.join(env['CURRENT_BUILD_INTERMEDIATE_DIR'], 'ModelInstances'),
duplicate=0)
list_test_exec = SConscript('Test/SConscript',
exports=(['env', 'all_libs']),
exports=(['env']),
variant_dir=os.path.join(env['CURRENT_BUILD_INTERMEDIATE_DIR'], 'Tests'),
duplicate=0)
......@@ -124,7 +124,7 @@ executable_list.extend(list_test_exec)
#---------------------------------------------------------
(post_processing_exec, post_processing_lib) = SConscript('PostProcessing/SConscript',
exports=(['env', 'all_libs']),
exports=(['env']),
variant_dir=os.path.join(env['CURRENT_BUILD_INTERMEDIATE_DIR'], 'PostProcessing'),
duplicate=0)
......