diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/spack/spack/relocate.py | 30 | ||||
-rw-r--r-- | lib/spack/spack/test/relocate.py | 9 |
2 files changed, 36 insertions, 3 deletions
diff --git a/lib/spack/spack/relocate.py b/lib/spack/spack/relocate.py index 8e4350a7b1..eec2ca918f 100644 --- a/lib/spack/spack/relocate.py +++ b/lib/spack/spack/relocate.py @@ -6,6 +6,7 @@ import os import re +import shutil import platform import spack.repo import spack.cmd @@ -86,7 +87,14 @@ def get_existing_elf_rpaths(path_name): Return the RPATHS returned by patchelf --print-rpath path_name as a list of strings. """ - patchelf = Executable(get_patchelf()) + + # if we're relocating patchelf itself, use it + + if path_name[-13:] == "/bin/patchelf": + patchelf = Executable(path_name) + else: + patchelf = Executable(get_patchelf()) + try: output = patchelf('--print-rpath', '%s' % path_name, output=str, error=str) @@ -326,8 +334,18 @@ def modify_elf_object(path_name, new_rpaths): """ Replace orig_rpath with new_rpath in RPATH of elf object path_name """ + new_joined = ':'.join(new_rpaths) - patchelf = Executable(get_patchelf()) + + # if we're relocating patchelf itself, use it + + if path_name[-13:] == "/bin/patchelf": + bak_path = path_name + ".bak" + shutil.copy(path_name, bak_path) + patchelf = Executable(bak_path) + else: + patchelf = Executable(get_patchelf()) + try: patchelf('--force-rpath', '--set-rpath', '%s' % new_joined, '%s' % path_name, output=str, error=str) @@ -659,7 +677,13 @@ def file_is_relocatable(file): raise ValueError('{0} is not an absolute path'.format(file)) strings = Executable('strings') - patchelf = Executable(get_patchelf()) + + # if we're relocating patchelf itself, use it + + if file[-13:] == "/bin/patchelf": + patchelf = Executable(file) + else: + patchelf = Executable(get_patchelf()) # Remove the RPATHS from the strings in the executable set_of_strings = set(strings(file, output=str).split()) diff --git a/lib/spack/spack/test/relocate.py b/lib/spack/spack/test/relocate.py index f070e150c7..4d7dc5b942 100644 --- a/lib/spack/spack/test/relocate.py +++ b/lib/spack/spack/test/relocate.py @@ -60,6 +60,15 @@ def test_file_is_relocatable(source_file, is_relocatable): assert spack.relocate.file_is_relocatable(executable) is is_relocatable +@pytest.mark.requires_executables( + 'patchelf', 'strings', 'file' +) +def test_patchelf_is_relocatable(): + patchelf = spack.relocate.get_patchelf() + assert spack.relocate.is_binary(patchelf) + assert spack.relocate.file_is_relocatable(patchelf) + + @pytest.mark.skipif( platform.system().lower() != 'linux', reason='implementation for MacOS still missing' |