Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions infra/base-images/base-builder/indexer/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@
import subprocess
from typing import Final, Sequence

from absl import logging

from google3.pyglib import gfile
import pathlib


LD_BINARY_NAME: Final[str] = "ld-linux-x86-64.so.2"
_LD_BINARY_PATH: Final[pathlib.Path] = pathlib.Path("/lib64") / LD_BINARY_NAME

Expand Down Expand Up @@ -79,3 +85,52 @@ def get_shared_libraries(
)

return _parse_ld_trace_output(result.stdout.decode())


def copy_shared_libraries(
libraries: Sequence[SharedLibrary], dst_path: pathlib.Path
) -> None:
"""Copies the shared libraries to the shared directory."""
for lib in libraries:
try:
logging.info("Copying %s => %s", lib.name, lib.path)
gfile.Copy(lib.path, dst_path / lib.path.name, overwrite=True, mode=0o755)
except gfile.GOSError:
logging.exception("Could not copy %s to %s", lib.path, dst_path)
raise


def patch_binary_rpath_and_interpreter(
binary_path: os.PathLike[str],
lib_mount_path: pathlib.Path,
):
"""Patches the binary rpath and interpreter."""
subprocess.run(
[
"patchelf",
"--set-rpath",
lib_mount_path.as_posix(),
"--force-rpath",
binary_path,
],
check=True,
)

subprocess.run(
[
"patchelf",
"--set-interpreter",
(lib_mount_path / LD_BINARY_NAME).as_posix(),
binary_path,
],
check=True,
)


def get_library_mount_path(binary_id: str) -> pathlib.Path:
return pathlib.Path("/tmp") / (binary_id + "_lib")


def report_progress(stage: str, is_done: bool = False) -> None:
"""Reports progress of a stage of the snapshotting process."""
logging.info("%s%s", stage, "..." if not is_done else "")
Loading