[PATCH] D62508: gn build: Make it possible to build with coverage information

Nico Weber via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon May 27 18:11:25 PDT 2019


thakis created this revision.
thakis added reviewers: pcc, phosek.
Herald added a project: LLVM.
thakis added a comment.

I'm not sure this does the right thing in a multi-toolchain setup. It seems to do the trick in normal macOS builds though.


https://reviews.llvm.org/D62508

Files:
  llvm/utils/gn/build/BUILD.gn


Index: llvm/utils/gn/build/BUILD.gn
===================================================================
--- llvm/utils/gn/build/BUILD.gn
+++ llvm/utils/gn/build/BUILD.gn
@@ -3,6 +3,19 @@
 import("//llvm/utils/gn/build/toolchain/compiler.gni")
 import("//llvm/utils/gn/build/toolchain/target_flags.gni")
 
+declare_args() {
+  # Whether to build everything with coverage information.
+  # After building with this, run tests and then run
+  #    llvm/utils/prepare-code-coverage-artifact.py  \
+  #        .../llvm-profdata .../llvm-cov out/gn/profiles/ report/ \
+  #        out/gn/bin/llvm-undname ...`
+  # to generate a HTML report for the binaries passed in the last line.
+  llvm_build_instrumented_coverage = false
+}
+
+assert(!llvm_build_instrumented_coverage || is_clang,
+       "llvm_build_instrumented_coverage requires clang as host compiler")
+
 config("compiler_defaults") {
   defines = []
 
@@ -136,6 +149,21 @@
   if (use_lld && host_os != "win") {
     ldflags += [ "-fuse-ld=lld" ]
   }
+
+  if (llvm_build_instrumented_coverage) {
+    cflags += [
+      "-fcoverage-mapping",
+
+      # Using an absolute path here is lame, but it's used at test execution
+      # time to generate the profiles, and lit doesn't specify a fixed folder
+      # for test execution -- so this is the only way to get all profiles into
+      # a single folder like llvm/utils/prepare-code-coverage-artifact.py
+      # expects.
+      "-fprofile-instr-generate=" +
+          rebase_path("$root_build_dir/profiles/%4m.profraw"),
+    ]
+    ldflags += [ "-fprofile-instr-generate" ]
+  }
 }
 
 config("no_exceptions") {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D62508.201602.patch
Type: text/x-patch
Size: 1622 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190528/ddf4505b/attachment.bin>


More information about the llvm-commits mailing list