File tree 5 files changed +20
-8
lines changed
cli/src/main/kotlin/com/bazel_diff
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
2
2
3
3
import com.bazel_diff.log.Logger
4
4
import 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
8
5
import org.koin.core.component.KoinComponent
6
+ import org.koin.core.component.inject
7
+ import java.util.Calendar
9
8
10
9
class BazelClient (private val useCquery : Boolean , private val fineGrainedHashExternalRepos : Set <String >) : KoinComponent {
11
10
private val logger: Logger by inject()
Original file line number Diff line number Diff line change @@ -45,7 +45,7 @@ class BazelQueryService(
45
45
val targets = outputFile.inputStream().buffered().use { proto ->
46
46
if (useCquery) {
47
47
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 }
49
49
} else {
50
50
mutableListOf<Build .Target >().apply {
51
51
while (true ) {
@@ -60,6 +60,15 @@ class BazelQueryService(
60
60
return targets
61
61
}
62
62
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
+
63
72
@OptIn(ExperimentalCoroutinesApi ::class )
64
73
private suspend fun runQuery (
65
74
query : String ,
Original file line number Diff line number Diff line change @@ -37,11 +37,11 @@ class BazelRule(private val rule: Build.Rule) {
37
37
val name: String = rule.name
38
38
39
39
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} " ) }) {
41
41
val splitRule = ruleInput.split(" //" .toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()
42
42
if (splitRule.size == 2 ) {
43
43
var externalRule = splitRule[0 ]
44
- externalRule = externalRule.replaceFirst(" @" .toRegex(), " " )
44
+ externalRule = externalRule.replaceFirst(" @+ " .toRegex(), " " )
45
45
return String .format(" //external:%s" , externalRule)
46
46
}
47
47
}
Original file line number Diff line number Diff line change @@ -67,4 +67,4 @@ class ExternalRepoResolver(
67
67
return it.readLine()
68
68
}
69
69
}
70
- }
70
+ }
Original file line number Diff line number Diff line change @@ -48,7 +48,11 @@ class SourceFileHasher : KoinComponent {
48
48
val filenameSubstring = name.substring(2 )
49
49
Paths .get(filenameSubstring.removePrefix(" :" ).replace(' :' , ' /' ))
50
50
} 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
+ }
52
56
if (parts.size != 2 ) {
53
57
logger.w { " Invalid source label $name " }
54
58
return @sha256
You can’t perform that action at this time.
0 commit comments