Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
Remove dead path handling code #280
This PR removes some path handling code that seems to be dead code. But “I have only proved it correct, not tried it.” Please test on real-world projects.
Summary of changes:
I believe that unclear objdir semantics might be related to the occasional “gcovr doesn't work with CMake” reports. This PR has no fix, but I now have a clearer understanding of this problem.
This commit removes unreachable/unnecessary link handling code. In particular: - os.path.realpath() already handles links properly, so no custom implementation is needed. - The PathAliaser capabilities are not exposed to users and can therefore be removed. This code could be removed because its caches were never written, only read from. I assume this code was originally written for Python versions that did not have sufficient support for symlinks? However, that is no longer an issue.
The find_potential_working_directories_via_objdir() function has various heuristics, and some seem to be dead code. The removed code had the following behaviour: let abs_filename be the absolute .gcda file name. Examples: (f1) "/the-project/build/foo.gcda" (f2) "/the-project/build/something/foo.gcda" let objdir be the object directory. Examples: (o1) "/the-project/build/" (o2) "../build/different/../" (o3) "/the-project/build/foo.gcda" (o4) "../build/foo.gcda" (o5) "../.." The objdir is normpath()'d, which folds parent directory segments away. Any remaining ".." segments will be at the start. Examples: (o1) "/the-project/build" (o2) "../build" (o3) "/the-project/build/foo.gcda" (o4) "../build/foo.gcda" (o5) "../.." Common trailing path segments are removed from both paths. This will only do anything if objdir points to that specific gcda file. Examples: (o1) (unchanged) (o2) (unchanged) (o3,f1) "" (paths are equal) (o3,f2) o:"/the-project/build", f:"/the-project/build/something" (basename is common) (o4,f1) o:".." f:"/the-project/" (o4,f2) o:"../build" f:"/the-project/build/something" (basename is common) (o5) (unchanged) If the objdir was completely matched, return no working dirs. This applies in case (o3,f1). If the objdir ends with a ".." segment (which can only happen if all remaining segments are ".." due to the normpath()), expand the remaining file names like a "*/" glob pattern (but always strip one extra segment). (o4,f1) glob "/*/" (o5,f1) glob "/the-project/build/*/*/" (o5,f2) glob "/the-project/build/something/*/*/" Since the objdir should be a directory and not a single gcda file, the (o3) and (o4) can never be encountered in practice. The (o5) case (objdir only consists of ".." segments) could be observed in practice, but would indicate an extremely weird build process. The resulting glob patterns have no reasonable interpretation and are unlikely to match a good working directory. The remaining heuristics can be matched and are left intact. Specifically: If the objdir is absolute: If the objdir exists it is returned as a working directory suggestion. This matches (o1) and (o3). If the objdir is relative, it is appended to a base path. As a base path, the CWD and the dirname(abs_filename) are tried. The following paths would be tested, any existing ones will be returned: (o2,f1) "/the-project/build/../build/different/../" (o2,f2) "/the-project/build/something/../build/different/../" (o2,cwd) "../build/different/../" (o4,f1) "/the-project/build/../build/" (o4,f2) "/the-project/build/something/../build/" (o4,cwd) "../build/" Some of these suggestions are unlikely to exist, e.g. the (f2) cases where the gcda is in a subdirectory. The only reasonable interpretation is that objdir might be intended as an unmodified path, but the other cases will have to stay for now.
@@ Coverage Diff @@ ## master #280 +/- ## ========================================== + Coverage 91.64% 94.22% +2.58% ========================================== Files 14 14 Lines 1591 1507 -84 Branches 281 260 -21 ========================================== - Hits 1458 1420 -38 + Misses 83 43 -40 + Partials 50 44 -6