Skip to content

Commit

Permalink
fix: Fix more canonical names
Browse files Browse the repository at this point in the history
  • Loading branch information
honnix committed Oct 1, 2024
1 parent 8d85ffd commit 87596b5
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 10 deletions.
7 changes: 3 additions & 4 deletions cli/src/main/kotlin/com/bazel_diff/bazel/BazelClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>) : KoinComponent {
private val logger: Logger by inject()
Expand All @@ -31,7 +30,7 @@ class BazelClient(private val useCquery: Boolean, private val fineGrainedHashExt
queryService.query(repoTargetsQuery.joinToString(" + ") { "'$it'" }))
.distinctBy { it.rule.name }
} else {
val buildTargetsQuery = listOf("//...:all-targets") + fineGrainedHashExternalRepos.map { "@$it//...:all-targets" }
val buildTargetsQuery = listOf("//...:all-targets") + fineGrainedHashExternalRepos.map { "@@$it//...:all-targets" }
queryService.query((repoTargetsQuery + buildTargetsQuery).joinToString(" + ") { "'$it'" })
}
val queryDuration = Calendar.getInstance().getTimeInMillis() - queryEpoch
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ 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 {
it.target.rule.name in compatibleTargetSet ||
it.target.rule.name.startsWith("@") && "@${it.target.rule.name}" in compatibleTargetSet
}.map { it.target }
} else {
mutableListOf<Build.Target>().apply {
while (true) {
Expand Down
4 changes: 2 additions & 2 deletions cli/src/main/kotlin/com/bazel_diff/bazel/BazelRule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ class BazelRule(private val rule: Build.Rule) {
val name: String = rule.name

private fun transformRuleInput(fineGrainedHashExternalRepos: Set<String>, 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)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class ExternalRepoResolver(
val queryResultLine = runProcessAndCaptureFirstLine(
bazelPath.toString(),
"query",
"@$repoName//...",
"@@$repoName//...",
"--keep_going",
"--output",
"location"
Expand Down Expand Up @@ -67,4 +67,4 @@ class ExternalRepoResolver(
return it.readLine()
}
}
}
}
6 changes: 5 additions & 1 deletion cli/src/main/kotlin/com/bazel_diff/hash/SourceFileHasher.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 87596b5

Please sign in to comment.