File tree Expand file tree Collapse file tree 3 files changed +26
-1
lines changed
src/main/java/com/google/devtools/build/lib/analysis Expand file tree Collapse file tree 3 files changed +26
-1
lines changed Original file line number Diff line number Diff line change @@ -565,6 +565,13 @@ public boolean shouldInstrumentTestTargets() {
565
565
return options .instrumentTestTargets ;
566
566
}
567
567
568
+ /**
569
+ * Returns a boolean of whether to collect code coverage for generated files or not.
570
+ */
571
+ public boolean shouldCollectCodeCoverageForGeneratedFiles () {
572
+ return options .collectCodeCoverageForGeneratedFiles ;
573
+ }
574
+
568
575
/**
569
576
* Returns a new, unordered mapping of names to values of "Make" variables defined by this
570
577
* configuration.
Original file line number Diff line number Diff line change @@ -440,6 +440,14 @@ public ExecConfigurationDistinguisherSchemeConverter() {
440
440
+ " not be specified directly - 'bazel coverage' command should be used instead." )
441
441
public boolean collectCodeCoverage ;
442
442
443
+ @ Option (
444
+ name = "experimental_collect_code_coverage_for_generated_files" ,
445
+ defaultValue = "false" ,
446
+ documentationCategory = OptionDocumentationCategory .OUTPUT_PARAMETERS ,
447
+ effectTags = {OptionEffectTag .AFFECTS_OUTPUTS },
448
+ help = "If specified, Bazel will also generate collect coverage information for generated files." )
449
+ public boolean collectCodeCoverageForGeneratedFiles ;
450
+
443
451
@ Option (
444
452
name = "build_runfile_manifests" ,
445
453
defaultValue = "true" ,
Original file line number Diff line number Diff line change @@ -208,7 +208,8 @@ public static InstrumentedFilesInfo collect(
208
208
for (TransitiveInfoCollection dep :
209
209
getPrerequisitesForAttributes (ruleContext , spec .sourceAttributes )) {
210
210
for (Artifact artifact : dep .getProvider (FileProvider .class ).getFilesToBuild ().toList ()) {
211
- if (spec .instrumentedFileTypes .matches (artifact .getFilename ())) {
211
+ if (shouldIncludeArtifact (ruleContext .getConfiguration (), artifact ) &&
212
+ spec .instrumentedFileTypes .matches (artifact .getFilename ())) {
212
213
localSourcesBuilder .add (artifact );
213
214
}
214
215
}
@@ -256,6 +257,15 @@ public static boolean shouldIncludeLocalSources(
256
257
&& config .getInstrumentationFilter ().isIncluded (label .toString ()));
257
258
}
258
259
260
+ /**
261
+ * Return whether the artifact should be collected based on the origin of the artifact
262
+ * and the --experimental_collect_code_coverage_for_generated_files config setting.
263
+ */
264
+ public static boolean shouldIncludeArtifact (
265
+ BuildConfigurationValue config , Artifact artifact ) {
266
+ return artifact .isSourceArtifact () || config .shouldCollectCodeCoverageForGeneratedFiles ();
267
+ }
268
+
259
269
/**
260
270
* The set of file types and attributes to visit to collect instrumented files for a certain rule
261
271
* 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