From b266e489b1b2651e9139c45c8545c3bbdae385ac Mon Sep 17 00:00:00 2001 From: Rd Date: Mon, 22 Jul 2024 13:18:25 +0530 Subject: [PATCH] Temporary reference point for handling multiple shard coverage data This will be later removed. Using lcov's merge mechanism combines every data even that are not relavant to the source file making it un reliable, another option would be to manually merge them which would again turn complicated when dealing with branch and function data on scale --- .../android/scripts/common/BazelClient.kt | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/scripts/src/java/org/oppia/android/scripts/common/BazelClient.kt b/scripts/src/java/org/oppia/android/scripts/common/BazelClient.kt index 8e276a84d54..e4f97d472b3 100644 --- a/scripts/src/java/org/oppia/android/scripts/common/BazelClient.kt +++ b/scripts/src/java/org/oppia/android/scripts/common/BazelClient.kt @@ -187,6 +187,31 @@ class BazelClient(private val rootDirectory: File, private val commandExecutor: "Coverage command output lines " + "with bazel tests --collect coverage: $coverageCommandOutputLines" ) + + val regex = """(.*/shard_\d+_of_\d+/coverage\.dat)""".toRegex() + val shardCoveragePaths = coverageCommandOutputLines + .flatMap { regex.findAll(it).map { matchResult -> + matchResult.value.trim() + } + } + + println("Shard coverage path: $shardCoveragePaths") + + val lcovCommand = buildString { + append("lcov ") + shardCoveragePaths.forEach { path -> + append("--add-tracefile $path ") + } + append("--output-file ${rootDirectory}/coverage_reports/lcov_combined.dat") + } + + val process = ProcessBuilder(*lcovCommand.split(" ").toTypedArray()) + .redirectErrorStream(true) + .start() + + val output = process.inputStream.bufferedReader().readText() + println("Output: $output") + return File(rootDirectory, "/bazel-out/_coverage/_coverage_report.dat").readLines() } else { println("In does not have Shard count")