filter-lcov.py raw

   1  #!/usr/bin/env python3
   2  # Copyright (c) 2017-present The Bitcoin Core developers
   3  # Distributed under the MIT software license, see the accompanying
   4  # file COPYING or http://www.opensource.org/licenses/mit-license.php.
   5  
   6  import argparse
   7  
   8  parser = argparse.ArgumentParser(description='Remove the coverage data from a tracefile for all files matching the pattern.')
   9  parser.add_argument('--pattern', '-p', action='append', help='the pattern of files to remove', required=True)
  10  parser.add_argument('tracefile', help='the tracefile to remove the coverage data from')
  11  parser.add_argument('outfile', help='filename for the output to be written to')
  12  
  13  args = parser.parse_args()
  14  tracefile = args.tracefile
  15  pattern = args.pattern
  16  outfile = args.outfile
  17  
  18  in_remove = False
  19  with open(tracefile, 'r') as f:
  20      with open(outfile, 'w') as wf:
  21          for line in f:
  22              for p in pattern:
  23                  if line.startswith("SF:") and p in line:
  24                      in_remove = True
  25              if not in_remove:
  26                  wf.write(line)
  27              if line == 'end_of_record\n':
  28                  in_remove = False
  29