install_tree: symlink handling and add 'ignore' option (#9019)

Fixes #9001

#8289 added support for install_tree and copy_tree to merge into an existing
directory structure. However, it did not properly handle relative symlinks and
also removed support for the 'ignore' keyword. Additionally, some of the tests
were overly-strict when checking the permissions on the copied files.

This updates the install_tree/copy_tree methods and their tests:

* copy_tree/install_tree now preserve relative link targets (if the symlink in the
  source directory structure is relative, the symlink created in the destination
  will be relative)
* Added support for 'ignore' argument back to copy_tree/install_tree (removed
  in #8289). It is no longer the object output by shutil.ignore_patterns: you pass a
  function that accepts a path relative to the source and returns whether that
  path should be copied.
* The openfoam packages (currently the only ones making use of the 'ignore'
  argument) are updated for the new API
* When a symlink target is absolute, copy_tree and install_tree now rewrite the
  source prefix to be the destination prefix
* copy_tree tests no longer check permissions: copy_tree doesn't enforce
  anything about permissions so its tests don't check for that
* install_tree tests no longer check for exact permission matching since it can add
  file permissions
This commit is contained in:
scheibelp
2018-08-17 22:08:38 -04:00
committed by GitHub
parent a7a6745120
commit 638cc64571
5 changed files with 98 additions and 30 deletions

View File

@@ -54,7 +54,6 @@
##############################################################################
import glob
import re
import shutil
import os
from spack import *
@@ -382,7 +381,6 @@ def build(self, spec, prefix):
def install(self, spec, prefix):
"""Install under the projectdir"""
opts = str(self.foam_arch)
# Fairly ugly since intermediate targets are scattered inside sources
appdir = 'applications'
@@ -419,19 +417,22 @@ def install(self, spec, prefix):
subitem = join_path(appdir, 'Allwmake')
install(subitem, join_path(self.projectdir, subitem))
ignored = [opts] # Ignore intermediate targets
foam_arch_str = str(self.foam_arch)
# Ignore intermediate targets
ignore = lambda p: os.path.basename(p) == foam_arch_str
for d in ['src', 'tutorials']:
install_tree(
d,
join_path(self.projectdir, d),
ignore=shutil.ignore_patterns(*ignored),
ignore=ignore,
symlinks=True)
for d in ['solvers', 'utilities']:
install_tree(
join_path(appdir, d),
join_path(self.projectdir, appdir, d),
ignore=shutil.ignore_patterns(*ignored),
ignore=ignore,
symlinks=True)
etc_dir = join_path(self.projectdir, 'etc')

View File

@@ -60,7 +60,6 @@
##############################################################################
import glob
import re
import shutil
import os
from spack import *
@@ -692,12 +691,13 @@ def install(self, spec, prefix):
dirs.extend(['doc'])
# Install platforms (and doc) skipping intermediate targets
ignored = ['src', 'applications', 'html', 'Guides']
relative_ignore_paths = ['src', 'applications', 'html', 'Guides']
ignore = lambda p: p in relative_ignore_paths
for d in dirs:
install_tree(
d,
join_path(self.projectdir, d),
ignore=shutil.ignore_patterns(*ignored),
ignore=ignore,
symlinks=True)
etc_dir = join_path(self.projectdir, 'etc')

View File

@@ -55,7 +55,6 @@
##############################################################################
import glob
import re
import shutil
import os
import llnl.util.tty as tty
@@ -345,12 +344,13 @@ def install(self, spec, prefix):
dirs.extend(['doc'])
# Install platforms (and doc) skipping intermediate targets
ignored = ['src', 'applications', 'html', 'Guides']
relative_ignore_paths = ['src', 'applications', 'html', 'Guides']
ignore = lambda p: p in relative_ignore_paths
for d in dirs:
install_tree(
d,
join_path(self.projectdir, d),
ignore=shutil.ignore_patterns(*ignored),
ignore=ignore,
symlinks=True)
etc_dir = join_path(self.projectdir, 'etc')