summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/spack/spack/directives.py8
-rw-r--r--lib/spack/spack/test/directives.py8
2 files changed, 15 insertions, 1 deletions
diff --git a/lib/spack/spack/directives.py b/lib/spack/spack/directives.py
index b2058737e0..6e9dd819bb 100644
--- a/lib/spack/spack/directives.py
+++ b/lib/spack/spack/directives.py
@@ -361,6 +361,8 @@ def _depends_on(pkg, spec, when=None, type=default_deptype, patches=None):
return
dep_spec = spack.spec.Spec(spec)
+ if not dep_spec.name:
+ raise DependencyError("Invalid dependency specification in package '%s':" % pkg.name, spec)
if pkg.name == dep_spec.name:
raise CircularReferenceError("Package '%s' cannot depend on itself." % pkg.name)
@@ -769,7 +771,11 @@ class DirectiveError(spack.error.SpackError):
"""This is raised when something is wrong with a package directive."""
-class CircularReferenceError(DirectiveError):
+class DependencyError(DirectiveError):
+ """This is raised when a dependency specification is invalid."""
+
+
+class CircularReferenceError(DependencyError):
"""This is raised when something depends on itself."""
diff --git a/lib/spack/spack/test/directives.py b/lib/spack/spack/test/directives.py
index 616d7ef5ee..d1fc31d09b 100644
--- a/lib/spack/spack/test/directives.py
+++ b/lib/spack/spack/test/directives.py
@@ -4,6 +4,7 @@
# SPDX-License-Identifier: (Apache-2.0 OR MIT)
import pytest
+import spack.directives
import spack.repo
import spack.spec
@@ -60,3 +61,10 @@ def test_extends_spec(config, mock_packages):
assert extender.dependencies
assert extender.package.extends(extendee)
+
+
+@pytest.mark.regression("34368")
+def test_error_on_anonymous_dependency(config, mock_packages):
+ pkg = spack.repo.path.get_pkg_class("a")
+ with pytest.raises(spack.directives.DependencyError):
+ spack.directives._depends_on(pkg, "@4.5")