File tree Expand file tree Collapse file tree 3 files changed +25
-2
lines changed
src/main/java/com/google/devtools/build/lib/analysis Expand file tree Collapse file tree 3 files changed +25
-2
lines changed Original file line number Diff line number Diff line change @@ -566,6 +566,11 @@ public boolean shouldInstrumentTestTargets() {
566566 return options .instrumentTestTargets ;
567567 }
568568
569+ /** Returns a boolean of whether to collect code coverage for generated files or not. */
570+ public boolean shouldCollectCodeCoverageForGeneratedFiles () {
571+ return options .collectCodeCoverageForGeneratedFiles ;
572+ }
573+
569574 /**
570575 * Returns a new, unordered mapping of names to values of "Make" variables defined by this
571576 * configuration.
Original file line number Diff line number Diff line change @@ -434,6 +434,16 @@ public ExecConfigurationDistinguisherSchemeConverter() {
434434 + " not be specified directly - 'bazel coverage' command should be used instead." )
435435 public boolean collectCodeCoverage ;
436436
437+ @ Option (
438+ name = "experimental_collect_code_coverage_for_generated_files" ,
439+ defaultValue = "false" ,
440+ documentationCategory = OptionDocumentationCategory .OUTPUT_PARAMETERS ,
441+ effectTags = {OptionEffectTag .AFFECTS_OUTPUTS },
442+ help =
443+ "If specified, Bazel will also generate collect coverage information for generated"
444+ + " files." )
445+ public boolean collectCodeCoverageForGeneratedFiles ;
446+
437447 @ Option (
438448 name = "build_runfile_manifests" ,
439449 defaultValue = "true" ,
Original file line number Diff line number Diff line change @@ -208,8 +208,8 @@ public static InstrumentedFilesInfo collect(
208208 for (TransitiveInfoCollection dep :
209209 getPrerequisitesForAttributes (ruleContext , spec .sourceAttributes )) {
210210 for (Artifact artifact : dep .getProvider (FileProvider .class ).getFilesToBuild ().toList ()) {
211- if (artifact . isSourceArtifact () &&
212- spec .instrumentedFileTypes .matches (artifact .getFilename ())) {
211+ if (shouldIncludeArtifact ( ruleContext . getConfiguration (), artifact )
212+ && spec .instrumentedFileTypes .matches (artifact .getFilename ())) {
213213 localSourcesBuilder .add (artifact );
214214 }
215215 }
@@ -257,6 +257,14 @@ public static boolean shouldIncludeLocalSources(
257257 && config .getInstrumentationFilter ().isIncluded (label .toString ()));
258258 }
259259
260+ /**
261+ * Return whether the artifact should be collected based on the origin of the artifact and the
262+ * --experimental_collect_code_coverage_for_generated_files config setting.
263+ */
264+ public static boolean shouldIncludeArtifact (BuildConfigurationValue config , Artifact artifact ) {
265+ return artifact .isSourceArtifact () || config .shouldCollectCodeCoverageForGeneratedFiles ();
266+ }
267+
260268 /**
261269 * The set of file types and attributes to visit to collect instrumented files for a certain rule
262270 * type. The class is intentionally immutable, so that a single instance is sufficient for all
You can’t perform that action at this time.
0 commit comments