diff --git a/tools/deps_guard/elf_file_mgr/elf_file.py b/tools/deps_guard/elf_file_mgr/elf_file.py index 40709e100709eeb34ce12b9cf5d30cb964175d87..f119ed117bb219488af2bd9688441adaf6ab0cab 100755 --- a/tools/deps_guard/elf_file_mgr/elf_file.py +++ b/tools/deps_guard/elf_file_mgr/elf_file.py @@ -19,7 +19,7 @@ import os from stat import ST_SIZE -from .utils import command +from .utils import command, command_without_error class ElfFile(dict): @@ -53,24 +53,14 @@ class ElfFile(dict): def library_depends(self): if not os.access(self._f, os.F_OK): raise Exception("Cannot find lib: " + self._f) - dynamics = command("readelf", "--dynamic", self._f_safe) + file_name = self._f_safe.split("/")[-1].strip("'") + dynamics = command_without_error("strings", self._f_safe, f"|grep -E lib_.so|grep -v {file_name}") res = [] - for line in dynamics: - pos = line.find("(NEEDED)") - if pos <= 0: - continue - line = line[pos + 8:] - line = line.strip() - if not line.startswith("Shared library:"): - continue - line = line[15:] - line = line.strip() - if line.startswith("["): - line = line[1:] - if line.endswith("]"): - line = line[:-1] - line = line.strip() - res.append(line) + if dynamics: + for line in dynamics: + if line.startswith("lib") and line.endswith(".so"): + res.append(line) + return res def __extract_soname(self): diff --git a/tools/deps_guard/elf_file_mgr/utils.py b/tools/deps_guard/elf_file_mgr/utils.py index 1894a3add583ed02b883723235edf1b187b61e31..087c55195d58321ad594f9efe24a14fdad7e10e5 100755 --- a/tools/deps_guard/elf_file_mgr/utils.py +++ b/tools/deps_guard/elf_file_mgr/utils.py @@ -44,3 +44,11 @@ def command(command, *args): print("With output:", output) sys.exit(1) return [i for i in output.split('\n') if i] + +# return a list of lines of output of the command without reminding errors +def command_without_error(command, *args): + debug(DEBUG_SPAM, "calling", command, ' '.join(args)) + pipe = os.popen(command + ' ' + ' '.join(args), 'r') + output = pipe.read().strip() + status = pipe.close() + return [i for i in output.split('\n') if i] diff --git a/tools/deps_guard/rules/NO-Depends-On-NAPI/whitelist.json b/tools/deps_guard/rules/NO-Depends-On-NAPI/whitelist.json index 1020050686fed9e03cb6e996ee232b12a0b2532e..91ea33b6f3a2d008664ced86c97dac9b879de241 100644 --- a/tools/deps_guard/rules/NO-Depends-On-NAPI/whitelist.json +++ b/tools/deps_guard/rules/NO-Depends-On-NAPI/whitelist.json @@ -2,5 +2,6 @@ "accessibility", "remote_file_share_native", "medialibrary", - "utils" + "utils", + "usbmanager" ]