diff options
author | Erik Abair <abaire@google.com> | 2016-08-23 16:52:53 +0000 |
---|---|---|
committer | John Cater <jcater@google.com> | 2016-08-23 22:58:10 +0000 |
commit | 30a91955420e6b6fa9a5fc6b7488ca4a9e12597d (patch) | |
tree | f22a21f9b42cc3f3973f58b4fc74eeb666e942b1 /src | |
parent | b6fd4ed25b6201eaaabb14c389c02819184ad4a6 (diff) |
Adds a flag to generate LLVM coverage symbols.
This change adds a new --experimental_use_llvm_covmap flag which may
be used in conjunction with the --collect_code_coverage flag to
generate LLVM style coverage symbols instead of gcov.
--
MOS_MIGRATED_REVID=131065609
Diffstat (limited to 'src')
3 files changed, 60 insertions, 12 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/config/BuildConfiguration.java b/src/main/java/com/google/devtools/build/lib/analysis/config/BuildConfiguration.java index d516d17dfa..ec53d74de3 100644 --- a/src/main/java/com/google/devtools/build/lib/analysis/config/BuildConfiguration.java +++ b/src/main/java/com/google/devtools/build/lib/analysis/config/BuildConfiguration.java @@ -649,6 +649,14 @@ public final class BuildConfiguration { + "'//tools/test:coverage_report_generator'.") public Label coverageReportGenerator; + @Option(name = "experimental_use_llvm_covmap", + defaultValue = "false", + category = "experimental", + help = "If specified, Bazel will generate llvm-cov coverage map information rather than " + + "gcov when collect_code_coverage is enabled." + ) + public boolean useLLVMCoverageMapFormat; + @Option(name = "cache_test_results", defaultValue = "auto", category = "testing", @@ -2237,6 +2245,10 @@ public final class BuildConfiguration { return options.collectMicroCoverage; } + public boolean isLLVMCoverageMapFormatEnabled() { + return options.useLLVMCoverageMapFormat; + } + public boolean isActionsEnabled() { return actionsEnabled; } diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppConfiguration.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppConfiguration.java index 70af928677..e9a89c782c 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppConfiguration.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppConfiguration.java @@ -333,6 +333,7 @@ public class CppConfiguration extends BuildConfiguration.Fragment { private final boolean stripBinaries; private final String solibDirectory; private final CompilationMode compilationMode; + private final boolean useLLVMCoverageMap; /** * If true, the ConfiguredTarget is only used to get the necessary cross-referenced @@ -353,6 +354,7 @@ public class CppConfiguration extends BuildConfiguration.Fragment { this.crosstoolTop = params.crosstoolTop; this.ccToolchainLabel = params.ccToolchainLabel; this.compilationMode = params.commonOptions.compilationMode; + this.useLLVMCoverageMap = params.commonOptions.useLLVMCoverageMapFormat; this.lipoContextCollector = cppOptions.lipoCollector; @@ -947,6 +949,30 @@ public class CppConfiguration extends BuildConfiguration.Fragment { toolchainBuilder); } if (!features.contains("coverage")) { + String compileFlags; + String linkerFlags; + if (useLLVMCoverageMap) { + compileFlags = + "flag_group {" + + " flag: '-fprofile-instr-generate'" + + " flag: '-fcoverage-mapping'" + + "}"; + linkerFlags = + " flag_group {" + + " flag: '-fprofile-instr-generate'" + + "}"; + } else { + compileFlags = + " expand_if_all_available: 'gcov_gcno_file'" + + "flag_group {" + + " flag: '-fprofile-arcs'" + + " flag: '-ftest-coverage'" + + "}"; + linkerFlags = + " flag_group {" + + " flag: '-lgcov'" + + "}"; + } TextFormat.merge( "" + "feature {" @@ -959,19 +985,13 @@ public class CppConfiguration extends BuildConfiguration.Fragment { + " action: 'c++-header-parsing'" + " action: 'c++-header-preprocessing'" + " action: 'c++-module-compile'" - + " expand_if_all_available: 'gcov_gcno_file'" - + " flag_group {" - + " flag: '-fprofile-arcs'" - + " flag: '-ftest-coverage'" - + " }" + + compileFlags + " }" + " flag_set {" + " action: 'c++-link-interface-dynamic-library'" + " action: 'c++-link-dynamic-library'" + " action: 'c++-link-executable'" - + " flag_group {" - + " flag: '-lgcov'" - + " }" + + linkerFlags + " }" + "}", toolchainBuilder); diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/CompilationSupport.java b/src/main/java/com/google/devtools/build/lib/rules/objc/CompilationSupport.java index 4da2ff3eab..ba5adf1c5b 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/objc/CompilationSupport.java +++ b/src/main/java/com/google/devtools/build/lib/rules/objc/CompilationSupport.java @@ -123,11 +123,19 @@ public final class CompilationSupport { static final ImmutableList<String> LINKER_COVERAGE_FLAGS = ImmutableList.of("-ftest-coverage", "-fprofile-arcs"); + @VisibleForTesting + static final ImmutableList<String> LINKER_LLVM_COVERAGE_FLAGS = + ImmutableList.of("-fprofile-instr-generate"); + // Flags for clang 6.1(xcode 6.4) @VisibleForTesting - static final ImmutableList<String> CLANG_COVERAGE_FLAGS = + static final ImmutableList<String> CLANG_GCOV_COVERAGE_FLAGS = ImmutableList.of("-fprofile-arcs", "-ftest-coverage"); + @VisibleForTesting + static final ImmutableList<String> CLANG_LLVM_COVERAGE_FLAGS = + ImmutableList.of("-fprofile-instr-generate", "-fcoverage-mapping"); + // These are added by Xcode when building, because the simulator is built on OSX // frameworks so we aim compile to match the OSX objc runtime. @VisibleForTesting @@ -548,7 +556,11 @@ public final class CompilationSupport { List<String> coverageFlags = ImmutableList.of(); if (collectCodeCoverage) { - coverageFlags = CLANG_COVERAGE_FLAGS; + if (buildConfiguration.isLLVMCoverageMapFormatEnabled()) { + coverageFlags = CLANG_LLVM_COVERAGE_FLAGS; + } else { + coverageFlags = CLANG_GCOV_COVERAGE_FLAGS; + } } commandLine @@ -658,7 +670,7 @@ public final class CompilationSupport { hasSwiftSources); Optional<Artifact> gcnoFile = Optional.absent(); - if (runCodeCoverage) { + if (runCodeCoverage && !buildConfiguration.isLLVMCoverageMapFormatEnabled()) { gcnoFile = Optional.of(intermediateArtifacts.gcnoFile(sourceFile)); } @@ -1388,7 +1400,11 @@ public final class CompilationSupport { .add(objcProvider.get(ObjcProvider.LINKOPT)); if (buildConfiguration.isCodeCoverageEnabled()) { - commandLine.add(LINKER_COVERAGE_FLAGS); + if (buildConfiguration.isLLVMCoverageMapFormatEnabled()) { + commandLine.add(LINKER_LLVM_COVERAGE_FLAGS); + } else { + commandLine.add(LINKER_COVERAGE_FLAGS); + } } if (objcProvider.is(USES_SWIFT)) { |