forked from Tinder/bazel-diff
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathModules.kt
More file actions
89 lines (84 loc) · 3 KB
/
Modules.kt
File metadata and controls
89 lines (84 loc) · 3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package com.bazel_diff.di
import com.bazel_diff.bazel.BazelClient
import com.bazel_diff.bazel.BazelQueryService
import com.bazel_diff.hash.*
import com.bazel_diff.io.ContentHashProvider
import com.bazel_diff.log.Logger
import com.bazel_diff.log.StderrLogger
import com.bazel_diff.process.Redirect
import com.bazel_diff.process.process
import com.google.gson.GsonBuilder
import java.io.File
import java.nio.file.Path
import java.nio.file.Paths
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.runBlocking
import org.koin.core.module.Module
import org.koin.core.qualifier.named
import org.koin.dsl.module
@OptIn(ExperimentalCoroutinesApi::class)
fun hasherModule(
workingDirectory: Path,
bazelPath: Path,
contentHashPath: File?,
startupOptions: List<String>,
commandOptions: List<String>,
cqueryOptions: List<String>,
useCquery: Boolean,
keepGoing: Boolean,
trackDeps: Boolean,
fineGrainedHashExternalRepos: Set<String>,
fineGrainedHashExternalReposFile: File?,
excludeExternalTargets: Boolean,
): Module = module {
if (fineGrainedHashExternalReposFile != null && fineGrainedHashExternalRepos.isNotEmpty()) {
System.err.println("Error: fineGrainedHashExternalReposFile and fineGrainedHashExternalRepos are mutually exclusive - please provide only one of them")
System.exit(1)
}
val updatedFineGrainedHashExternalRepos = fineGrainedHashExternalReposFile?.let { file ->
file.readLines()
.filter { it.isNotBlank() }
.toSet()
} ?: fineGrainedHashExternalRepos
val cmd: MutableList<String> =
ArrayList<String>().apply {
add(bazelPath.toString())
addAll(startupOptions)
add("info")
add("output_base")
}
val result = runBlocking {
process(
*cmd.toTypedArray(),
stdout = Redirect.CAPTURE,
workingDirectory = workingDirectory.toFile(),
stderr = Redirect.PRINT,
destroyForcibly = true,
)
}
val outputPath = Paths.get(result.output.single())
val debug = System.getProperty("DEBUG", "false").equals("true")
single {
BazelQueryService(
workingDirectory,
bazelPath,
startupOptions,
commandOptions,
cqueryOptions,
keepGoing,
debug)
}
single { BazelClient(useCquery, updatedFineGrainedHashExternalRepos, excludeExternalTargets) }
single { BuildGraphHasher(get()) }
single { TargetHasher() }
single { RuleHasher(useCquery, trackDeps, updatedFineGrainedHashExternalRepos) }
single<SourceFileHasher> { SourceFileHasherImpl(updatedFineGrainedHashExternalRepos) }
single { ExternalRepoResolver(workingDirectory, bazelPath, outputPath) }
single(named("working-directory")) { workingDirectory }
single(named("output-base")) { outputPath }
single { ContentHashProvider(contentHashPath) }
}
fun loggingModule(verbose: Boolean) = module { single<Logger> { StderrLogger(verbose) } }
fun serialisationModule() = module {
single { GsonBuilder().disableHtmlEscaping().setPrettyPrinting().create() }
}