diff --git a/lib/spack/spack/__init__.py b/lib/spack/spack/__init__.py index 3051d3f7427..0ba42bbbfcd 100644 --- a/lib/spack/spack/__init__.py +++ b/lib/spack/spack/__init__.py @@ -188,3 +188,6 @@ import spack.util.executable from spack.util.executable import * __all__ += spack.util.executable.__all__ + +from spack.package import install_dependency_symlinks, flatten_dependencies, DependencyConflictError +__all__ += ['install_dependency_symlinks', 'flatten_dependencies', 'DependencyConflictError'] diff --git a/lib/spack/spack/package.py b/lib/spack/spack/package.py index 291056a7b93..b488e4c49db 100644 --- a/lib/spack/spack/package.py +++ b/lib/spack/spack/package.py @@ -1243,6 +1243,27 @@ def rpath_args(self): return " ".join("-Wl,-rpath,%s" % p for p in self.rpath) +def install_dependency_symlinks(pkg, spec, prefix): + """Execute a dummy install and flatten dependencies""" + flatten_dependencies(spec, prefix) + +def flatten_dependencies(spec, flat_dir): + """Make each dependency of spec present in dir via symlink.""" + for dep in spec.traverse(root=False): + name = dep.name + + dep_path = spack.install_layout.path_for_spec(dep) + dep_files = LinkTree(dep_path) + + os.mkdir(flat_dir+'/'+name) + + conflict = dep_files.find_conflict(flat_dir+'/'+name) + if conflict: + raise DependencyConflictError(conflict) + + dep_files.merge(flat_dir+'/'+name) + + def validate_package_url(url_string): """Determine whether spack can handle a particular URL or not.""" url = urlparse(url_string) @@ -1380,3 +1401,11 @@ def __init__(self, path): class ActivationError(ExtensionError): def __init__(self, msg, long_msg=None): super(ActivationError, self).__init__(msg, long_msg) + + +class DependencyConflictError(spack.error.SpackError): + """Raised when the dependencies cannot be flattened as asked for.""" + def __init__(self, conflict): + super(DependencyConflictError, self).__init__( + "%s conflicts with another file in the flattened directory." %( + conflict))