File tree Expand file tree Collapse file tree 5 files changed +20
-8
lines changed
cli/src/main/kotlin/com/bazel_diff Expand file tree Collapse file tree 5 files changed +20
-8
lines changed Original file line number Diff line number Diff line change @@ -2,10 +2,9 @@ package com.bazel_diff.bazel
22
33import com.bazel_diff.log.Logger
44import com.google.devtools.build.lib.query2.proto.proto2api.Build
5- import java.nio.file.Path
6- import java.util.*
7- import org.koin.core.component.inject
85import org.koin.core.component.KoinComponent
6+ import org.koin.core.component.inject
7+ import java.util.Calendar
98
109class BazelClient (private val useCquery : Boolean , private val fineGrainedHashExternalRepos : Set <String >) : KoinComponent {
1110 private val logger: Logger by inject()
Original file line number Diff line number Diff line change @@ -45,7 +45,7 @@ class BazelQueryService(
4545 val targets = outputFile.inputStream().buffered().use { proto ->
4646 if (useCquery) {
4747 val cqueryResult = AnalysisProtosV2 .CqueryResult .parseFrom(proto)
48- cqueryResult.resultsList.filter { it.target.rule.name in compatibleTargetSet }.map { it.target }
48+ cqueryResult.resultsList.filter { inCompatibleTargetSet(it, compatibleTargetSet) }.map { it.target }
4949 } else {
5050 mutableListOf<Build .Target >().apply {
5151 while (true ) {
@@ -60,6 +60,15 @@ class BazelQueryService(
6060 return targets
6161 }
6262
63+ private fun inCompatibleTargetSet (
64+ target : AnalysisProtosV2 .ConfiguredTarget ,
65+ compatibleTargetSet : Set <String >
66+ ): Boolean {
67+ val name = target.target.rule.name
68+ return name in compatibleTargetSet ||
69+ name.startsWith(" @" ) && ! name.startsWith(" @@" ) && " @${name} " in compatibleTargetSet
70+ }
71+
6372 @OptIn(ExperimentalCoroutinesApi ::class )
6473 private suspend fun runQuery (
6574 query : String ,
Original file line number Diff line number Diff line change @@ -37,11 +37,11 @@ class BazelRule(private val rule: Build.Rule) {
3737 val name: String = rule.name
3838
3939 private fun transformRuleInput (fineGrainedHashExternalRepos : Set <String >, ruleInput : String ): String {
40- if (ruleInput.startsWith(" @" ) && fineGrainedHashExternalRepos.none { ruleInput.startsWith(" @$it " ) }) {
40+ if (ruleInput.startsWith(" @" ) && fineGrainedHashExternalRepos.none { ruleInput.startsWith(" @$it " ) || ruleInput.startsWith( " @@ ${it} " ) }) {
4141 val splitRule = ruleInput.split(" //" .toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()
4242 if (splitRule.size == 2 ) {
4343 var externalRule = splitRule[0 ]
44- externalRule = externalRule.replaceFirst(" @" .toRegex(), " " )
44+ externalRule = externalRule.replaceFirst(" @+ " .toRegex(), " " )
4545 return String .format(" //external:%s" , externalRule)
4646 }
4747 }
Original file line number Diff line number Diff line change @@ -67,4 +67,4 @@ class ExternalRepoResolver(
6767 return it.readLine()
6868 }
6969 }
70- }
70+ }
Original file line number Diff line number Diff line change @@ -48,7 +48,11 @@ class SourceFileHasher : KoinComponent {
4848 val filenameSubstring = name.substring(2 )
4949 Paths .get(filenameSubstring.removePrefix(" :" ).replace(' :' , ' /' ))
5050 } else if (name.startsWith(" @" )) {
51- val parts = name.substring(1 ).split(" //" )
51+ val parts = if (name.startsWith(" @@" )) {
52+ name.substring(2 ).split(" //" )
53+ } else {
54+ name.substring(1 ).split(" //" )
55+ }
5256 if (parts.size != 2 ) {
5357 logger.w { " Invalid source label $name " }
5458 return @sha256
You can’t perform that action at this time.
0 commit comments