diff --git a/cli/src/main/kotlin/com/bazel_diff/bazel/BazelClient.kt b/cli/src/main/kotlin/com/bazel_diff/bazel/BazelClient.kt index d3d9132..5f65c69 100644 --- a/cli/src/main/kotlin/com/bazel_diff/bazel/BazelClient.kt +++ b/cli/src/main/kotlin/com/bazel_diff/bazel/BazelClient.kt @@ -2,10 +2,9 @@ package com.bazel_diff.bazel import com.bazel_diff.log.Logger import com.google.devtools.build.lib.query2.proto.proto2api.Build -import java.nio.file.Path -import java.util.* -import org.koin.core.component.inject import org.koin.core.component.KoinComponent +import org.koin.core.component.inject +import java.util.Calendar class BazelClient(private val useCquery: Boolean, private val fineGrainedHashExternalRepos: Set) : KoinComponent { private val logger: Logger by inject() diff --git a/cli/src/main/kotlin/com/bazel_diff/bazel/BazelQueryService.kt b/cli/src/main/kotlin/com/bazel_diff/bazel/BazelQueryService.kt index a66cd3f..f240136 100644 --- a/cli/src/main/kotlin/com/bazel_diff/bazel/BazelQueryService.kt +++ b/cli/src/main/kotlin/com/bazel_diff/bazel/BazelQueryService.kt @@ -45,7 +45,7 @@ class BazelQueryService( val targets = outputFile.inputStream().buffered().use { proto -> if (useCquery) { val cqueryResult = AnalysisProtosV2.CqueryResult.parseFrom(proto) - cqueryResult.resultsList.filter { it.target.rule.name in compatibleTargetSet }.map { it.target } + cqueryResult.resultsList.filter { inCompatibleTargetSet(it, compatibleTargetSet) }.map { it.target } } else { mutableListOf().apply { while (true) { @@ -60,6 +60,15 @@ class BazelQueryService( return targets } + private fun inCompatibleTargetSet( + target: AnalysisProtosV2.ConfiguredTarget, + compatibleTargetSet: Set + ): Boolean { + val name = target.target.rule.name + return name in compatibleTargetSet || + name.startsWith("@") && !name.startsWith("@@") && "@${name}" in compatibleTargetSet + } + @OptIn(ExperimentalCoroutinesApi::class) private suspend fun runQuery( query: String, diff --git a/cli/src/main/kotlin/com/bazel_diff/bazel/BazelRule.kt b/cli/src/main/kotlin/com/bazel_diff/bazel/BazelRule.kt index 6e0769e..3ef015a 100644 --- a/cli/src/main/kotlin/com/bazel_diff/bazel/BazelRule.kt +++ b/cli/src/main/kotlin/com/bazel_diff/bazel/BazelRule.kt @@ -37,11 +37,11 @@ class BazelRule(private val rule: Build.Rule) { val name: String = rule.name private fun transformRuleInput(fineGrainedHashExternalRepos: Set, ruleInput: String): String { - if (ruleInput.startsWith("@") && fineGrainedHashExternalRepos.none { ruleInput.startsWith("@$it") }) { + if (ruleInput.startsWith("@") && fineGrainedHashExternalRepos.none { ruleInput.startsWith("@$it") || ruleInput.startsWith("@@${it}") }) { val splitRule = ruleInput.split("//".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray() if (splitRule.size == 2) { var externalRule = splitRule[0] - externalRule = externalRule.replaceFirst("@".toRegex(), "") + externalRule = externalRule.replaceFirst("@+".toRegex(), "") return String.format("//external:%s", externalRule) } } diff --git a/cli/src/main/kotlin/com/bazel_diff/hash/ExternalRepoResolver.kt b/cli/src/main/kotlin/com/bazel_diff/hash/ExternalRepoResolver.kt index f500372..9107754 100644 --- a/cli/src/main/kotlin/com/bazel_diff/hash/ExternalRepoResolver.kt +++ b/cli/src/main/kotlin/com/bazel_diff/hash/ExternalRepoResolver.kt @@ -67,4 +67,4 @@ class ExternalRepoResolver( return it.readLine() } } -} \ No newline at end of file +} diff --git a/cli/src/main/kotlin/com/bazel_diff/hash/SourceFileHasher.kt b/cli/src/main/kotlin/com/bazel_diff/hash/SourceFileHasher.kt index b53af85..e988af7 100644 --- a/cli/src/main/kotlin/com/bazel_diff/hash/SourceFileHasher.kt +++ b/cli/src/main/kotlin/com/bazel_diff/hash/SourceFileHasher.kt @@ -48,7 +48,11 @@ class SourceFileHasher : KoinComponent { val filenameSubstring = name.substring(2) Paths.get(filenameSubstring.removePrefix(":").replace(':', '/')) } else if (name.startsWith("@")) { - val parts = name.substring(1).split("//") + val parts = if (name.startsWith("@@")) { + name.substring(2).split("//") + } else { + name.substring(1).split("//") + } if (parts.size != 2) { logger.w { "Invalid source label $name" } return@sha256