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() {
566
566
return options .instrumentTestTargets ;
567
567
}
568
568
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
+
569
574
/**
570
575
* Returns a new, unordered mapping of names to values of "Make" variables defined by this
571
576
* configuration.
Original file line number Diff line number Diff line change @@ -434,6 +434,16 @@ public ExecConfigurationDistinguisherSchemeConverter() {
434
434
+ " not be specified directly - 'bazel coverage' command should be used instead." )
435
435
public boolean collectCodeCoverage ;
436
436
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
+
437
447
@ Option (
438
448
name = "build_runfile_manifests" ,
439
449
defaultValue = "true" ,
Original file line number Diff line number Diff line change @@ -208,8 +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 (artifact . isSourceArtifact () &&
212
- spec .instrumentedFileTypes .matches (artifact .getFilename ())) {
211
+ if (shouldIncludeArtifact ( ruleContext . getConfiguration (), artifact )
212
+ && spec .instrumentedFileTypes .matches (artifact .getFilename ())) {
213
213
localSourcesBuilder .add (artifact );
214
214
}
215
215
}
@@ -257,6 +257,14 @@ public static boolean shouldIncludeLocalSources(
257
257
&& config .getInstrumentationFilter ().isIncluded (label .toString ()));
258
258
}
259
259
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
+
260
268
/**
261
269
* The set of file types and attributes to visit to collect instrumented files for a certain rule
262
270
* 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