From 5cb40cbcd2d9b6a95515de99bb6b3cc7fae14787 Mon Sep 17 00:00:00 2001 From: Todd Gamblin Date: Wed, 11 May 2022 15:36:46 -0700 Subject: directory_layout: remove outdated checks for old DAG hash We previously had checks in `directory_layout` to check for build-dependency conflicts when we weren't storing build dependencies. We don't need those anymore; we can just rely on the DAG hash now that it includes everything we know about each spec. - [x] Remove vestigial code for checking installed spec against concrete spec in `ensure_installed()` - [x] Remove `SpecHashCollisionError` -- if specs have the same hash now, they're the same as far as `DirectoryLayout` should be concerned. - [x] Convert spec comparison to `dag_hash()` comparison when adding extensions. --- lib/spack/spack/directory_layout.py | 39 +++++------------------------- lib/spack/spack/environment/environment.py | 1 - 2 files changed, 6 insertions(+), 34 deletions(-) diff --git a/lib/spack/spack/directory_layout.py b/lib/spack/spack/directory_layout.py index 56ba01c7b4..3ccec788d8 100644 --- a/lib/spack/spack/directory_layout.py +++ b/lib/spack/spack/directory_layout.py @@ -238,10 +238,10 @@ class DirectoryLayout(object): def ensure_installed(self, spec): """ - Throws DirectoryLayoutError if: + Throws InconsistentInstallDirectoryError if: 1. spec prefix does not exist - 2. spec prefix does not contain a spec file - 3. the spec file does not correspond to the spec + 2. spec prefix does not contain a spec file, or + 3. We read a spec with the wrong DAG hash out of an existing install directory. """ _check_concrete(spec) path = self.path_for_spec(spec) @@ -257,25 +257,7 @@ class DirectoryLayout(object): " " + path) installed_spec = self.read_spec(spec_file_path) - if installed_spec == spec: - return - - # DAG hashes currently do not include build dependencies. - # - # TODO: remove this when we do better concretization and don't - # ignore build-only deps in hashes. - elif (installed_spec.copy(deps=('link', 'run')) == - spec.copy(deps=('link', 'run'))): - # The directory layout prefix is based on the dag hash, so among - # specs with differing full-hash but matching dag-hash, only one - # may be installed. This means for example that for two instances - # that differ only in CMake version used to build, only one will - # be installed. - return - - if spec.dag_hash() == installed_spec.dag_hash(): - raise SpecHashCollisionError(spec, installed_spec) - else: + if installed_spec.dag_hash() != spec.dag_hash(): raise InconsistentInstallDirectoryError( 'Spec file in %s does not match hash!' % spec_file_path) @@ -463,8 +445,8 @@ class YamlViewExtensionsLayout(ExtensionsLayout): def check_extension_conflict(self, spec, ext_spec): exts = self._extension_map(spec) if ext_spec.name in exts: - installed_spec = exts[ext_spec.name].copy(deps=('link', 'run')) - if ext_spec.copy(deps=('link', 'run')) == installed_spec: + installed_spec = exts[ext_spec.name] + if ext_spec.dag_hash() == installed_spec.dag_hash(): raise ExtensionAlreadyInstalledError(spec, ext_spec) else: raise ExtensionConflictError(spec, ext_spec, installed_spec) @@ -584,15 +566,6 @@ class DirectoryLayoutError(SpackError): super(DirectoryLayoutError, self).__init__(message, long_msg) -class SpecHashCollisionError(DirectoryLayoutError): - """Raised when there is a hash collision in an install layout.""" - - def __init__(self, installed_spec, new_spec): - super(SpecHashCollisionError, self).__init__( - 'Specs %s and %s have the same SHA-1 prefix!' - % (installed_spec, new_spec)) - - class RemoveFailedError(DirectoryLayoutError): """Raised when a DirectoryLayout cannot remove an install prefix.""" diff --git a/lib/spack/spack/environment/environment.py b/lib/spack/spack/environment/environment.py index 6ed4297fca..8c71deb561 100644 --- a/lib/spack/spack/environment/environment.py +++ b/lib/spack/spack/environment/environment.py @@ -1828,7 +1828,6 @@ class Environment(object): spec = Spec.from_node_dict(node_dict) if not spec._hash: # in v1 lockfiles, the hash only occurs as a key - print("HERE") spec._hash = lockfile_key specs_by_hash[lockfile_key] = spec -- cgit v1.2.3-70-g09d2