Skip to content

Commit

Permalink
Emit error if shared lib is not found
Browse files Browse the repository at this point in the history
The `check_shared_libraries_closure()` method does not raise an
exception if one of the share libraries is not found.

As the goals here is to make sure the shared libraries link with
appropriate shared libraries, the check should also raise an error
if a `not found` message is returned by `lld`.

An error is now raised when the `not found` message is raised by one
of the shared libraries.

Closes #7
  • Loading branch information
grouigrokon committed Jul 22, 2024
1 parent 502cad9 commit 515adf4
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 9 deletions.
24 changes: 17 additions & 7 deletions src/e3/anod/spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,23 @@ def check_shared_libraries_closure(
# Line looks like:
# `` otherdll.so => /other/otherdll.so (0xabcd)``
name, path = line.strip().split(" => ", 1)

if case_sensitive:
in_ignored = len([k for k in ignored if name.startswith(k)]) > 0
else:
in_ignored = (
len([k for k in ignored if name.lower().startswith(k.lower())])
> 0
)

# Make sure there are no "not found" errors
if "not found" in line.lower():
if not in_ignored:
if lib_file not in errors:
errors[lib_file] = []
errors[lib_file].append(f"\n\t- {name}: {path}")
continue

path = re.sub(" (.*)", "", path)

# Make sure a path is defined, we may have lines like::
Expand All @@ -494,13 +511,6 @@ def check_shared_libraries_closure(
if not path.strip() or not Path(path).exists():
continue

if case_sensitive:
in_ignored = len([k for k in ignored if name.startswith(k)]) > 0
else:
in_ignored = (
len([k for k in ignored if name.lower().startswith(k.lower())])
> 0
)
if os.path.relpath(path, root_dir).startswith("..") and not in_ignored:
if lib_file not in errors:
errors[lib_file] = []
Expand Down
32 changes: 30 additions & 2 deletions tests/tests_e3/anod/spec_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,34 @@
),
),
),
(
(
(
"/usr/bin/ls:\n"
"\tlinux-vdso.so.1 (0xxxx)\n"
"\tlibselinux.so.1 => /lib/x86_64-linux-gnu/libselinux.so.1 (0xxxx)\n"
"\tlibc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0xxxx)\n"
"\tlibpcre2-8.so.0 => not found\n"
"\t/lib64/ld-linux-x86-64.so.2 (0xxxx)\n"
),
["libc.so.6", "libselinux.so.1"],
),
(("- libpcre2-8.so.0: not found"),),
),
(
(
(
"/usr/bin/ls:\n"
"\tlinux-vdso.so.1 (0xxxx)\n"
"\tlibselinux.so.1 => /lib/x86_64-linux-gnu/libselinux.so.1 (0xxxx)\n"
"\tlibc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0xxxx)\n"
"\tlibpcre2-8.so.0 => not found\n"
"\t/lib64/ld-linux-x86-64.so.2 (0xxxx)\n"
),
["libc.so.6", "libselinux.so.1", "libpcre2-8.so.0"],
),
(None,),
),
]


Expand Down Expand Up @@ -173,13 +201,13 @@ def test_spec_check_dll_closure(ldd, arguments: tuple, expected: tuple) -> None:
elif errors:
with pytest.raises(AnodError) as ae:
test_spec.check_shared_libraries_closure(
prefix=None, ignored_libs=None, ldd_output=ldd_output
prefix=None, ignored_libs=ignored, ldd_output=ldd_output
)
assert errors in ae.value.args[0]
else:
# There is an ldd_output, but no errors may be raised on unix hosts.
test_spec.check_shared_libraries_closure(
prefix=None, ignored_libs=None, ldd_output=ldd_output
prefix=None, ignored_libs=ignored, ldd_output=ldd_output
)


Expand Down

0 comments on commit 515adf4

Please sign in to comment.