Repository navigation
Expand file tree
/
Copy pathbuild.gradle.kts
More file actions
280 lines (237 loc) · 8.88 KB
/
Copy pathbuild.gradle.kts
File metadata and controls
280 lines (237 loc) · 8.88 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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.async
import kotlinx.coroutines.awaitAll
import kotlinx.coroutines.runBlocking
import java.io.FileNotFoundException
plugins {
alias(libs.plugins.android.application) apply false
alias(libs.plugins.jetbrains.kotlin.android) apply false
alias(libs.plugins.jetbrains.kotlin.jvm) apply false
alias(libs.plugins.compose.compiler) apply false
alias(libs.plugins.ktlint)
alias(benchmarkLibs.plugins.baselineprofile) apply false
id("dependency-verification")
}
buildscript {
repositories {
google()
mavenCentral()
maven {
url = uri("https://plugins.gradle.org/m2/")
content {
includeGroupByRegex("org\\.jlleitschuh\\.gradle.*")
}
}
}
dependencies {
classpath(libs.gradle)
classpath(libs.androidx.navigation.safe.args.gradle.plugin)
classpath(libs.protobuf.gradle.plugin)
classpath("com.squareup.wire:wire-gradle-plugin:6.4.5") {
exclude(group = "com.squareup.wire", module = "wire-swift-generator")
exclude(group = "com.squareup.wire", module = "wire-grpc-client")
exclude(group = "com.squareup.wire", module = "wire-grpc-jvm")
exclude(group = "com.squareup.wire", module = "wire-grpc-server-generator")
exclude(group = "io.outfoxx", module = "swiftpoet")
}
classpath(libs.androidx.benchmark.gradle.plugin)
classpath(files("$rootDir/wire-handler/wire-handler-1.0.0.jar"))
classpath(libs.com.google.devtools.ksp.gradle.plugin)
}
}
tasks.withType<Wrapper> {
distributionType = Wrapper.DistributionType.ALL
}
subprojects {
if (JavaVersion.current().isJava8Compatible) {
allprojects {
tasks.withType<Javadoc> {
(options as StandardJavadocDocletOptions).addStringOption("Xdoclint:none", "-quiet")
}
}
}
tasks.withType<Test>().configureEach {
if (name.contains("ScreenshotTest")) {
// Compose preview screenshot testing does not support parallel execution.
maxParallelForks = 1
// The plugin creates this task for every module, but most have no previews to validate.
failOnNoDiscoveredTests = false
} else {
maxParallelForks = (Runtime.getRuntime().availableProcessors() / 4).coerceAtLeast(1)
}
// Raised for robolectric
maxHeapSize = "2g"
}
// The reference images aren't tracked as outputs, so without this the task is skipped after they change on disk.
tasks.matching { it.name.startsWith("update") && it.name.endsWith("ScreenshotTest") }.configureEach {
outputs.upToDateWhen { false }
outputs.doNotCacheIf("Reference images are not tracked outputs") { true }
}
}
tasks.register("buildQa") {
group = "Verification"
description = "Quality Assurance for build logic."
dependsOn(
gradle.includedBuild("build-logic").task(":tools:test"),
gradle.includedBuild("build-logic").task(":tools:ktlintCheck"),
gradle.includedBuild("build-logic").task(":plugins:ktlintCheck")
)
}
tasks.register("qa") {
group = "Verification"
description = "Quality Assurance. Run before release."
dependsOn("clean")
}
tasks.register("ci") {
group = "Verification"
description = "Faster version of qa that's intended to be run on PRs. Uses a :fast-lint instead of full lint."
dependsOn("clean")
}
tasks.register("validateScreenshots") {
group = "Verification"
description = "Validates Compose screenshot tests. Intended to run only on CI, not local builds."
}
tasks.register("updateScreenshots") {
group = "Verification"
description = "Regenerates Compose screenshot reference images."
}
tasks.register("qaRemote") {
group = "Verification"
description = "Full qa plus screenshot validation. Intended to run on CI, not local builds."
dependsOn("qa")
dependsOn("validateScreenshots")
}
tasks.register("ciRemote") {
group = "Verification"
description = "Faster PR verification (ci) plus screenshot validation. Intended to run on CI, not local builds."
dependsOn("ci")
dependsOn("validateScreenshots")
}
// Wire up QA dependencies after all projects are evaluated
gradle.projectsEvaluated {
val appTestTask = tasks.findByPath(":Signal-Android:testPlayProdDebugUnitTest")!!
val appLintTask = tasks.findByPath(":Signal-Android:lintPlayProdDebug")!!
val appCompileInstrumentationTask = tasks.findByPath(":Signal-Android:compilePlayProdDebugAndroidTestSources")
tasks.named("qa") {
dependsOn("ktlintCheck")
dependsOn("buildQa")
dependsOn("checkStopship")
// Main app tasks
dependsOn(appTestTask)
dependsOn(appLintTask)
// Instrumentation
appCompileInstrumentationTask?.let { dependsOn(it) }
// All subproject ktlint checks
subprojects.forEach { subproject ->
subproject.tasks.findByName("ktlintCheck")?.let { dependsOn(it) }
}
// Library module tasks
subprojects.filter { it.name != "Signal-Android" }.forEach { subproject ->
val testTask = subproject.tasks.findByName("testDebugUnitTest") ?: subproject.tasks.findByName("test")
testTask?.let { dependsOn(it) }
subproject.tasks.findByName("lintDebug")?.let { dependsOn(it) }
}
}
// All modules get screenshotTests enabled by default, but the validate task fails if there's no tests.
// So we just filter out the modules that have no tests ourselves.
val screenshotTestTargets = subprojects
.filter { it.file("src/screenshotTest").isDirectory }
.map { it to if (it.name == "Signal-Android") "PlayProdDebug" else "Debug" }
tasks.named("validateScreenshots") {
screenshotTestTargets.forEach { (subproject, variant) ->
subproject.tasks.findByName("validate${variant}ScreenshotTest")?.let { dependsOn(it) }
}
}
tasks.named("updateScreenshots") {
screenshotTestTargets.forEach { (subproject, variant) ->
subproject.tasks.findByName("update${variant}ScreenshotTest")?.let { dependsOn(it) }
}
}
tasks.named("ci") {
dependsOn("ktlintCheck")
dependsOn("buildQa")
dependsOn("checkStopship")
dependsOn(appTestTask)
appCompileInstrumentationTask?.let { dependsOn(it) }
dependsOn(":fast-lint:fastLint")
subprojects.forEach { subproject ->
subproject.tasks.findByName("ktlintCheck")?.let { dependsOn(it) }
}
subprojects.filter { it.name != "Signal-Android" }.forEach { subproject ->
val testTask = subproject.tasks.findByName("testDebugUnitTest") ?: subproject.tasks.findByName("test")
testTask?.let { dependsOn(it) }
}
}
// Ensure clean runs before everything else
rootProject.allprojects.forEach { project ->
project.tasks.matching { it.name != "clean" }.configureEach {
mustRunAfter("clean")
}
}
// If you let all of these things run in parallel, gradle will likely OOM.
// To avoid this, we put non-app tests and lints behind the much heavier app tests and lints.
subprojects.filter { it.name != "Signal-Android" }.forEach { subproject ->
appTestTask.let { task ->
subproject.tasks.findByName("testDebugUnitTest")?.mustRunAfter(task)
subproject.tasks.findByName("test")?.mustRunAfter(task)
}
appLintTask.let { task ->
subproject.tasks.findByName("lintDebug")?.mustRunAfter(task)
}
}
}
tasks.register("clean", Delete::class) {
delete(rootProject.layout.buildDirectory)
}
tasks.register("format") {
group = "Formatting"
description = "Runs the ktlint formatter on all sources in this project and included builds"
dependsOn(
gradle.includedBuild("build-logic").task(":plugins:ktlintFormat"),
gradle.includedBuild("build-logic").task(":tools:ktlintFormat"),
*subprojects.mapNotNull { tasks.findByPath(":${it.path}:ktlintFormat") }.toTypedArray()
)
}
tasks.register("checkStopship") {
val cachedProjectDir = projectDir
doLast {
val excludedFiles = listOf(
"build.gradle.kts",
"lint.xml"
)
val excludedDirectories = listOf(
".idea"
)
val allowedExtensions = setOf("kt", "kts", "java", "xml")
val allFiles = cachedProjectDir.walkTopDown()
.onEnter { it.name != "build" || it.relativeTo(cachedProjectDir).path.contains("src") }
.asSequence()
.filter { it.isFile && it.extension in allowedExtensions }
.filterNot {
val path = it.relativeTo(cachedProjectDir).path
excludedFiles.contains(path) || excludedDirectories.any { d -> path.startsWith(d) }
}
.toList()
println("[STOPSHIP Check] There are ${allFiles.size} relevant files.")
val scope = CoroutineScope(Dispatchers.IO)
val stopshipFiles = mutableSetOf<String>()
runBlocking {
allFiles.map { file ->
scope.async {
try {
if (file.readText().contains("STOPSHIP")) {
stopshipFiles += file.relativeTo(cachedProjectDir).path
}
} catch (e: FileNotFoundException) {
// Ignore
}
}
}
.awaitAll()
}
if (stopshipFiles.isNotEmpty()) {
throw GradleException("STOPSHIP found! Files: $stopshipFiles")
}
}
}