def GetActualFilePathAndType(shortname): actual_lib_path = ldtools.FindFile([shortname], env.get('SEARCH_DIRS'), ldtools.LibraryTypes.ANY) if actual_lib_path == None: Log.Warning('Could not find path of lib: %s, assuming it is native', shortname) file_type = 'so' else: file_type = FileType(actual_lib_path) return actual_lib_path, file_type
def GetTransitiveClosureOfNeeded(base_needed): visited_portable = set() visited_native = set() all_needed = set(base_needed) worklist = deque(base_needed) while len(worklist) != 0: lib = worklist.popleft() if lib in visited_portable or lib in visited_native: continue actual_lib_path, file_type = GetActualFilePathAndType(lib) if file_type == 'so': # We could trace if we used objdump / readelf... Log.Warning('Not tracing dependencies of native lib %s', lib) visited_native.add(lib) continue elif file_type == 'pso': visited_portable.add(lib) more_needed = GetBitcodeMetadata(actual_lib_path).get( 'NeedsLibrary', []) all_needed |= set(more_needed) worklist.extend(more_needed) else: Log.Fatal('Lib: %s is neither bitcode nor native', lib) return all_needed