File tree 3 files changed +25
-2
lines changed
src/main/java/com/google/devtools/build/lib/analysis 3 files changed +25
-2
lines changed Original file line number Diff line number Diff line change @@ -536,6 +536,11 @@ public boolean shouldInstrumentTestTargets() {
536
536
return options .instrumentTestTargets ;
537
537
}
538
538
539
+ /** Returns a boolean of whether to collect code coverage for generated files or not. */
540
+ public boolean shouldCollectCodeCoverageForGeneratedFiles () {
541
+ return options .collectCodeCoverageForGeneratedFiles ;
542
+ }
543
+
539
544
/**
540
545
* Returns a new, unordered mapping of names to values of "Make" variables defined by this
541
546
* configuration.
Original file line number Diff line number Diff line change @@ -425,6 +425,16 @@ public ExecConfigurationDistinguisherSchemeConverter() {
425
425
+ " not be specified directly - 'bazel coverage' command should be used instead." )
426
426
public boolean collectCodeCoverage ;
427
427
428
+ @ Option (
429
+ name = "experimental_collect_code_coverage_for_generated_files" ,
430
+ defaultValue = "false" ,
431
+ documentationCategory = OptionDocumentationCategory .OUTPUT_PARAMETERS ,
432
+ effectTags = {OptionEffectTag .AFFECTS_OUTPUTS },
433
+ help =
434
+ "If specified, Bazel will also generate collect coverage information for generated"
435
+ + " files." )
436
+ public boolean collectCodeCoverageForGeneratedFiles ;
437
+
428
438
@ Option (
429
439
name = "build_runfile_manifests" ,
430
440
defaultValue = "true" ,
Original file line number Diff line number Diff line change @@ -213,8 +213,8 @@ public static InstrumentedFilesInfo collect(
213
213
for (TransitiveInfoCollection dep :
214
214
getPrerequisitesForAttributes (ruleContext , spec .sourceAttributes )) {
215
215
for (Artifact artifact : dep .getProvider (FileProvider .class ).getFilesToBuild ().toList ()) {
216
- if (artifact . isSourceArtifact () &&
217
- spec .instrumentedFileTypes .matches (artifact .getFilename ())) {
216
+ if (shouldIncludeArtifact ( ruleContext . getConfiguration (), artifact )
217
+ && spec .instrumentedFileTypes .matches (artifact .getFilename ())) {
218
218
localSourcesBuilder .add (artifact );
219
219
}
220
220
}
@@ -262,6 +262,14 @@ public static boolean shouldIncludeLocalSources(
262
262
&& config .getInstrumentationFilter ().isIncluded (label .toString ()));
263
263
}
264
264
265
+ /**
266
+ * Return whether the artifact should be collected based on the origin of the artifact and the
267
+ * --experimental_collect_code_coverage_for_generated_files config setting.
268
+ */
269
+ public static boolean shouldIncludeArtifact (BuildConfigurationValue config , Artifact artifact ) {
270
+ return artifact .isSourceArtifact () || config .shouldCollectCodeCoverageForGeneratedFiles ();
271
+ }
272
+
265
273
/**
266
274
* The set of file types and attributes to visit to collect instrumented files for a certain rule
267
275
* 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