Provide more info in SbangPathError to aid CI debugging (#26316)

This commit is contained in:
Tamara Dahlgren 2021-10-06 12:03:33 -07:00 committed by GitHub
parent cb5b28392e
commit affd2236e6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 3 deletions

View file

@ -28,9 +28,12 @@ def sbang_install_path():
"""Location sbang should be installed within Spack's ``install_tree``."""
sbang_root = str(spack.store.unpadded_root)
install_path = os.path.join(sbang_root, "bin", "sbang")
if len(install_path) > shebang_limit:
raise SbangPathError(
'Install tree root is too long. Spack cannot patch shebang lines.')
path_length = len(install_path)
if path_length > shebang_limit:
msg = ('Install tree root is too long. Spack cannot patch shebang lines'
' when script path length ({0}) exceeds limit ({1}).\n {2}')
msg = msg.format(path_length, shebang_limit, install_path)
raise SbangPathError(msg)
return install_path

View file

@ -225,3 +225,21 @@ def test_install_sbang(install_mockery):
# install again and make sure sbang is still fine
sbang.install_sbang()
check_sbang_installation()
def test_install_sbang_too_long(tmpdir):
root = str(tmpdir)
num_extend = sbang.shebang_limit - len(root) - len('/bin/sbang')
long_path = root
while num_extend > 1:
add = min(num_extend, 255)
long_path = os.path.join(long_path, 'e' * add)
num_extend -= add
with spack.store.use_store(spack.store.Store(long_path)):
with pytest.raises(sbang.SbangPathError) as exc_info:
sbang.sbang_install_path()
err = str(exc_info.value)
assert 'root is too long' in err
assert 'exceeds limit' in err
assert 'cannot patch' in err