def find_libs()

in pack.py [0:0]


def find_libs(kp, system):
  if system == 'Darwin':
    ldd = 'otool -L'
    starting_line = 1
    extension = '.dylib'
  elif system == 'Linux':
    ldd = 'ldd'
    starting_line = 0
    extension = '.so'
  else:
    return []

  def get_names(path):
    if not os.path.isfile(path):
      print('Warning: ' + path + ' doesn\'t exist. This is fine if that\'s a ' +
        'system library that can expected to be found elsewhere.')
      return None

    libs = shell(ldd + ' ' + path)
    libs = [x for x in libs[starting_line:] if extension in x]
    libs = [x.split(' ')[0] for x in libs]
    libs = [x.split('/')[-1] for x in libs]
    return libs

  all_libs = set(get_names('/'.join(kp)))
  not_found = set()
  while True:
    new_set = set()
    for lib in all_libs:
      deps = get_names('third_party/lib/' + lib)
      if deps is None:
        not_found.add(lib)
      else:
        new_set.update(deps)
    old_len = len(all_libs)
    all_libs.update(new_set)
    if len(all_libs) == old_len:
      break

  for lib in not_found:
    all_libs.remove(lib)

  return list(all_libs)