From 1fa38689d87480bb0d291af9b9cf0dbcf7557eb5 Mon Sep 17 00:00:00 2001 From: Gregory Becker Date: Fri, 18 Mar 2016 09:35:56 -0700 Subject: Created flatten_dependencies function that dummy packages can use to create sane install environments. --- lib/spack/spack/directory_layout.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'lib') diff --git a/lib/spack/spack/directory_layout.py b/lib/spack/spack/directory_layout.py index 242eb1afa0..9f17404062 100644 --- a/lib/spack/spack/directory_layout.py +++ b/lib/spack/spack/directory_layout.py @@ -33,6 +33,7 @@ import yaml import llnl.util.tty as tty from llnl.util.filesystem import join_path, mkdirp +from llnl.util.link_tree import * from spack.spec import Spec from spack.error import SpackError @@ -131,6 +132,23 @@ class DirectoryLayout(object): raise NotImplementedError() + def flatten_dependencies(self, 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 = self.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 path_for_spec(self, spec): """Return an absolute path from the root to a directory for the spec.""" _check_concrete(spec) -- cgit v1.2.3-60-g2f50 From 80495e50f9b3a5de6d0aadb054a770a685939e79 Mon Sep 17 00:00:00 2001 From: Gregory Becker Date: Fri, 18 Mar 2016 09:46:18 -0700 Subject: added error class for error that should never come up --- lib/spack/spack/directory_layout.py | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'lib') diff --git a/lib/spack/spack/directory_layout.py b/lib/spack/spack/directory_layout.py index 9f17404062..dfd0dc42e4 100644 --- a/lib/spack/spack/directory_layout.py +++ b/lib/spack/spack/directory_layout.py @@ -498,3 +498,10 @@ class NoSuchExtensionError(DirectoryLayoutError): super(NoSuchExtensionError, self).__init__( "%s cannot be removed from %s because it's not activated."% ( ext_spec.short_spec, spec.short_spec)) + +class DependencyConflictError(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)) -- cgit v1.2.3-60-g2f50 From 76672a4e34e37aec0223e67d140fd19e9115b5a6 Mon Sep 17 00:00:00 2001 From: Gregory Becker Date: Fri, 18 Mar 2016 11:28:44 -0700 Subject: Refactoring flat_install --- lib/spack/spack/__init__.py | 3 +++ lib/spack/spack/directory_layout.py | 24 ------------------------ lib/spack/spack/package.py | 30 ++++++++++++++++++++++++++++++ 3 files changed, 33 insertions(+), 24 deletions(-) (limited to 'lib') diff --git a/lib/spack/spack/__init__.py b/lib/spack/spack/__init__.py index ab78ecef30..155e190597 100644 --- a/lib/spack/spack/__init__.py +++ b/lib/spack/spack/__init__.py @@ -174,3 +174,6 @@ __all__ += spack.directives.__all__ import spack.util.executable from spack.util.executable import * __all__ += spack.util.executable.__all__ + +from spack.package import flat_install, flatten_dependencies, DependencyConflictError +__all__ += ['flat_install', 'flatten_dependencies', 'DependencyConflictError'] diff --git a/lib/spack/spack/directory_layout.py b/lib/spack/spack/directory_layout.py index dfd0dc42e4..e275031387 100644 --- a/lib/spack/spack/directory_layout.py +++ b/lib/spack/spack/directory_layout.py @@ -132,23 +132,6 @@ class DirectoryLayout(object): raise NotImplementedError() - def flatten_dependencies(self, 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 = self.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 path_for_spec(self, spec): """Return an absolute path from the root to a directory for the spec.""" _check_concrete(spec) @@ -498,10 +481,3 @@ class NoSuchExtensionError(DirectoryLayoutError): super(NoSuchExtensionError, self).__init__( "%s cannot be removed from %s because it's not activated."% ( ext_spec.short_spec, spec.short_spec)) - -class DependencyConflictError(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)) diff --git a/lib/spack/spack/package.py b/lib/spack/spack/package.py index 972a0410b9..1a962268cf 100644 --- a/lib/spack/spack/package.py +++ b/lib/spack/spack/package.py @@ -1211,6 +1211,28 @@ class Package(object): return " ".join("-Wl,-rpath,%s" % p for p in self.rpath) +def flat_install(pkg, spec, prefix): + """Execute a dummy install and flatten dependencies""" + os.mkdir(prefix+'/libs') + flatten_dependencies(spec, prefix+'/libs') + +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) @@ -1348,3 +1370,11 @@ class ExtensionConflictError(ExtensionError): 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)) -- cgit v1.2.3-60-g2f50 From af7e3cadde02b2ab9b6de2c588a41663141928dd Mon Sep 17 00:00:00 2001 From: Gregory Becker Date: Fri, 18 Mar 2016 11:34:07 -0700 Subject: cleanup --- lib/spack/spack/directory_layout.py | 1 - 1 file changed, 1 deletion(-) (limited to 'lib') diff --git a/lib/spack/spack/directory_layout.py b/lib/spack/spack/directory_layout.py index e275031387..242eb1afa0 100644 --- a/lib/spack/spack/directory_layout.py +++ b/lib/spack/spack/directory_layout.py @@ -33,7 +33,6 @@ import yaml import llnl.util.tty as tty from llnl.util.filesystem import join_path, mkdirp -from llnl.util.link_tree import * from spack.spec import Spec from spack.error import SpackError -- cgit v1.2.3-60-g2f50 From 151b04637ef01b8cde5967df6165bd245311b90a Mon Sep 17 00:00:00 2001 From: Gregory Becker Date: Fri, 18 Mar 2016 11:55:31 -0700 Subject: changed function name and removed hardcoded libs dir --- lib/spack/spack/__init__.py | 4 ++-- lib/spack/spack/package.py | 5 ++--- 2 files changed, 4 insertions(+), 5 deletions(-) (limited to 'lib') diff --git a/lib/spack/spack/__init__.py b/lib/spack/spack/__init__.py index 155e190597..5d62d597cb 100644 --- a/lib/spack/spack/__init__.py +++ b/lib/spack/spack/__init__.py @@ -175,5 +175,5 @@ import spack.util.executable from spack.util.executable import * __all__ += spack.util.executable.__all__ -from spack.package import flat_install, flatten_dependencies, DependencyConflictError -__all__ += ['flat_install', 'flatten_dependencies', 'DependencyConflictError'] +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 1a962268cf..4c458522e0 100644 --- a/lib/spack/spack/package.py +++ b/lib/spack/spack/package.py @@ -1211,10 +1211,9 @@ class Package(object): return " ".join("-Wl,-rpath,%s" % p for p in self.rpath) -def flat_install(pkg, spec, prefix): +def install_dependency_symlinks(pkg, spec, prefix): """Execute a dummy install and flatten dependencies""" - os.mkdir(prefix+'/libs') - flatten_dependencies(spec, prefix+'/libs') + flatten_dependencies(spec, prefix) def flatten_dependencies(spec, flat_dir): """Make each dependency of spec present in dir via symlink.""" -- cgit v1.2.3-60-g2f50