Skip to content

Commit

Permalink
ASP-based solver: handle installed specs from unknown namespaces
Browse files Browse the repository at this point in the history
fixes spack#28259

This commit discard specs from unknown namespaces from the
ones that can be "reused" during concretization. Previously
Spack would just error out when encountering them.
  • Loading branch information
alalazo committed Apr 15, 2022
1 parent 0e0c438 commit d1d0bed
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/spack/spack/solver/asp.py
Original file line number Diff line number Diff line change
Expand Up @@ -1645,6 +1645,12 @@ def _facts_from_concrete_spec(self, spec, possible):
# be dependencies (don't tell it about the others)
h = spec.dag_hash()
if spec.name in possible and h not in self.seen_hashes:
try:
# Only consider installed packages for repo we know
spack.repo.path.repo_for_pkg(spec)
except spack.repo.UnknownNamespaceError:
return

# this indicates that there is a spec like this installed
self.gen.fact(fn.installed_hash(spec.name, h))

Expand Down
38 changes: 38 additions & 0 deletions lib/spack/spack/test/concretize.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,28 @@ def change(self, context):
return _changing_pkg


@pytest.fixture()
def additional_repo_with_c(tmpdir_factory, mutable_mock_repo):
"""Add a repository with a simple package"""
repo_dir = tmpdir_factory.mktemp('myrepo')
repo_dir.join('repo.yaml').write("""
repo:
namespace: myrepo
""", ensure=True)
packages_dir = repo_dir.ensure('packages', dir=True)
package_py = """
class C(Package):
homepage = "http://www.example.com"
url = "http://www.example.com/root-1.0.tar.gz"
version(1.0, sha256='abcde')
"""
packages_dir.join('c', 'package.py').write(package_py, ensure=True)
repo = spack.repo.Repo(str(repo_dir))
mutable_mock_repo.put_first(repo)
return repo


# This must use the mutable_config fixture because the test
# adjusting_default_target_based_on_compiler uses the current_host fixture,
# which changes the config.
Expand Down Expand Up @@ -1485,3 +1507,19 @@ def test_conditional_values_in_conditional_variant(self):

s = Spec('conditional-values-in-variant@1.60.0').concretized()
assert 'cxxstd' in s.variants

@pytest.mark.regression('28259')
def test_reuse_with_unknown_namespace_dont_raise(
self, additional_repo_with_c, mutable_mock_repo
):
s = Spec('c').concretized()
assert s.namespace == 'myrepo'
s.package.do_install(fake=True, explicit=True)

# TODO: To mock repo removal we need to recreate the RepoPath
mutable_mock_repo.remove(additional_repo_with_c)
spack.repo.path = spack.repo.RepoPath(*spack.repo.path.repos)

with spack.config.override("concretizer:reuse", True):
s = Spec('c').concretized()
assert s.namespace == 'builtin.mock'

0 comments on commit d1d0bed

Please sign in to comment.