Skip to content

Commit

Permalink
detect and add binary search paths
Browse files Browse the repository at this point in the history
Signed-off-by: Zen <[email protected]>
  • Loading branch information
desultory committed Feb 14, 2025
1 parent 1603054 commit 4aca27d
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/ugrd/base/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,26 @@ def _process_binaries_multi(self, binary: str) -> None:

self.logger.debug("Adding binary: %s" % binary)
self["binaries"].append(binary)
self["binary_search_paths"] = dependencies[0].parent # Add the binary path to the search paths

def _process_binary_search_paths_multi(self, search_path: Path) -> None:
""" Adds a binary search path to the binary search paths list. """
search_path = Path(search_path)

if str(search_path) in self["binary_search_paths"]:
return self.logger.debug("Binary search path already in list, skipping: %s" % search_path)

while search_path.is_symlink(): # Resolve symlinks
search_path = search_path.resolve()

if not search_path.is_dir(): # If the path is not a directory, use the parent directory
search_path = search_path.parent

if str(search_path) in self["binary_search_paths"]: # Check again after resolving symlinks
return self.logger.debug("Binary search path already in list, skipping: %s" % search_path)

self.logger.info("Adding binary search path: %s" % search_path)
self.data["binary_search_paths"].append(str(search_path))


def _validate_dependency(self, dependency: Union[Path, str]) -> None:
Expand Down
3 changes: 3 additions & 0 deletions src/ugrd/base/core.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@ merge_usr = true
hostonly = true
validate = true
library_paths = [ "/lib64" ]
binary_search_paths = ["/bin"]
old_count = 1
timeout = 15

[imports.config_processing]
"ugrd.base.core" = [ "_process_build_logging",
"_process_out_file",
"_process_binaries_multi",
"_process_binary_search_paths_multi",
"_process_libraries_multi",
"_process_dependencies_multi",
"_process_opt_dependencies_multi",
Expand Down Expand Up @@ -68,6 +70,7 @@ library_paths = "NoDupFlatList" # library_paths property, used to define the li
find_libgcc = "bool" # If true, the initramfs will search for libgcc_s.so.1 and add it to the initramfs
libraries = "NoDupFlatList" # Additional libraries, by name, added to the initramfs
binaries = "NoDupFlatList" # Binaries which should be included in the intiramfs, dependencies resolved with lddtree
binary_search_paths = "NoDupFlatList" # Binary paths, used to define the paths to search for binaries
copies = "dict" # Copies dict, defines the files to be copied to the initramfs
nodes = "dict" # Nodes dict, defines the device nodes to be created
paths = "NoDupFlatList" # Paths to be created in the initramfs
Expand Down
5 changes: 5 additions & 0 deletions src/ugrd/initramfs_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,11 @@ def generate_profile(self) -> list[str]:
self.logger.debug("Library paths: %s" % library_paths)
out.append(f"export LD_LIBRARY_PATH={library_paths}")

# Add search paths
search_paths = ":".join(self["binary_search_paths"])
self.logger.debug("Search paths: %s" % search_paths)
out.append(f"export PATH={search_paths}:$PATH")

for func_name, func_content in self.included_functions.items():
out.append("\n\n" + func_name + "() {")
if isinstance(func_content, str):
Expand Down

0 comments on commit 4aca27d

Please sign in to comment.