1212import tempfile
1313import hashlib
1414import glob
15+ from ordereddict_backport import OrderedDict
1516
1617from contextlib import closing
1718import ruamel .yaml as yaml
@@ -1105,11 +1106,26 @@ def relocate_package(spec, allow_root):
11051106 new_deps = spack .build_environment .get_rpath_deps (spec .package )
11061107 for d in new_deps :
11071108 hash_to_prefix [d .format ('{hash}' )] = str (d .prefix )
1108- prefix_to_prefix = dict ()
1109+ # Spurious replacements (e.g. sbang) will cause issues with binaries
1110+ # For example, the new sbang can be longer than the old one.
1111+ # Hence 2 dictionaries are maintained here.
1112+ prefix_to_prefix_text = OrderedDict ({})
1113+ prefix_to_prefix_bin = OrderedDict ({})
1114+ prefix_to_prefix_text [old_prefix ] = new_prefix
1115+ prefix_to_prefix_bin [old_prefix ] = new_prefix
1116+ prefix_to_prefix_text [old_layout_root ] = new_layout_root
1117+ prefix_to_prefix_bin [old_layout_root ] = new_layout_root
11091118 for orig_prefix , hash in prefix_to_hash .items ():
1110- prefix_to_prefix [orig_prefix ] = hash_to_prefix .get (hash , None )
1111- prefix_to_prefix [old_prefix ] = new_prefix
1112- prefix_to_prefix [old_layout_root ] = new_layout_root
1119+ prefix_to_prefix_text [orig_prefix ] = hash_to_prefix .get (hash , None )
1120+ prefix_to_prefix_bin [orig_prefix ] = hash_to_prefix .get (hash , None )
1121+ # This is vestigial code for the *old* location of sbang. Previously,
1122+ # sbang was a bash script, and it lived in the spack prefix. It is
1123+ # now a POSIX script that lives in the install prefix. Old packages
1124+ # will have the old sbang location in their shebangs.
1125+ import spack .hooks .sbang as sbang
1126+ orig_sbang = '#!/bin/bash {0}/bin/sbang' .format (old_spack_prefix )
1127+ new_sbang = sbang .sbang_shebang_line ()
1128+ prefix_to_prefix_text [orig_sbang ] = new_sbang
11131129
11141130 tty .debug ("Relocating package from" ,
11151131 "%s to %s." % (old_layout_root , new_layout_root ))
@@ -1137,15 +1153,14 @@ def is_backup_file(file):
11371153 relocate .relocate_macho_binaries (files_to_relocate ,
11381154 old_layout_root ,
11391155 new_layout_root ,
1140- prefix_to_prefix , rel ,
1156+ prefix_to_prefix_bin , rel ,
11411157 old_prefix ,
11421158 new_prefix )
1143-
11441159 if 'elf' in platform .binary_formats :
11451160 relocate .relocate_elf_binaries (files_to_relocate ,
11461161 old_layout_root ,
11471162 new_layout_root ,
1148- prefix_to_prefix , rel ,
1163+ prefix_to_prefix_bin , rel ,
11491164 old_prefix ,
11501165 new_prefix )
11511166 # Relocate links to the new install prefix
@@ -1156,12 +1171,7 @@ def is_backup_file(file):
11561171
11571172 # For all buildcaches
11581173 # relocate the install prefixes in text files including dependencies
1159- relocate .relocate_text (text_names ,
1160- old_layout_root , new_layout_root ,
1161- old_prefix , new_prefix ,
1162- old_spack_prefix ,
1163- new_spack_prefix ,
1164- prefix_to_prefix )
1174+ relocate .relocate_text (text_names , prefix_to_prefix_text )
11651175
11661176 paths_to_relocate = [old_prefix , old_layout_root ]
11671177 paths_to_relocate .extend (prefix_to_hash .keys ())
@@ -1171,22 +1181,13 @@ def is_backup_file(file):
11711181 map (lambda filename : os .path .join (workdir , filename ),
11721182 buildinfo ['relocate_binaries' ])))
11731183 # relocate the install prefixes in binary files including dependencies
1174- relocate .relocate_text_bin (files_to_relocate ,
1175- old_prefix , new_prefix ,
1176- old_spack_prefix ,
1177- new_spack_prefix ,
1178- prefix_to_prefix )
1179-
1180- # If we are installing back to the same location
1181- # relocate the sbang location if the spack directory changed
1184+ relocate .relocate_text_bin (files_to_relocate , prefix_to_prefix_bin )
1185+
1186+ # If we are installing back to the same location
1187+ # relocate the sbang location if the spack directory changed
11821188 else :
11831189 if old_spack_prefix != new_spack_prefix :
1184- relocate .relocate_text (text_names ,
1185- old_layout_root , new_layout_root ,
1186- old_prefix , new_prefix ,
1187- old_spack_prefix ,
1188- new_spack_prefix ,
1189- prefix_to_prefix )
1190+ relocate .relocate_text (text_names , prefix_to_prefix_text )
11901191
11911192
11921193def extract_tarball (spec , filename , allow_root = False , unsigned = False ,
0 commit comments