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 818372d7ddb..0bb44640bcd 100644 --- a/scripts/src/java/org/oppia/android/scripts/common/BazelClient.kt +++ b/scripts/src/java/org/oppia/android/scripts/common/BazelClient.kt @@ -144,14 +144,27 @@ class BazelClient(private val rootDirectory: File, private val commandExecutor: fun runCoverageForTestTarget(bazelTestTarget: String): List? { val instrumentation = bazelTestTarget.split(":")[0] val computeInstrumentation = instrumentation.split("/").let { "//${it[2]}/..." } -// val coverageCommandOutputLines = executeBazelCommand( - executeBazelCommand( + /*val coverageCommandOutputLines = executeBazelCommand( +// executeBazelCommand( "test", "--collect_code_coverage", "--combined_report=lcov", bazelTestTarget, "--instrumentation_filter=$computeInstrumentation" + )*/ + + val targetParts = bazelTestTarget.split(":") + val targetPath = "${targetParts[0]}:*" + val targetName = targetParts[1] + + val buildRule = executeBazelCommand( + "query", + "attr(name, $targetName, $targetPath)", + "--output=build", ) + println("BUILD: $buildRule") + println("BUILD has shard count: ${buildRule.any { "shard_count" in it }}") + println("Printing for the bazel test target: $bazelTestTarget") // println(File(rootDirectory,"/bazel-out/_coverage/_coverage_report.dat").exists()) // println(File(rootDirectory,"/bazel-out/_coverage/_coverage_report.dat").readText()) @@ -159,7 +172,30 @@ class BazelClient(private val rootDirectory: File, private val commandExecutor: File(path).readLines() }*/ - return File(rootDirectory,"/bazel-out/_coverage/_coverage_report.dat").readLines() + val hasShardCount = buildRule.any { "shard_count" in it } + if (hasShardCount) { + println("In has Shard count") +// val coverageCommandOutputLines = executeBazelCommand( + executeBazelCommand( + "test", + "--collect_code_coverage", + "--combined_report=lcov", + bazelTestTarget, + "--instrumentation_filter=$computeInstrumentation" + ) + return File(rootDirectory, "/bazel-out/_coverage/_coverage_report.dat").readLines() + } else { + println("In does not have Shard count") + val coverageCommandOutputLines = executeBazelCommand( +// executeBazelCommand( + "coverage", + bazelTestTarget, + "--instrumentation_filter=$computeInstrumentation" + ) + return parseCoverageDataFilePath(coverageCommandOutputLines)?.let { path -> + File(path).readLines() + } + } } private fun parseCoverageDataFilePath(coverageCommandOutputLines: List): String? {