parameters: (options)
docstring: Implements the 'merge' action of this tool.
docstring_summary: Implements the 'merge' action of this tool.
docstring_tokens: Implements the merge action of this tool .
function: def merge(options):
    """Implements the 'merge' action of this tool."""
  
    # Check if folder with coverage output exists.
    assert (os.path.exists(options.coverage_dir) and
            os.path.isdir(options.coverage_dir))
  
    # Inputs for multiprocessing. List of tuples of:
    # Coverage dir, absoluate path to executable, sancov file name.
    inputs = []
    for sancov_file in os.listdir(options.coverage_dir):
      match = SANCOV_FILE_RE.match(sancov_file)
      if match:
        inputs.append((
            options.coverage_dir,
            os.path.join(options.build_dir, match.group(1)),
            sancov_file,
        ))
  
    logging.info('Merging %d sancov files into %s',
                 len(inputs), options.json_input)
  
    # Post-process covered lines in parallel.
    pool = Pool(CPUS)
    try:
      results = pool.imap_unordered(get_covered_lines, inputs)
    finally:
      pool.close()
  
    # Load existing json data file for merging the results.
    with open(options.json_input, 'r') as f:
      data = json.load(f)
  
    # Merge muliprocessing results. Mutates data.
    merge_covered_line_results(data, results)
  
    logging.info('Merged data from %d executables, which covers %d files.',
                 len(data['tests']), len(data['files']))
    logging.info('Writing results to %s', options.json_output)
  
    # Write merged results to file.
    with open(options.json_output, 'w') as f:
      json.dump(data, f, sort_keys=True)
function_tokens: def merge ( options ) : # Check if folder with coverage output exists. assert ( os . path . exists ( options . coverage_dir ) and os . path . isdir ( options . coverage_dir ) ) # Inputs for multiprocessing. List of tuples of: # Coverage dir, absoluate path to executable, sancov file name. inputs = [ ] for sancov_file in os . listdir ( options . coverage_dir ) : match = SANCOV_FILE_RE . match ( sancov_file ) if match : inputs . append ( ( options . coverage_dir , os . path . join ( options . build_dir , match . group ( 1 ) ) , sancov_file , ) ) logging . info ( 'Merging %d sancov files into %s' , len ( inputs ) , options . json_input ) # Post-process covered lines in parallel. pool = Pool ( CPUS ) try : results = pool . imap_unordered ( get_covered_lines , inputs ) finally : pool . close ( ) # Load existing json data file for merging the results. with open ( options . json_input , 'r' ) as f : data = json . load ( f ) # Merge muliprocessing results. Mutates data. merge_covered_line_results ( data , results ) logging . info ( 'Merged data from %d executables, which covers %d files.' , len ( data [ 'tests' ] ) , len ( data [ 'files' ] ) ) logging . info ( 'Writing results to %s' , options . json_output ) # Write merged results to file. with open ( options . json_output , 'w' ) as f : json . dump ( data , f , sort_keys = True )