diff --git a/SConstruct b/SConstruct index fd35f7938..72c9648bf 100644 --- a/SConstruct +++ b/SConstruct @@ -1036,11 +1036,14 @@ if env['build_docs']: SConscript('doc/SConscript') if 'samples' in COMMAND_LINE_TARGETS or 'install' in COMMAND_LINE_TARGETS: + sampledir_excludes = ['ct2ctml', '\\.o$', '^~$', 'xml$', '\\.in', + 'SConscript', 'Makefile.am'] SConscript('samples/cxx/SConscript') # Install C++ samples inst = env.RecursiveInstall(pjoin('$inst_sampledir', 'cxx'), - 'samples/cxx') + 'samples/cxx', + exclude=sampledir_excludes) installTargets.extend(inst) if env['f90_interface'] == 'y': @@ -1049,9 +1052,11 @@ if 'samples' in COMMAND_LINE_TARGETS or 'install' in COMMAND_LINE_TARGETS: if env['addInstallTargets'] and env['f90_interface'] == 'y': # install F90 / F77 samples - inst = env.RecursiveInstall(pjoin('$inst_sampledir', 'f77'), 'samples/f77') + inst = env.RecursiveInstall(pjoin('$inst_sampledir', 'f77'), + 'samples/f77', sampledir_excludes) installTargets.extend(inst) - inst = env.RecursiveInstall(pjoin('$inst_sampledir', 'f90'), 'samples/f90') + inst = env.RecursiveInstall(pjoin('$inst_sampledir', 'f90'), + 'samples/f90', sampledir_excludes) installTargets.extend(inst) diff --git a/site_scons/site_tools/recursiveInstall.py b/site_scons/site_tools/recursiveInstall.py index 70b473ad8..197e95b31 100644 --- a/site_scons/site_tools/recursiveInstall.py +++ b/site_scons/site_tools/recursiveInstall.py @@ -1,6 +1,7 @@ import os +import re -def RecursiveInstall(env, target, dir): +def RecursiveInstall(env, target, dir, exclude=None): """ This tool adds the builder: @@ -12,6 +13,9 @@ def RecursiveInstall(env, target, dir): and if any thing in dir_source is updated the install is rerun + 'exclude' is a list of regular expression patterns for files + to skip, e.g. ['\\.o$', '^~'] + It behaves similar to the env.Install builtin. However it expects two directories and correctly sets up the dependencies between each sub file instead of just between the two directories. @@ -27,7 +31,12 @@ def RecursiveInstall(env, target, dir): and see the one to one correspondence between source and target files within each directory. """ - nodes = _recursive_install(env, dir) + if exclude: + excludePatterns = [re.compile(e) for e in exclude] + else: + excludePatterns = [] + + nodes = _recursive_install(env, dir, excludePatterns) dir = env.Dir(dir).abspath target = env.Dir(target).abspath @@ -45,14 +54,22 @@ def RecursiveInstall(env, target, dir): return out -def _recursive_install(env, path): +def _recursive_install(env, path, exclude): """ Helper function for RecursiveInstall """ nodes = env.Glob(os.path.join(path, '*'), strings=False) nodes.extend(env.Glob(os.path.join(path, '*.*'), strings=False)) out = [] for n in nodes: + skip = False + for e in exclude: + if e.search(n.name): + skip = True + break + if skip: + continue + if n.isdir(): - out.extend(_recursive_install(env, n.abspath)) + out.extend(_recursive_install(env, n.abspath, exclude)) else: out.append(n)