|
67 | 67 | import java.io.FileOutputStream;
|
68 | 68 | import java.io.IOException;
|
69 | 69 | import java.io.OutputStream;
|
| 70 | +import java.io.PrintWriter; |
70 | 71 | import java.time.Duration;
|
71 | 72 | import java.util.ArrayList;
|
72 | 73 | import java.util.List;
|
@@ -371,6 +372,12 @@ private BlazeCommandResult execExclusively(
|
371 | 372 | message, FailureDetails.Command.Code.STARLARK_CPU_PROFILING_INITIALIZATION_FAILURE);
|
372 | 373 | }
|
373 | 374 | }
|
| 375 | + if (!commonOptions.starlarkCoverageReport.isEmpty()) { |
| 376 | + // Record coverage for all `.bzl` files, excluding the built-ins, which don't have paths that |
| 377 | + // could be resolved when a human-readable coverage report is generated. |
| 378 | + Starlark.startCoverageCollection( |
| 379 | + path -> !path.startsWith("/virtual_builtins_bzl") && path.endsWith(".bzl")); |
| 380 | + } |
374 | 381 |
|
375 | 382 | BlazeCommandResult result =
|
376 | 383 | createDetailedCommandResult(
|
@@ -603,6 +610,18 @@ private BlazeCommandResult execExclusively(
|
603 | 610 | }
|
604 | 611 | }
|
605 | 612 | }
|
| 613 | + if (!commonOptions.starlarkCoverageReport.isEmpty()) { |
| 614 | + FileOutputStream out; |
| 615 | + try { |
| 616 | + out = new FileOutputStream(commonOptions.starlarkCoverageReport); |
| 617 | + } catch (IOException ex) { |
| 618 | + String message = "Starlark coverage recorder: " + ex.getMessage(); |
| 619 | + outErr.printErrLn(message); |
| 620 | + return createDetailedCommandResult( |
| 621 | + message, FailureDetails.Command.Code.STARLARK_COVERAGE_REPORT_DUMP_FAILURE); |
| 622 | + } |
| 623 | + Starlark.dumpCoverage(new PrintWriter(out)); |
| 624 | + } |
606 | 625 |
|
607 | 626 | needToCallAfterCommand = false;
|
608 | 627 | return runtime.afterCommand(env, result);
|
|
0 commit comments