Relocate¶
A script to ensure the proper rpaths are in place for the relenv environment.
- relenv.relocate.handle_elf(path, libs, rpath_only, root=None)¶
Handle the parsing and pathcing of an ELF file.
- Parameters:
path (str) – The path of the ELF file
libs (str) – The libs directory
rpath_only (bool) – If true, only ensure the correct rpaths are present and don’t copy the file
root (str, optional) – The directory to ensure the file is under, defaults to None
- relenv.relocate.handle_macho(path, root_dir, rpath_only)¶
Ensure the given macho file has the correct rpath and is in th correct location.
- Parameters:
path (str) – The path to a macho file
root_dir (str) – The directory the file needs to reside under
rpath_only (bool) – If true, only ensure the correct rpaths are present and don’t copy the file
- Returns:
The information from
parse_macho
on the macho file.
- relenv.relocate.is_elf(path)¶
Determines whether the given file is an ELF file.
- Parameters:
path (str) – The path to the file to check
- Returns:
Whether the file is an ELF file
- Return type:
bool
- relenv.relocate.is_in_dir(filepath, directory)¶
Determines whether a file is contained within a directory.
- Parameters:
filepath (str) – The path to the file to check
directory (str) – The directory to check within
- Returns:
Whether the file is contained within the given directory
- Return type:
bool
- relenv.relocate.is_macho(path)¶
Determines whether the given file is a macho file.
- Parameters:
path (str) – The path to the file to check
- Returns:
Whether the file is a macho file
- Return type:
bool
- relenv.relocate.main(root, libs_dir=None, rpath_only=True, log_level='DEBUG', log_file_name='<stdout>')¶
The entrypoint into the relocate script.
- Parameters:
root (str) – The root directory to operate traverse for files to be patched
libs_dir (str, optional) – The directory to place the libraries in, defaults to None
rpath_only (bool, optional) – If true, only ensure the correct rpaths are present and don’t copy the file, defaults to True
log_level (str, optional) – The level to log at, defaults to “INFO”
- relenv.relocate.parse_macho(path)¶
Run
otool -l <path>
and return its parsed output.- Parameters:
path (str) – The path to the file
- Returns:
The parsed relevant RPATH content, or None if it isn’t an object file
- Return type:
dict or None
- relenv.relocate.parse_otool_l(stdout)¶
Parse the output of
otool -l <path>
.- Parameters:
stdout (str) – The output of the
otool -l <path>
command- Returns:
The parsed relevant output with command keys and path values
- Return type:
dict
- relenv.relocate.parse_readelf_d(stdout)¶
Parse the output of
readelf -d <path>
.- Parameters:
stdout (str) – The output of the
readelf -d <path>
command- Returns:
The RPATH values
- Return type:
list
- relenv.relocate.parse_rpath(path)¶
Run
readelf -d <path>
and return its parsed output.- Parameters:
path (str) – The path to the file
- Returns:
The RPATH’s found.
- Return type:
list
- relenv.relocate.patch_rpath(path, new_rpath, only_relative=True)¶
Patch the rpath of a given ELF file.
- Parameters:
path (str) – The path to an ELF file
new_rpath (str) – The new rpath to add
only_relative (bool, optional) – Whether or not to remove non-relative rpaths, defaults to True
- Returns:
The new rpath, or False if patching failed
- Return type:
str or bool