]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
Handle missing .gcno file gracefully
authorJoel Rosdahl <joel@rosdahl.net>
Thu, 1 Oct 2020 11:00:30 +0000 (13:00 +0200)
committerJoel Rosdahl <joel@rosdahl.net>
Thu, 1 Oct 2020 11:13:34 +0000 (13:13 +0200)
GCC ≥9 has changed behavior for -ftest-coverage and --coverage in
combination with -fprofile-dir=dir:

- Without -fprofile-dir=dir the file is placed next to the object file
  but with a “.gcno” extension.
- With -fprofile-dir=dir the file is also place next to the object file
  (i.e. not in the specified profile directory) but the same style of
  name as used for “.gcda” files (full pathname with slashes replaced
  with hash characters).

Fix this by:

- Checking if the expected (GCC <9) .gcno file is present. If not, fall
  back to running the compiler and increment the “unsupported option”
  counter.
- Making sure to perform the above check before copying the object file
  to the cache so that a later ccache invocation won’t believe that
  there is a result in the cache.
- Improving the copy_file routine to not create the destination file
  until it knows that there is a source file to copy from.

Fixes #674.

(cherry picked from commit 6abd78b5ec7cdfeedff36454b07a8dbff312b554)

src/ccache.cpp

index d620ce9c0f1cf039f275a44edf548755b2db9e86..f27e011f6838c751c0b4ba996f42687ed1941abe 100644 (file)
@@ -992,6 +992,15 @@ to_cache(Context& ctx,
     result_writer.write(Result::FileType::dependency, ctx.args_info.output_dep);
   }
   if (ctx.args_info.generating_coverage) {
+    if (!Stat::stat(ctx.args_info.output_cov)) {
+      // The .gcno file is missing. This is likely due to compiling with GCC 9+,
+      // which uses another name for the .gcno file when using -ftest-coverage
+      // or --coverage when -fprofile-dir=dir is given. The .gcno file is still
+      // placed next to the object file, not in the specified profile directory,
+      // though.
+      log("{} is missing", ctx.args_info.output_cov);
+      throw Failure(Statistic::unsupported_compiler_option);
+    }
     result_writer.write(Result::FileType::coverage, ctx.args_info.output_cov);
   }
   if (ctx.args_info.generating_stackusage) {