16
16
17
17
package androidx.build
18
18
19
- import java.io.ByteArrayOutputStream
20
19
import javax.inject.Inject
21
20
import org.gradle.api.Project
22
- import org.gradle.api.attributes.Attribute
23
21
import org.gradle.api.tasks.Copy
24
- import org.gradle.api.tasks.Exec
25
- import org.gradle.kotlin.dsl.creating
26
22
import org.gradle.kotlin.dsl.dependencies
27
- import org.gradle.kotlin.dsl.getValue
23
+ import org.gradle.kotlin.dsl.getByName
28
24
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
29
25
import org.jetbrains.kotlin.gradle.plugin.KotlinJsCompilerType
30
26
import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet
31
27
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget
32
28
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTargetWithSimulatorTests
33
- import org.jetbrains.kotlin.gradle.targets.native.DefaultSimulatorTestRun
34
29
import org.jetbrains.kotlin.konan.target.KonanTarget
35
30
import org.tomlj.Toml
36
31
@@ -283,7 +278,17 @@ open class AndroidXComposeMultiplatformExtensionImpl @Inject constructor(
283
278
addAll(darwinFlags)
284
279
if (isIOS) addAll(iosFlags)
285
280
}
286
- it.freeCompilerArgs = it.freeCompilerArgs + flags
281
+
282
+ // TODO: Remove when the issue is fixed in KGP
283
+ // https://youtrack.jetbrains.com/issue/KT-74564
284
+ // it.freeCompilerArgs += flags
285
+ //
286
+ // Fixes problem when instrumented tests compilation is not properly applied to
287
+ // the framework configuration.
288
+ it.linkTaskProvider.configure {
289
+ @Suppress(" DEPRECATION" )
290
+ it.kotlinOptions.freeCompilerArgs + = flags
291
+ }
287
292
}
288
293
}
289
294
multiplatformExtension.run {
@@ -295,68 +300,36 @@ open class AndroidXComposeMultiplatformExtensionImpl @Inject constructor(
295
300
}
296
301
}
297
302
298
- // https://youtrack.jetbrains.com/issue/KT-55751/MPP-Gradle-Consumable-configurations-must-have-unique-attributes
299
- private val instrumentedTestAttribute = Attribute .of(" instrumentedTest" , String ::class .java)
300
- private val instrumentedTestCompilationAttribute = Attribute .of(" instrumentedTestCompilation" , String ::class .java)
301
- override fun iosInstrumentedTest (): Unit =
303
+ override fun iosInstrumentedTest () {
302
304
multiplatformExtension.run {
303
- fun getDeviceName (): String? {
304
- return project.findProperty(" iosSimulatorName" ) as ? String
305
- }
306
-
307
- val bootTask = project.tasks.register(" bootIosSimulator" , Exec ::class .java) { task ->
308
- task.isIgnoreExitValue = true
309
- task.errorOutput = ByteArrayOutputStream ()
310
- task.doFirst {
311
- val simulatorName = getDeviceName()
312
- ? : error(" Device is not provided. Use Use the -PiosSimulatorName=<Device name> flag to pass the device." )
313
- task.commandLine(" xcrun" , " simctl" , " boot" , simulatorName)
314
- }
315
- task.doLast {
316
- val result = task.executionResult.get()
317
- if (result.exitValue != 148 && result.exitValue != 149 ) { // ignoring device already booted errors
318
- result.assertNormalExitValue()
319
- }
320
- }
321
- }
305
+ val uikitInstrumentedTest = sourceSets.create(" uikitInstrumentedTest" )
322
306
323
307
fun KotlinNativeTargetWithSimulatorTests.configureTestRun () {
324
- attributes.attribute(instrumentedTestAttribute, " test" )
325
- testRuns.forEach {
326
- (it as DefaultSimulatorTestRun ).executionTask.configure { task ->
327
- task.dependsOn(bootTask)
328
- task.standalone.set(false )
329
- task.device.set(getDeviceName())
308
+ val testCompilation = compilations.create(" instrumentedTest" ) {
309
+ compilerOptions {
310
+ // Generate K/N test runner for kotlin.test @Test support
311
+ freeCompilerArgs.add(" -tr" )
330
312
}
313
+
314
+ it.associateWith(compilations.getByName(" test" ))
315
+ it.defaultSourceSet.dependsOn(uikitInstrumentedTest)
331
316
}
332
- compilations.forEach {
333
- it.attributes.attribute(instrumentedTestCompilationAttribute, " test" )
317
+ binaries.framework(" InstrumentedTest" , setOf (DEBUG )) {
318
+ compilation = testCompilation
319
+ baseName = " InstrumentedTest"
320
+ isStatic = true
334
321
}
335
322
}
336
-
337
- iosX64(" uikitInstrumentedX64" ) {
338
- configureTestRun()
339
- }
340
- // Testing on real iOS devices is not supported.
341
- // iosArm64("uikitInstrumentedArm64") { ... }
342
- iosSimulatorArm64(" uikitInstrumentedSimArm64" ) {
343
- configureTestRun()
344
- }
345
-
346
- val uikitMain = sourceSets.getByName(" uikitMain" )
347
- val uikitInstrumentedMain = sourceSets.create(" uikitInstrumentedMain" )
348
- val uikitInstrumentedX64Main = sourceSets.getByName(" uikitInstrumentedX64Main" )
349
- val uikitInstrumentedSimArm64Main = sourceSets.getByName(" uikitInstrumentedSimArm64Main" )
350
- uikitInstrumentedMain.dependsOn(uikitMain)
351
- uikitInstrumentedX64Main.dependsOn(uikitInstrumentedMain)
352
- uikitInstrumentedSimArm64Main.dependsOn(uikitInstrumentedMain)
353
-
354
- val commonTest = sourceSets.getByName(" commonTest" )
355
- val uikitInstrumentedTest = sourceSets.create(" uikitInstrumentedTest" )
356
- val uikitInstrumentedX64Test = sourceSets.getByName(" uikitInstrumentedX64Test" )
357
- val uikitInstrumentedSimArm64Test = sourceSets.getByName(" uikitInstrumentedSimArm64Test" )
358
- uikitInstrumentedTest.dependsOn(commonTest)
359
- uikitInstrumentedX64Test.dependsOn(uikitInstrumentedTest)
360
- uikitInstrumentedSimArm64Test.dependsOn(uikitInstrumentedTest)
323
+ testableTargets.getByName(
324
+ " uikitX64" ,
325
+ KotlinNativeTargetWithSimulatorTests ::class ,
326
+ KotlinNativeTargetWithSimulatorTests ::configureTestRun
327
+ )
328
+ testableTargets.getByName(
329
+ " uikitSimArm64" ,
330
+ KotlinNativeTargetWithSimulatorTests ::class ,
331
+ KotlinNativeTargetWithSimulatorTests ::configureTestRun
332
+ )
361
333
}
334
+ }
362
335
}
0 commit comments