auto-patchelf: add IgnoredDependency event

This logs when there was a missing dependency that was matched by an
ignore pattern.

The test case is extended to also check for having the IgnoredDependency
events in the structured log output.
This commit is contained in:
Florian Klink 2026-01-27 13:20:46 +02:00
parent 45a5479dc1
commit c45f008187
2 changed files with 18 additions and 5 deletions

View file

@ -256,6 +256,15 @@ class SetInterpreter:
return f"setting interpreter of {self.file}"
@dataclass
class IgnoredDependency:
file: Path # The file that contains the ignored dependency
name: Path # The name of the dependency
pattern: str # The pattern that caused this missing dep to be ignored
def to_human_readable_str(self) -> str:
return f"warn: auto-patchelf ignoring missing {self.name} wanted by {self.file}"
@dataclass
class Dependency:
file: Path # The file that contains the dependency
@ -464,7 +473,7 @@ def auto_patchelf(
for dep in missing:
for pattern in ignore_missing:
if fnmatch(dep.name.name, pattern):
logger.debug(f"warn: auto-patchelf ignoring missing {dep.name} wanted by {dep.file}")
logger.log(IgnoredDependency(file=dep.file, name=dep.name, pattern=pattern))
break
else:
logger.debug(f"error: auto-patchelf could not satisfy dependency {dep.name} wanted by {dep.file}")

View file

@ -31,7 +31,8 @@ stdenv.mkDerivation {
auto-patchelf \
--paths ./usr/bin/ToneLib-Jam \
--libs ${lib.getLib freetype}/lib \
--structured-logs > log.jsonl || true
--ignore-missing "libasound.so.*" "libGL.so.*" \
--structured-logs | tee log.jsonl
# Expect 1 SetInterpreter line
jq -e -s '[.[] | select(has("SetInterpreter"))] | length == 1' log.jsonl
@ -39,13 +40,16 @@ stdenv.mkDerivation {
# We expect 3 Dependency lines
jq -e -s '[.[] | select(has("Dependency"))] | length == 3' log.jsonl
# Expect the last line to set the rpath as expected
jq -e -s 'last == {
# We expect 2 IgnoredDependency lines
jq -e -s '[.[] | select(has("IgnoredDependency"))] | length == 2' log.jsonl
# Expect there to be a SetRpath event using the expected rpath
jq -e -s 'any(.[]; . == {
"SetRpath": {
"file": "usr/bin/ToneLib-Jam",
"rpath": "${lib.getLib freetype}/lib"
}
}' log.jsonl
})' log.jsonl
cp log.jsonl $out
'';