package audit: ensure stand-alone test method not include in build-phase testing (#30352)

This commit is contained in:
Tamara Dahlgren 2022-05-05 09:04:16 -07:00 committed by GitHub
parent c9714533f3
commit 011a491b16
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 2 deletions

View File

@ -276,6 +276,24 @@ def _search_duplicate_specs_in_externals(error_cls):
)
@package_directives
def _check_build_test_callbacks(pkgs, error_cls):
"""Ensure stand-alone test method is not included in build-time callbacks"""
errors = []
for pkg_name in pkgs:
pkg = spack.repo.get(pkg_name)
test_callbacks = pkg.build_time_test_callbacks
if test_callbacks and 'test' in test_callbacks:
msg = ('{0} package contains "test" method in '
'build_time_test_callbacks')
instr = ('Remove "test" from: [{0}]'
.format(', '.join(test_callbacks)))
errors.append(error_cls(msg.format(pkg.name), [instr]))
return errors
@package_directives
def _check_patch_urls(pkgs, error_cls):
"""Ensure that patches fetched from GitHub have stable sha256 hashes."""

View File

@ -17,6 +17,8 @@
(['wrong-variant-in-depends-on'], 'PKG-DIRECTIVES'),
# This package has a GitHub patch URL without full_index=1
(['invalid-github-patch-url'], 'PKG-DIRECTIVES'),
# This package has a stand-alone 'test' method in build-time callbacks
(['test-build-callbacks'], 'PKG-DIRECTIVES'),
# This package has no issues
(['mpileaks'], None),
# This package has a conflict with a trigger which cannot constrain the constraint

View File

@ -16,8 +16,8 @@ class TestBuildCallbacks(Package):
version('1.0', '0123456789abcdef0123456789abcdef')
phases = ['build', 'install']
# set to undefined method
build_time_test_callbacks = ['undefined-build-test']
# Include undefined method (runtime failure) and 'test' (audit failure)
build_time_test_callbacks = ['undefined-build-test', 'test']
run_after('build')(Package._run_default_build_time_test_callbacks)
def build(self, spec, prefix):