database: don't warn adding missing build deps (#33361)

When installing an individual spec `spack --only=package --cache-only /xyz`
from a buildcache, Spack currently issues tons of warnings about
missing build deps (and their deps) in the database.

This PR disables these warnings, since it's fine to have a spec without
its build deps in the db (they are just "missing").
This commit is contained in:
Harmen Stoppels 2022-10-17 18:30:19 +02:00 committed by GitHub
parent 839cf48352
commit e7b14dd491
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -48,7 +48,10 @@
import spack.store
import spack.util.lock as lk
import spack.util.spack_json as sjson
from spack.directory_layout import DirectoryLayoutError
from spack.directory_layout import (
DirectoryLayoutError,
InconsistentInstallDirectoryError,
)
from spack.error import SpackError
from spack.filesystem_view import YamlFilesystemView
from spack.util.crypto import bit_length
@ -1063,7 +1066,14 @@ def _read(self):
elif self.is_upstream:
tty.warn("upstream not found: {0}".format(self._index_path))
def _add(self, spec, directory_layout=None, explicit=False, installation_time=None):
def _add(
self,
spec,
directory_layout=None,
explicit=False,
installation_time=None,
allow_missing=False,
):
"""Add an install record for this spec to the database.
Assumes spec is installed in ``layout.path_for_spec(spec)``.
@ -1074,9 +1084,7 @@ def _add(self, spec, directory_layout=None, explicit=False, installation_time=No
Args:
spec: spec to be added
directory_layout: layout of the spec installation
**kwargs:
explicit
explicit:
Possible values: True, False, any
A spec that was installed following a specific user
@ -1084,9 +1092,10 @@ def _add(self, spec, directory_layout=None, explicit=False, installation_time=No
pulled-in as a dependency of a user requested spec
it's considered implicit.
installation_time
installation_time:
Date and time of installation
allow_missing: if True, don't warn when installation is not found on on disk
This is useful when installing specs without build deps.
"""
if not spec.concrete:
raise NonConcreteSpecAddError("Specs added to DB must be concrete.")
@ -1100,11 +1109,22 @@ def _add(self, spec, directory_layout=None, explicit=False, installation_time=No
# Retrieve optional arguments
installation_time = installation_time or _now()
for dep in spec.dependencies(deptype=_tracked_deps):
dkey = dep.dag_hash()
if dkey not in self._data:
extra_args = {"explicit": False, "installation_time": installation_time}
self._add(dep, directory_layout, **extra_args)
for edge in spec.edges_to_dependencies(deptype=_tracked_deps):
if edge.spec.dag_hash() in self._data:
continue
# allow missing build-only deps. This prevents excessive
# warnings when a spec is installed, and its build dep
# is missing a build dep; there's no need to install the
# build dep's build dep first, and there's no need to warn
# about it missing.
dep_allow_missing = allow_missing or edge.deptypes == ("build",)
self._add(
edge.spec,
directory_layout,
explicit=False,
installation_time=installation_time,
allow_missing=dep_allow_missing,
)
# Make sure the directory layout agrees whether the spec is installed
if not spec.external and directory_layout:
@ -1115,6 +1135,7 @@ def _add(self, spec, directory_layout=None, explicit=False, installation_time=No
installed = True
self._installed_prefixes.add(path)
except DirectoryLayoutError as e:
if not (allow_missing and isinstance(e, InconsistentInstallDirectoryError)):
msg = (
"{0} is being {1} in the database with prefix {2}, "
"but this directory does not contain an installation of "