summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Scheibel <scheibel1@llnl.gov>2020-06-25 06:27:27 -0700
committerGitHub <noreply@github.com>2020-06-25 08:27:27 -0500
commita31c115d799c364f60e82fed02ba1fcc80bd935f (patch)
treec4d473b449b7c0192807d90aac93cac4d3daa88b
parent5c712a03a1262b97fc920c86a2125fef7c806762 (diff)
downloadspack-a31c115d799c364f60e82fed02ba1fcc80bd935f.tar.gz
spack-a31c115d799c364f60e82fed02ba1fcc80bd935f.tar.bz2
spack-a31c115d799c364f60e82fed02ba1fcc80bd935f.tar.xz
spack-a31c115d799c364f60e82fed02ba1fcc80bd935f.zip
Fix global activation check for upstream extendees (#17231)
* short-circuit is_activated check when the extendee is installed upstream * add test for checking activation status of packages with an extendee installed upstream
-rw-r--r--lib/spack/spack/package.py5
-rw-r--r--lib/spack/spack/test/test_activations.py29
2 files changed, 34 insertions, 0 deletions
diff --git a/lib/spack/spack/package.py b/lib/spack/spack/package.py
index dc32effbec..5c4ff23d40 100644
--- a/lib/spack/spack/package.py
+++ b/lib/spack/spack/package.py
@@ -1027,6 +1027,11 @@ class PackageBase(with_metaclass(PackageMeta, PackageViewMixin, object)):
if not self.is_extension:
raise ValueError(
"is_activated called on package that is not an extension.")
+ if self.extendee_spec.package.installed_upstream:
+ # If this extends an upstream package, it cannot be activated for
+ # it. This bypasses construction of the extension map, which can
+ # can fail when run in the context of a downstream Spack instance
+ return False
extensions_layout = view.extensions_layout
exts = extensions_layout.extension_map(self.extendee_spec)
return (self.name in exts) and (exts[self.name] == self.spec)
diff --git a/lib/spack/spack/test/test_activations.py b/lib/spack/spack/test/test_activations.py
index eaac98f318..d1780b8963 100644
--- a/lib/spack/spack/test/test_activations.py
+++ b/lib/spack/spack/test/test_activations.py
@@ -408,3 +408,32 @@ def test_perl_activation_view(tmpdir, perl_and_extension_dirs,
assert not os.path.exists(os.path.join(perl_prefix, 'bin/perl-ext-tool'))
assert os.path.exists(os.path.join(view_dir, 'bin/perl-ext-tool'))
+
+
+def test_is_activated_upstream_extendee(tmpdir, builtin_and_mock_packages,
+ monkeypatch):
+ """When an extendee is installed upstream, make sure that the extension
+ spec is never considered to be globally activated for it.
+ """
+ extendee_spec = spack.spec.Spec('python')
+ extendee_spec._concrete = True
+
+ python_name = 'python'
+ tmpdir.ensure(python_name, dir=True)
+
+ python_prefix = str(tmpdir.join(python_name))
+ # Set the prefix on the package's spec reference because that is a copy of
+ # the original spec
+ extendee_spec.package.spec.prefix = python_prefix
+ monkeypatch.setattr(extendee_spec.package.__class__,
+ 'installed_upstream', True)
+
+ ext_name = 'py-extension1'
+ tmpdir.ensure(ext_name, dir=True)
+ ext_pkg = create_ext_pkg(
+ ext_name, str(tmpdir.join(ext_name)), extendee_spec, monkeypatch)
+
+ # The view should not be checked at all if the extendee is installed
+ # upstream, so use 'None' here
+ mock_view = None
+ assert not ext_pkg.is_activated(mock_view)