Build cache: relocate path to spack/bin/sbang in text files. (#11592)
* Build cache: relocate path to spack/bin/sbang in text files. * Found in testing. * update packaging test * Make sbang replacement including #!/bin/bash. Add an additional spack prefix replacement to fix stage directory references. * flake8 * Use buildinfo.get() so old buildcaches without buildinfo['spackprefix'] can be read.
This commit is contained in:
parent
f5a2d7698d
commit
88473a8da3
@ -171,6 +171,7 @@ def write_buildinfo_file(prefix, workdir, rel=False):
|
||||
buildinfo = {}
|
||||
buildinfo['relative_rpaths'] = rel
|
||||
buildinfo['buildpath'] = spack.store.layout.root
|
||||
buildinfo['spackprefix'] = spack.paths.prefix
|
||||
buildinfo['relative_prefix'] = os.path.relpath(
|
||||
prefix, spack.store.layout.root)
|
||||
buildinfo['relocate_textfiles'] = text_to_relocate
|
||||
@ -459,7 +460,9 @@ def relocate_package(workdir, allow_root):
|
||||
"""
|
||||
buildinfo = read_buildinfo_file(workdir)
|
||||
new_path = spack.store.layout.root
|
||||
new_prefix = spack.paths.prefix
|
||||
old_path = buildinfo['buildpath']
|
||||
old_prefix = buildinfo.get('spackprefix', '/not/in/buildinfo/dictionary')
|
||||
rel = buildinfo.get('relative_rpaths', False)
|
||||
if rel:
|
||||
return
|
||||
@ -472,7 +475,9 @@ def relocate_package(workdir, allow_root):
|
||||
# Don't add backup files generated by filter_file during install step.
|
||||
if not path_name.endswith('~'):
|
||||
path_names.add(path_name)
|
||||
relocate.relocate_text(path_names, old_path, new_path)
|
||||
relocate.relocate_text(path_names, oldpath=old_path,
|
||||
newpath=new_path, oldprefix=old_prefix,
|
||||
newprefix=new_prefix)
|
||||
# If the binary files in the package were not edited to use
|
||||
# relative RPATHs, then the RPATHs need to be relocated
|
||||
if not rel:
|
||||
@ -602,7 +607,8 @@ def get_specs(force=False):
|
||||
urls = set()
|
||||
for mirror_name, mirror_url in mirrors.items():
|
||||
if mirror_url.startswith('file'):
|
||||
mirror = mirror_url.replace('file://', '') + "/" + _build_cache_relative_path
|
||||
mirror = mirror_url.replace(
|
||||
'file://', '') + "/" + _build_cache_relative_path
|
||||
tty.msg("Finding buildcaches in %s" % mirror)
|
||||
if os.path.exists(mirror):
|
||||
files = os.listdir(mirror)
|
||||
|
@ -19,6 +19,7 @@ class InstallRootStringException(spack.error.SpackError):
|
||||
"""
|
||||
Raised when the relocated binary still has the install root string.
|
||||
"""
|
||||
|
||||
def __init__(self, file_path, root_path):
|
||||
super(InstallRootStringException, self).__init__(
|
||||
"\n %s \ncontains string\n %s \n"
|
||||
@ -249,7 +250,7 @@ def strings_contains_installroot(path_name, root_dir):
|
||||
strings = Executable('strings')
|
||||
output = strings('%s' % path_name,
|
||||
output=str, err=str)
|
||||
return (root_dir in output)
|
||||
return (root_dir in output or spack.paths.prefix in output)
|
||||
|
||||
|
||||
def modify_elf_object(path_name, new_rpaths):
|
||||
@ -438,11 +439,18 @@ def relocate_links(path_names, old_dir, new_dir):
|
||||
os.symlink(new_src, path_name)
|
||||
|
||||
|
||||
def relocate_text(path_names, old_dir, new_dir):
|
||||
def relocate_text(path_names, oldpath, newpath, oldprefix, newprefix):
|
||||
"""
|
||||
Replace old path with new path in text file path_name
|
||||
"""
|
||||
fs.filter_file('%s' % old_dir, '%s' % new_dir, *path_names, backup=False)
|
||||
fs.filter_file('%s' % oldpath, '%s' % newpath, *path_names,
|
||||
backup=False, string=True)
|
||||
sbangre = '#!/bin/bash %s/bin/sbang' % oldprefix
|
||||
sbangnew = '#!/bin/bash %s/bin/sbang' % newprefix
|
||||
fs.filter_file(sbangre, sbangnew, *path_names,
|
||||
backup=False, string=True)
|
||||
fs.filter_file(oldprefix, newprefix, *path_names,
|
||||
backup=False, string=True)
|
||||
|
||||
|
||||
def substitute_rpath(orig_rpath, topdir, new_root_path):
|
||||
@ -543,6 +551,13 @@ def file_is_relocatable(file):
|
||||
tty.debug(msg.format(spack.store.layout.root, file))
|
||||
return False
|
||||
|
||||
if any(spack.paths.prefix in x for x in set_of_strings):
|
||||
# One binary has the root folder not in the RPATH,
|
||||
# meaning that this spec is not relocatable
|
||||
msg = 'Found "{0}" in {1} strings'
|
||||
tty.debug(msg.format(spack.paths.prefix, file))
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
|
||||
|
@ -245,7 +245,8 @@ def test_relocate_text(tmpdir):
|
||||
script.close()
|
||||
filenames = [filename]
|
||||
new_dir = '/opt/rh/devtoolset/'
|
||||
relocate_text(filenames, old_dir, new_dir)
|
||||
relocate_text(filenames, oldpath=old_dir, newpath=new_dir,
|
||||
oldprefix=old_dir, newprefix=new_dir)
|
||||
with open(filename, "r")as script:
|
||||
for line in script:
|
||||
assert(new_dir in line)
|
||||
|
Loading…
Reference in New Issue
Block a user