@@ -3,11 +3,16 @@ import app.cash.licensee.UnusedAction
3
3
import com.gradleup.librarian.gradle.Librarian
4
4
import nmcp.NmcpAggregationExtension
5
5
import org.gradle.api.Project
6
- import org.gradle.api.Task
7
- import org.gradle.api.tasks.TaskProvider
8
6
import org.gradle.jvm.tasks.Jar
7
+ import org.jetbrains.kotlin.gradle.dsl.KotlinJvmExtension
9
8
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
10
9
import org.jetbrains.kotlin.gradle.dsl.KotlinVersion
10
+ import org.jetbrains.kotlin.gradle.plugin.ExecutionTaskHolder
11
+ import org.jetbrains.kotlin.gradle.plugin.KotlinTarget
12
+ import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTargetWithSimulatorTests
13
+ import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTargetWithTests
14
+ import org.jetbrains.kotlin.gradle.plugin.mpp.NativeOutputKind
15
+ import org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsIrTarget
11
16
import kotlin.time.Duration.Companion.hours
12
17
import kotlin.time.Duration.Companion.minutes
13
18
import kotlin.time.toJavaDuration
@@ -31,6 +36,8 @@ fun Project.apolloLibrary(
31
36
androidOptions : AndroidOptions ? = null,
32
37
publish : Boolean = true,
33
38
kotlinCompilerOptions : KotlinCompilerOptions = KotlinCompilerOptions (),
39
+ contributesCtng : Boolean = true,
40
+ enableWasmJsTests : Boolean = true
34
41
) {
35
42
group = property(" GROUP" )!!
36
43
version = version()
@@ -73,6 +80,61 @@ fun Project.apolloLibrary(
73
80
}
74
81
75
82
configureTesting()
83
+ project.kotlinTargets.forEach { target ->
84
+ /* *
85
+ * Disable every native test except the KotlinNativeTargetWithHostTests to save some time
86
+ */
87
+ if (target is KotlinNativeTargetWithSimulatorTests || target is KotlinNativeTargetWithTests <* >) {
88
+ target.testRuns.configureEach {
89
+ this as ExecutionTaskHolder <* >
90
+ executionTask.configure {
91
+ enabled = false
92
+ }
93
+ }
94
+ target.binaries.configureEach {
95
+ if (outputKind == NativeOutputKind .TEST ) {
96
+ linkTaskProvider.configure {
97
+ enabled = false
98
+ }
99
+ compilation.compileTaskProvider.configure {
100
+ enabled = false
101
+ }
102
+ }
103
+ }
104
+ }
105
+ /* *
106
+ * Disable wasmJs tests because they are not ready yet
107
+ */
108
+ if (! enableWasmJsTests && target is KotlinJsIrTarget && target.wasmTargetType != null ) {
109
+ target.subTargets.configureEach {
110
+ testRuns.configureEach {
111
+ executionTask.configure {
112
+ enabled = false
113
+ }
114
+ }
115
+ }
116
+ target.testRuns.configureEach {
117
+ executionTask.configure {
118
+ enabled = false
119
+ }
120
+ }
121
+ target.binaries.configureEach {
122
+ compilation.compileTaskProvider.configure {
123
+ enabled = false
124
+ }
125
+ }
126
+ }
127
+ }
128
+ /* *
129
+ * `ctng` is short for CiTestNoGradle. It's a shorthand task that runs all the `build`
130
+ * tasks except the Gradle plugin one because it is slow.
131
+ * the name is for historical reasons.
132
+ */
133
+ tasks.register(" ctng" ) {
134
+ if (contributesCtng) {
135
+ dependsOn(" build" )
136
+ }
137
+ }
76
138
77
139
tasks.withType(Jar ::class .java).configureEach {
78
140
manifest {
@@ -98,6 +160,15 @@ fun Project.apolloLibrary(
98
160
}
99
161
}
100
162
163
+ private val Project .kotlinTargets: Collection <KotlinTarget >
164
+ get() {
165
+ when (val kotlin = extensions.getByName(" kotlin" )) {
166
+ is KotlinJvmExtension -> return listOf (kotlin.target)
167
+ is KotlinMultiplatformExtension -> return kotlin.targets
168
+ else -> return emptyList()
169
+ }
170
+ }
171
+
101
172
fun Project.apolloLibrary (
102
173
namespace : String ,
103
174
jvmTarget : Int? = null,
@@ -109,6 +180,8 @@ fun Project.apolloLibrary(
109
180
androidOptions : AndroidOptions ? = null,
110
181
publish : Boolean = true,
111
182
kotlinCompilerOptions : KotlinCompilerOptions = KotlinCompilerOptions (),
183
+ contributesCtng : Boolean = true,
184
+ enableWasmJsTests : Boolean = true,
112
185
) {
113
186
val defaultTargets = defaultTargets(
114
187
withJvm = withJvm,
@@ -120,12 +193,14 @@ fun Project.apolloLibrary(
120
193
)
121
194
122
195
apolloLibrary(
123
- namespace,
124
- jvmTarget,
125
- defaultTargets,
126
- androidOptions,
127
- publish,
128
- kotlinCompilerOptions
196
+ namespace = namespace,
197
+ jvmTarget = jvmTarget,
198
+ defaultTargets = defaultTargets,
199
+ androidOptions = androidOptions,
200
+ publish = publish,
201
+ kotlinCompilerOptions = kotlinCompilerOptions,
202
+ contributesCtng = contributesCtng,
203
+ enableWasmJsTests = enableWasmJsTests
129
204
)
130
205
}
131
206
@@ -134,7 +209,7 @@ fun Project.apolloTest(
134
209
withJvm : Boolean = true,
135
210
appleTargets : Set <String > = setOf(hostTarget),
136
211
kotlinCompilerOptions : KotlinCompilerOptions = KotlinCompilerOptions (),
137
- jvmTarget : Int? = null
212
+ jvmTarget : Int? = null,
138
213
) {
139
214
apolloTest(
140
215
kotlinCompilerOptions = kotlinCompilerOptions,
0 commit comments