Relocate¶
A script to ensure the proper rpaths are in place for the relenv environment.
- relenv.relocate.handle_elf(path: str | PathLike[str], libs: str | PathLike[str], rpath_only: bool, root: str | PathLike[str] | None = None) 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: str | PathLike[str], root_dir: str | PathLike[str], rpath_only: bool) dict[str, list[str]] | None¶
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_machoon the macho file.
- relenv.relocate.is_elf(path: str | PathLike[str]) bool¶
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: str | PathLike[str], directory: str | PathLike[str]) bool¶
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: str | PathLike[str]) bool¶
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: str | PathLike[str], libs_dir: str | PathLike[str] | None = None, rpath_only: bool = True, log_level: str = 'DEBUG', log_file_name: str = '<stdout>') None¶
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: str | PathLike[str]) dict[str, list[str]] | None¶
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: str) dict[str, list[str]]¶
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: str) list[str]¶
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: str | PathLike[str]) list[str]¶
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: str | PathLike[str], new_rpath: str, only_relative: bool = True) str | bool¶
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