summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJordan Galby <67924449+Jordan474@users.noreply.github.com>2022-06-07 16:17:33 +0200
committerGitHub <noreply@github.com>2022-06-07 16:17:33 +0200
commite74d85a524dc0decbdc7d070017df1137793ce3f (patch)
tree34f9f89891a98a883e4260472f35e9620a57b5c2
parentffd63c5de1d9586920b70b86ca5a8ec71f17b0c2 (diff)
downloadspack-e74d85a524dc0decbdc7d070017df1137793ce3f.tar.gz
spack-e74d85a524dc0decbdc7d070017df1137793ce3f.tar.bz2
spack-e74d85a524dc0decbdc7d070017df1137793ce3f.tar.xz
spack-e74d85a524dc0decbdc7d070017df1137793ce3f.zip
Fix empty install prefix post-install sanity check (#30983)
-rw-r--r--lib/spack/spack/package_base.py8
-rw-r--r--lib/spack/spack/test/install.py16
-rw-r--r--var/spack/repos/builtin.mock/packages/failing-empty-install/package.py16
3 files changed, 33 insertions, 7 deletions
diff --git a/lib/spack/spack/package_base.py b/lib/spack/spack/package_base.py
index f88d907974..b4763bfab9 100644
--- a/lib/spack/spack/package_base.py
+++ b/lib/spack/spack/package_base.py
@@ -33,7 +33,7 @@ import six
import llnl.util.filesystem as fsys
import llnl.util.tty as tty
-from llnl.util.lang import memoized, nullcontext
+from llnl.util.lang import match_predicate, memoized, nullcontext
from llnl.util.link_tree import LinkTree
import spack.compilers
@@ -2178,10 +2178,8 @@ class PackageBase(six.with_metaclass(PackageMeta, PackageViewMixin, object)):
check_paths(self.sanity_check_is_file, 'file', os.path.isfile)
check_paths(self.sanity_check_is_dir, 'directory', os.path.isdir)
- installed = set(os.listdir(self.prefix))
- installed.difference_update(
- spack.store.layout.hidden_file_regexes)
- if not installed:
+ ignore_file = match_predicate(spack.store.layout.hidden_file_regexes)
+ if all(map(ignore_file, os.listdir(self.prefix))):
raise InstallError(
"Install failed for %s. Nothing was installed!" % self.name)
diff --git a/lib/spack/spack/test/install.py b/lib/spack/spack/test/install.py
index 845bdd92b2..d1f11aa4f4 100644
--- a/lib/spack/spack/test/install.py
+++ b/lib/spack/spack/test/install.py
@@ -379,9 +379,8 @@ def test_failing_build(install_mockery, mock_fetch, capfd):
spec = Spec('failing-build').concretized()
pkg = spec.package
- with pytest.raises(spack.build_environment.ChildError):
+ with pytest.raises(spack.build_environment.ChildError, match='Expected failure'):
pkg.do_install()
- assert 'InstallError: Expected Failure' in capfd.readouterr()[0]
class MockInstallError(spack.error.SpackError):
@@ -612,3 +611,16 @@ def test_install_error():
assert exc.__class__.__name__ == 'InstallError'
assert exc.message == msg
assert exc.long_message == long_msg
+
+
+@pytest.mark.disable_clean_stage_check
+def test_empty_install_sanity_check_prefix(
+ monkeypatch, install_mockery, mock_fetch, mock_packages
+):
+ """Test empty install triggers sanity_check_prefix."""
+ spec = Spec('failing-empty-install').concretized()
+ with pytest.raises(
+ spack.build_environment.ChildError,
+ match='Nothing was installed'
+ ):
+ spec.package.do_install()
diff --git a/var/spack/repos/builtin.mock/packages/failing-empty-install/package.py b/var/spack/repos/builtin.mock/packages/failing-empty-install/package.py
new file mode 100644
index 0000000000..f068b64499
--- /dev/null
+++ b/var/spack/repos/builtin.mock/packages/failing-empty-install/package.py
@@ -0,0 +1,16 @@
+# Copyright 2013-2022 Lawrence Livermore National Security, LLC and other
+# Spack Project Developers. See the top-level COPYRIGHT file for details.
+#
+# SPDX-License-Identifier: (Apache-2.0 OR MIT)
+from spack.package import *
+
+
+class FailingEmptyInstall(Package):
+ """This package installs nothing, install should fail."""
+ homepage = "http://www.example.com/trivial_install"
+ url = "http://www.unit-test-should-replace-this-url/trivial_install-1.0.tar.gz"
+
+ version('1.0', '0123456789abcdef0123456789abcdef')
+
+ def install(self, spec, prefix):
+ pass