def write_buildinfo_file(prefix, workdir, rel=False): """ Create a cache file containing information required for the relocation """ text_to_relocate = [] binary_to_relocate = [] link_to_relocate = [] blacklist = (".spack", "man") # Do this at during tarball creation to save time when tarball unpacked. # Used by make_package_relative to determine binaries to change. for root, dirs, files in os.walk(prefix, topdown=True): dirs[:] = [d for d in dirs if d not in blacklist] for filename in files: path_name = os.path.join(root, filename) m_type, m_subtype = relocate.mime_type(path_name) if os.path.islink(path_name): link = os.readlink(path_name) if os.path.isabs(link): # Relocate absolute links into the spack tree if link.startswith(spack.store.layout.root): rel_path_name = os.path.relpath(path_name, prefix) link_to_relocate.append(rel_path_name) else: msg = 'Absolute link %s to %s ' % (path_name, link) msg += 'outside of stage %s ' % prefix msg += 'cannot be relocated.' tty.warn(msg) # Check if the file contains a string with the installroot. # This cuts down on the number of files added to the list # of files potentially needing relocation elif relocate.strings_contains_installroot( path_name, spack.store.layout.root): if relocate.needs_binary_relocation(m_type, m_subtype): rel_path_name = os.path.relpath(path_name, prefix) binary_to_relocate.append(rel_path_name) elif relocate.needs_text_relocation(m_type, m_subtype): rel_path_name = os.path.relpath(path_name, prefix) text_to_relocate.append(rel_path_name) # Create buildinfo data and write it to disk 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 buildinfo['relocate_binaries'] = binary_to_relocate buildinfo['relocate_links'] = link_to_relocate filename = buildinfo_file_name(workdir) with open(filename, 'w') as outfile: outfile.write(syaml.dump(buildinfo, default_flow_style=True))
def test_relocate_text(tmpdir): with tmpdir.as_cwd(): # Validate the text path replacement old_dir = '/home/spack/opt/spack' filename = 'dummy.txt' with open(filename, "w") as script: script.write(old_dir) script.close() filenames = [filename] new_dir = '/opt/rh/devtoolset/' relocate_text(filenames, old_dir, new_dir) with open(filename, "r")as script: for line in script: assert(new_dir in line) assert(strings_contains_installroot(filename, old_dir) is False)
def write_buildinfo_file(prefix, workdir, rel=False): """ Create a cache file containing information required for the relocation """ text_to_relocate = [] binary_to_relocate = [] blacklist = (".spack", "man") os_id = platform.system() # Do this at during tarball creation to save time when tarball unpacked. # Used by make_package_relative to determine binaries to change. for root, dirs, files in os.walk(prefix, topdown=True): dirs[:] = [d for d in dirs if d not in blacklist] for filename in files: path_name = os.path.join(root, filename) # Check if the file contains a string with the installroot. # This cuts down on the number of files added to the list # of files potentially needing relocation if relocate.strings_contains_installroot(path_name, spack.store.layout.root): filetype = get_filetype(path_name) if relocate.needs_binary_relocation(filetype, os_id): rel_path_name = os.path.relpath(path_name, prefix) binary_to_relocate.append(rel_path_name) elif relocate.needs_text_relocation(filetype): rel_path_name = os.path.relpath(path_name, prefix) text_to_relocate.append(rel_path_name) # Create buildinfo data and write it to disk buildinfo = {} buildinfo['relative_rpaths'] = rel buildinfo['buildpath'] = spack.store.layout.root buildinfo['relative_prefix'] = os.path.relpath(prefix, spack.store.layout.root) buildinfo['relocate_textfiles'] = text_to_relocate buildinfo['relocate_binaries'] = binary_to_relocate filename = buildinfo_file_name(workdir) with open(filename, 'w') as outfile: outfile.write(yaml.dump(buildinfo, default_flow_style=True))
def write_buildinfo_file(prefix, workdir, rel=False): """ Create a cache file containing information required for the relocation """ text_to_relocate = [] binary_to_relocate = [] blacklist = (".spack", "man") os_id = platform.system() # Do this at during tarball creation to save time when tarball unpacked. # Used by make_package_relative to determine binaries to change. for root, dirs, files in os.walk(prefix, topdown=True): dirs[:] = [d for d in dirs if d not in blacklist] for filename in files: path_name = os.path.join(root, filename) # Check if the file contains a string with the installroot. # This cuts down on the number of files added to the list # of files potentially needing relocation if relocate.strings_contains_installroot( path_name, spack.store.layout.root): filetype = get_filetype(path_name) if relocate.needs_binary_relocation(filetype, os_id): rel_path_name = os.path.relpath(path_name, prefix) binary_to_relocate.append(rel_path_name) elif relocate.needs_text_relocation(filetype): rel_path_name = os.path.relpath(path_name, prefix) text_to_relocate.append(rel_path_name) # Create buildinfo data and write it to disk buildinfo = {} buildinfo['relative_rpaths'] = rel buildinfo['buildpath'] = spack.store.layout.root buildinfo['relative_prefix'] = os.path.relpath( prefix, spack.store.layout.root) buildinfo['relocate_textfiles'] = text_to_relocate buildinfo['relocate_binaries'] = binary_to_relocate filename = buildinfo_file_name(workdir) with open(filename, 'w') as outfile: outfile.write(yaml.dump(buildinfo, default_flow_style=True))