tools/code_coverage/coverage_utils.py
def GetSharedLibraries(binary_paths, build_dir, otool_path):
  """Returns list of shared libraries used by specified binaries."""
  logging.info('Finding shared libraries for targets (if any).')
  shared_libraries = []
  cmd = []
  shared_library_re = None

  if sys.platform.startswith('linux'):
    cmd.extend(['ldd'])
    shared_library_re = re.compile(r'.*\.so[.0-9]*\s=>\s(.*' + build_dir +
                                   r'.*\.so[.0-9]*)\s.*')
  elif sys.platform.startswith('darwin'):
    otool = otool_path if otool_path else 'otool'
    cmd.extend([otool, '-L'])
    shared_library_re = re.compile(r'\s+(@rpath/.*\.dylib)\s.*')
  else:
    assert False, 'Cannot detect shared libraries used by the given targets.'

  assert shared_library_re is not None

  cmd.extend(binary_paths)
  output = subprocess.check_output(cmd).decode('utf-8', 'ignore')

  for line in output.splitlines():
    m = shared_library_re.match(line)
    if not m:
      continue

    shared_library_path = m.group(1)
    if sys.platform.startswith('darwin'):
      # otool outputs "@rpath" macro instead of the dirname of the given binary.
      shared_library_path = shared_library_path.replace('@rpath', build_dir)

    if shared_library_path in shared_libraries:
      continue

    assert os.path.exists(shared_library_path), ('Shared library "%s" used by '
                                                 'the given target(s) does not '
                                                 'exist.' % shared_library_path)
    with open(shared_library_path, 'rb') as f:
      data = f.read()

    # Do not add non-instrumented libraries. Otherwise, llvm-cov errors outs.
    if b'__llvm_cov' in data:
      shared_libraries.append(shared_library_path)

  logging.debug('Found shared libraries (%d): %s.', len(shared_libraries),
                shared_libraries)
  logging.info('Finished finding shared libraries for targets.')
  return shared_libraries
Returns list of shared libraries used by specified binaries.
Returns list of shared libraries used by specified binaries.
Returns list of shared libraries used by specified binaries .
def GetSharedLibraries(binary_paths, build_dir, otool_path):
  logging.info('Finding shared libraries for targets (if any).')
  shared_libraries = []
  cmd = []
  shared_library_re = None
  if sys.platform.startswith('linux'):
    cmd.extend(['ldd'])
    shared_library_re = re.compile(r'.*\.so[.0-9]*\s=>\s(.*' + build_dir +
                                   r'.*\.so[.0-9]*)\s.*')
  elif sys.platform.startswith('darwin'):
    otool = otool_path if otool_path else 'otool'
    cmd.extend([otool, '-L'])
    shared_library_re = re.compile(r'\s+(@rpath/.*\.dylib)\s.*')
  else:
    assert False, 'Cannot detect shared libraries used by the given targets.'
  assert shared_library_re is not None
  cmd.extend(binary_paths)
  output = subprocess.check_output(cmd).decode('utf-8', 'ignore')
  for line in output.splitlines():
    m = shared_library_re.match(line)
    if not m:
      continue
    shared_library_path = m.group(1)
    if sys.platform.startswith('darwin'):
      shared_library_path = shared_library_path.replace('@rpath', build_dir)
    if shared_library_path in shared_libraries:
      continue
    assert os.path.exists(shared_library_path), ('Shared library "%s" used by '
                                                 'the given target(s) does not '
                                                 'exist.' % shared_library_path)
    with open(shared_library_path, 'rb') as f:
      data = f.read()
    if b'__llvm_cov' in data:
      shared_libraries.append(shared_library_path)
  logging.debug('Found shared libraries (%d): %s.', len(shared_libraries),
                shared_libraries)
  logging.info('Finished finding shared libraries for targets.')
  return shared_libraries
def GetSharedLibraries ( binary_paths , build_dir , otool_path ) : logging . info ( 'Finding shared libraries for targets (if any).' ) shared_libraries = [ ] cmd = [ ] shared_library_re = None if sys . platform . startswith ( 'linux' ) : cmd . extend ( [ 'ldd' ] ) shared_library_re = re . compile ( r'.*\.so[.0-9]*\s=>\s(.*' + build_dir + r'.*\.so[.0-9]*)\s.*' ) elif sys . platform . startswith ( 'darwin' ) : otool = otool_path if otool_path else 'otool' cmd . extend ( [ otool , '-L' ] ) shared_library_re = re . compile ( r'\s+(@rpath/.*\.dylib)\s.*' ) else : assert False , 'Cannot detect shared libraries used by the given targets.' assert shared_library_re is not None cmd . extend ( binary_paths ) output = subprocess . check_output ( cmd ) . decode ( 'utf-8' , 'ignore' ) for line in output . splitlines ( ) : m = shared_library_re . match ( line ) if not m : continue shared_library_path = m . group ( 1 ) if sys . platform . startswith ( 'darwin' ) : shared_library_path = shared_library_path . replace ( '@rpath' , build_dir ) if shared_library_path in shared_libraries : continue assert os . path . exists ( shared_library_path ) , ( 'Shared library "%s" used by ' 'the given target(s) does not ' 'exist.' % shared_library_path ) with open ( shared_library_path , 'rb' ) as f : data = f . read ( ) if b'__llvm_cov' in data : shared_libraries . append ( shared_library_path ) logging . debug ( 'Found shared libraries (%d): %s.' , len ( shared_libraries ) , shared_libraries ) logging . info ( 'Finished finding shared libraries for targets.' ) return shared_libraries
Returns list of shared libraries used by specified binaries.
Returns list of shared libraries used by specified binaries .
"""Returns list of shared libraries used by specified binaries.""" # otool outputs "@rpath" macro instead of the dirname of the given binary. # Do not add non-instrumented libraries. Otherwise, llvm-cov errors outs.
binary_paths
build_dir
otool_path