diff options
| -rwxr-xr-x | git-coverage | 40 |
1 files changed, 26 insertions, 14 deletions
diff --git a/git-coverage b/git-coverage index f14f744..11f5202 100755 --- a/git-coverage +++ b/git-coverage @@ -283,15 +283,24 @@ class GccCoverage: paths.append(os.path.abspath(path)) os.path.walk(".", visit, self._gcno_unresolved) - def _directory_gcno_compiled_in(self, gcno): - (directory, base) = os.path.split(gcno) - - # libtool always gets it's grubby little fingers involved - (parent, last) = os.path.split(directory) - if last == ".libs": - return parent - - return directory + def _directory_gcno_compiled_in(self, gcno, source): + (directory, unused) = os.path.split(gcno) + (srcdir, unused) = os.path.split(source) + + # Remove any common bits from gcno and source + # paths to account for automake subdir-objects + while True: + (parent, last) = os.path.split(directory) + (sparent, slast) = os.path.split(srcdir) + + # libtool always gets it's grubby little fingers involved + if last == ".libs": + directory = parent + elif last == slast: + directory = parent + srcdir = sparent + else: + return directory def _add_to_gcno_cache(self, gcno, source): if source not in self._gcno_cache: @@ -315,7 +324,7 @@ class GccCoverage: resolve.append(gcno) no_gcda = False - cmd = ['gcov', '--preserve-paths', '--relative-only', '--no-output'] + cmd = ['gcov', '--preserve-paths', '--no-output'] for gcno in resolve: self._gcno_unresolved.remove(gcno) @@ -330,13 +339,14 @@ class GccCoverage: # Run the gcno file through gcov in the --no-output mode # which will tell us the source file(s) it represents - directory = self._directory_gcno_compiled_in(gcno) for line in subprocess_lines(cmd + [gcno]): match = self._file_re.match(line.strip()) if not match: continue filename = match.group(1) + directory = self._directory_gcno_compiled_in(gcno, filename) + # We've found a gcno/source combination, make note of it path = os.path.join(directory, filename) self._add_to_gcno_cache(gcno, os.path.normpath(path)) @@ -347,7 +357,9 @@ class GccCoverage: matches = [] bad_mtime = False gcnos = self._gcno_cache.get(source, []) - mtime = os.path.getmtime(source) + mtime = 0 + if os.path.exists(source): + mtime = os.path.getmtime(source) for gcno in gcnos: # If the source file has been modified later than the @@ -375,12 +387,12 @@ class GccCoverage: for gcno in self._lookup_gcno_files(filename): # Need to run gcov in the same directory compiled in - directory = self._directory_gcno_compiled_in(gcno) + directory = self._directory_gcno_compiled_in(gcno, filename) oldcwd = os.getcwd() os.chdir(directory) gcovs = [] - cmd = ['gcov', '--preserve-paths', '--relative-only'] + cmd = ['gcov', '--preserve-paths'] for line in subprocess_lines(cmd + [gcno]): match = self._creating_re.match(line.strip()) if not match: |
