def write_buildinfo_file(spec, workdir, rel=False): """ Create a cache file containing information required for the relocation """ prefix = spec.prefix text_to_relocate = [] binary_to_relocate = [] link_to_relocate = [] blacklist = (".spack", "man") prefix_to_hash = dict() prefix_to_hash[str(spec.package.prefix)] = spec.dag_hash() deps = spack.build_environment.get_rpath_deps(spec.package) for d in deps: prefix_to_hash[str(d.prefix)] = d.dag_hash() # 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 prefix %s ' % prefix msg += 'should not be relocated.' tty.warn(msg) if relocate.needs_binary_relocation(m_type, m_subtype): if not filename.endswith('.o'): rel_path_name = os.path.relpath(path_name, prefix) binary_to_relocate.append(rel_path_name) if 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 buildinfo['prefix_to_hash'] = prefix_to_hash filename = buildinfo_file_name(workdir) with open(filename, 'w') as outfile: outfile.write(syaml.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 = [] 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))