parameters: (possible_gcov_files, source_files)
return_statement: return results
docstring: Takes a list of gcov filenames and a list of source filenames.
  
      The gcov files should have names of the form foo.o##foo.cc.gcov, as
      created by 'gcov -l'.
  
      Returns a dict mapping source filenames to tuples
        (total_lines, tested_lines, gcov_annotated_source)
      which are a number, a number, and a very long string, respectively.
  
      The fun bit is that we merge .gcov output generated by different object
      files; this way we can provide accurate information for header files and
      for monotone's current unit test system.
docstring_summary: Takes a list of gcov filenames and a list of source filenames.
docstring_tokens: Takes a list of gcov filenames and a list of source filenames .
function: def scan_gcov_files(possible_gcov_files, source_files):
      """Takes a list of gcov filenames and a list of source filenames.
  
      The gcov files should have names of the form foo.o##foo.cc.gcov, as
      created by 'gcov -l'.
  
      Returns a dict mapping source filenames to tuples
        (total_lines, tested_lines, gcov_annotated_source)
      which are a number, a number, and a very long string, respectively.
  
      The fun bit is that we merge .gcov output generated by different object
      files; this way we can provide accurate information for header files and
      for monotone's current unit test system."""
      results = {}
      for f in source_files:
          possible_gcovs = find_gcov(f, possible_gcov_files)
          base_name = os.path.splitext(os.path.basename(f))[0]
          if len(possible_gcovs) == 0:
              print "No gcov files found for: '%s' but it was compiled" % f
              continue
  
              (garbage,extension) = os.path.splitext(f)
              if extension  in [".cc", ".c", ".moc", ".cpp", ".cxx", ".m", ".mm"]:
                  lines = open(f, "r").readlines()
                  results[f] = (len(lines), 0, "".join(lines))
              continue
          elif len(possible_gcovs) > 1:
              print "More than one gcov file for %s %d" % (f,len(possible_gcovs))
          base_gcov_lines = parse_source_file(possible_gcovs[0])
  
          # Now we will try hard to merge the results with others
          # Our requirement is that we have the same amount of lines as
          # as the original file
          for cov_file in possible_gcovs:
              lines = open(cov_file, "r").readlines()
  
              # e.g. with phonon we have visualisation.h and we can not know
              # which header file (foldername) it is refering to. This is a gcov
              # limitation and i have no workaround yet. We just hope we will pick
              # the right header file...
              if len(lines) != len(base_gcov_lines):
                  print "Error Base: %s and Target: %s have different amount of lines" % (possible_gcovs[0],cov_file)
                  continue
  
              # now do the merging of the file. If it has the same basename
              # and the same number of lines things might work out
              # In the future take a look at the header of the file
              i = 0
              for line in lines:
                  accumulator = base_gcov_lines[i]
                  if accumulator[0] != STATE_TEST_CODE:
                      info = line.split(":", 1)[0]
                      if info.endswith("-"):
                          if accumulator[0] == STATE_NOT_SEEN:
                              accumulator[0] = STATE_NOT_CODE
                      else:
                          if info.endswith("#"):
                              num = 0
                          else:
                              num = int(info)
                          if accumulator[0] in (STATE_NOT_SEEN, STATE_NOT_CODE):
                              accumulator[0] = 0
                          accumulator[0] += num
                  i += 1
  
          # post processing of ths file
          (total_lines, total_covered) = (0, 0)
          annotated_lines = []
          for state, line in base_gcov_lines:
              if state == STATE_NOT_SEEN:
                  desc = "?????"
              elif state == STATE_TEST_CODE:
                  desc = "+"
              elif state == STATE_NOT_CODE:
                  desc = "-"
              elif state == 0:
                  desc = "#####"
                  total_lines += 1
              else:
                  desc = str(state)
                  total_lines += 1
                  total_covered += 1
              annotated_lines.append(":".join([desc.rjust(9), line]))
          results[f] = (total_lines, total_covered, "".join(annotated_lines))
      return results
  
  
  
      return results
function_tokens: def scan_gcov_files ( possible_gcov_files , source_files ) : results = { } for f in source_files : possible_gcovs = find_gcov ( f , possible_gcov_files ) base_name = os . path . splitext ( os . path . basename ( f ) ) [ 0 ] if len ( possible_gcovs ) == 0 : print "No gcov files found for: '%s' but it was compiled" % f continue ( garbage , extension ) = os . path . splitext ( f ) if extension in [ ".cc" , ".c" , ".moc" , ".cpp" , ".cxx" , ".m" , ".mm" ] : lines = open ( f , "r" ) . readlines ( ) results [ f ] = ( len ( lines ) , 0 , "" . join ( lines ) ) continue elif len ( possible_gcovs ) > 1 : print "More than one gcov file for %s %d" % ( f , len ( possible_gcovs ) ) base_gcov_lines = parse_source_file ( possible_gcovs [ 0 ] ) # Now we will try hard to merge the results with others # Our requirement is that we have the same amount of lines as # as the original file for cov_file in possible_gcovs : lines = open ( cov_file , "r" ) . readlines ( ) # e.g. with phonon we have visualisation.h and we can not know # which header file (foldername) it is refering to. This is a gcov # limitation and i have no workaround yet. We just hope we will pick # the right header file... if len ( lines ) != len ( base_gcov_lines ) : print "Error Base: %s and Target: %s have different amount of lines" % ( possible_gcovs [ 0 ] , cov_file ) continue # now do the merging of the file. If it has the same basename # and the same number of lines things might work out # In the future take a look at the header of the file i = 0 for line in lines : accumulator = base_gcov_lines [ i ] if accumulator [ 0 ] != STATE_TEST_CODE : info = line . split ( ":" , 1 ) [ 0 ] if info . endswith ( "-" ) : if accumulator [ 0 ] == STATE_NOT_SEEN : accumulator [ 0 ] = STATE_NOT_CODE else : if info . endswith ( "#" ) : num = 0 else : num = int ( info ) if accumulator [ 0 ] in ( STATE_NOT_SEEN , STATE_NOT_CODE ) : accumulator [ 0 ] = 0 accumulator [ 0 ] += num i += 1 # post processing of ths file ( total_lines , total_covered ) = ( 0 , 0 ) annotated_lines = [ ] for state , line in base_gcov_lines : if state == STATE_NOT_SEEN : desc = "?????" elif state == STATE_TEST_CODE : desc = "+" elif state == STATE_NOT_CODE : desc = "-" elif state == 0 : desc = "#####" total_lines += 1 else : desc = str ( state ) total_lines += 1 total_covered += 1 annotated_lines . append ( ":" . join ( [ desc . rjust ( 9 ) , line ] ) ) results [ f ] = ( total_lines , total_covered , "" . join ( annotated_lines ) ) return results return results