Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Fix more canonical names #231

Merged
merged 1 commit into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 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 Down
11 changes: 10 additions & 1 deletion cli/src/main/kotlin/com/bazel_diff/bazel/BazelQueryService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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<Build.Target>().apply {
while (true) {
Expand All @@ -60,6 +60,15 @@ class BazelQueryService(
return targets
}

private fun inCompatibleTargetSet(
target: AnalysisProtosV2.ConfiguredTarget,
compatibleTargetSet: Set<String>
): 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,
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 @@ -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
Loading