From 515adf4fa7dcfb48e48a307f4812f8dcb981e428 Mon Sep 17 00:00:00 2001 From: Frederic Leger Date: Mon, 22 Jul 2024 12:04:33 +0200 Subject: [PATCH] Emit error if shared lib is not found 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 --- src/e3/anod/spec.py | 24 +++++++++++++++++------- tests/tests_e3/anod/spec_test.py | 32 ++++++++++++++++++++++++++++++-- 2 files changed, 47 insertions(+), 9 deletions(-) diff --git a/src/e3/anod/spec.py b/src/e3/anod/spec.py index 00530033..7fbef8d6 100644 --- a/src/e3/anod/spec.py +++ b/src/e3/anod/spec.py @@ -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:: @@ -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] = [] diff --git a/tests/tests_e3/anod/spec_test.py b/tests/tests_e3/anod/spec_test.py index 779ffb7a..47a553de 100644 --- a/tests/tests_e3/anod/spec_test.py +++ b/tests/tests_e3/anod/spec_test.py @@ -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,), + ), ] @@ -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 )