diff options
author | Todd Gamblin <tgamblin@llnl.gov> | 2020-10-30 17:06:05 -0700 |
---|---|---|
committer | Todd Gamblin <tgamblin@llnl.gov> | 2020-11-01 16:23:48 -0800 |
commit | a80d221bfa1c9be4b2b9eff9f057edf62c34e50b (patch) | |
tree | f37f8844e8b2c9176ba6d41cdd29d107dadd64fe /lib/spack/spack/test/relocate.py | |
parent | a4dd8d5582d3d4bae74c4a8d500a950f2237500a (diff) | |
download | spack-a80d221bfa1c9be4b2b9eff9f057edf62c34e50b.tar.gz spack-a80d221bfa1c9be4b2b9eff9f057edf62c34e50b.tar.bz2 spack-a80d221bfa1c9be4b2b9eff9f057edf62c34e50b.tar.xz spack-a80d221bfa1c9be4b2b9eff9f057edf62c34e50b.zip |
sbang: fixes for sbang relocation
This fixes sbang relocation when using old binary packages, and updates
code in `relocate.py`.
There are really two places where we would want to handle an `sbang`
relocation:
1. Installing an old package that uses `sbang` with shebang lines like
`#!/bin/bash $spack_prefix/sbang`
2. Installing a *new* package that uses `sbang` with shebang lines like
`#!/bin/sh $install_tree/sbang`
The second case is actually handled automatically by our text relocation;
we don't need any special relocation logic for new shebangs, as our
relocation logic already changes references to the build-time
`install_tree` to point to the `install_tree` at intall-time.
Case 1 was not properly handled -- we would not take an old binary
package and point its shebangs at the new `sbang` location. This PR fixes
that and updates the code in `relocation.py` with some notes.
There is one more case we don't currently handle: if a binary package is
created from an installation in a short prefix that does *not* need
`sbang` and is installed to a long prefix that *does* need `sbang`, we
won't do anything. We should just patch the file as we would for a normal
install. In some upcoming PR we should probably change *all* `sbang`
relocation logic to be idempotent and to apply to any sort of shebang'd
file. Then we'd only have to worry about which files to `sbang`-ify at
install time and wouldn't need to care about these special cases.
Diffstat (limited to 'lib/spack/spack/test/relocate.py')
-rw-r--r-- | lib/spack/spack/test/relocate.py | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/lib/spack/spack/test/relocate.py b/lib/spack/spack/test/relocate.py index f9e72ea0d7..e883bd44c5 100644 --- a/lib/spack/spack/test/relocate.py +++ b/lib/spack/spack/test/relocate.py @@ -12,6 +12,7 @@ import llnl.util.filesystem import pytest import spack.architecture import spack.concretize +import spack.hooks.sbang as sbang import spack.paths import spack.relocate import spack.spec @@ -401,3 +402,48 @@ def test_relocate_text_bin_raise_if_new_prefix_is_longer(): spack.relocate.relocate_text_bin( ['item'], short_prefix, long_prefix, None, None, None ) + + +@pytest.mark.parametrize("sbang_line", [ + "#!/bin/bash /path/to/orig/spack/bin/sbang", + "#!/bin/sh /orig/layout/root/bin/sbang" +]) +def test_relocate_text_old_sbang(tmpdir, sbang_line): + """Ensure that old and new sbang styles are relocated.""" + + old_install_prefix = "/orig/layout/root/orig/install/prefix" + new_install_prefix = os.path.join( + spack.store.layout.root, "new", "install", "prefix" + ) + + # input file with an sbang line + original = """\ +{0} +#!/usr/bin/env python + +/orig/layout/root/orig/install/prefix +""".format(sbang_line) + + # expected relocation + expected = """\ +{0} +#!/usr/bin/env python + +{1} +""".format(sbang.sbang_shebang_line(), new_install_prefix) + + path = tmpdir.ensure("path", "to", "file") + with path.open("w") as f: + f.write(original) + + spack.relocate.relocate_text( + [str(path)], + "/orig/layout/root", spack.store.layout.root, + old_install_prefix, new_install_prefix, + "/path/to/orig/spack", spack.paths.spack_root, + { + old_install_prefix: new_install_prefix + } + ) + + assert expected == open(str(path)).read() |