@@ -5,6 +5,7 @@ import org.gradle.api.*
5
5
import org.gradle.api.plugins.*
6
6
import org.gradle.util.*
7
7
import org.jetbrains.kotlin.gradle.dsl.*
8
+ import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet
8
9
import org.jetbrains.kotlin.gradle.plugin.mpp.*
9
10
import org.jetbrains.kotlin.konan.target.*
10
11
@@ -28,10 +29,12 @@ fun Project.configureNativeMultiplatform() {
28
29
}
29
30
30
31
val useNativeBuildInfraInIdea = subproject.findProperty(" useNativeBuildInfraInIdea" )?.toString()?.toBoolean() ? : false
32
+ val commonMain = kotlin.sourceSets.getByName(" commonMain" )
33
+ val commonTest = kotlin.sourceSets.getByName(" commonTest" )
31
34
val extension: Any = if (ideaActive && ! useNativeBuildInfraInIdea)
32
- NativeIdeaInfraExtension (subproject, kotlin, " native" )
35
+ NativeIdeaInfraExtension (subproject, kotlin, " native" , commonMain, commonTest )
33
36
else
34
- NativeBuildInfraExtension (subproject, kotlin, " native" )
37
+ NativeBuildInfraExtension (subproject, kotlin, " native" , commonMain, commonTest )
35
38
36
39
(kotlin as ExtensionAware ).extensions.add(" infra" , extension)
37
40
}
@@ -41,10 +44,12 @@ fun Project.configureNativeMultiplatform() {
41
44
abstract class NativeInfraExtension (
42
45
protected val project : Project ,
43
46
protected val kotlin : KotlinMultiplatformExtension ,
44
- protected val sourceSetName : String
47
+ protected val sourceSetName : String ,
48
+ commonMainSourceSet : KotlinSourceSet ,
49
+ commonTestSourceSet : KotlinSourceSet ,
45
50
) {
46
- protected val mainSourceSet = kotlin.sourceSets.maybeCreate(" ${sourceSetName} Main" )
47
- protected val testSourceSet = kotlin.sourceSets.maybeCreate(" ${sourceSetName} Test" )
51
+ protected val mainSourceSet = kotlin.sourceSets.maybeCreate(" ${sourceSetName} Main" ). apply { dependsOn(commonMainSourceSet) }
52
+ protected val testSourceSet = kotlin.sourceSets.maybeCreate(" ${sourceSetName} Test" ). apply { dependsOn(commonTestSourceSet) }
48
53
49
54
protected val sharedConfigs = mutableListOf<KotlinNativeTarget .() - > Unit > ()
50
55
fun shared (configure : Closure <* >) = shared { ConfigureUtil .configure(configure, this ) }
@@ -60,8 +65,13 @@ abstract class NativeInfraExtension(
60
65
abstract fun common (name : String , configure : NativeInfraExtension .() -> Unit )
61
66
}
62
67
63
- class NativeIdeaInfraExtension (project : Project , kotlin : KotlinMultiplatformExtension , sourceSetName : String ) :
64
- NativeInfraExtension (project, kotlin, sourceSetName) {
68
+ class NativeIdeaInfraExtension (
69
+ project : Project ,
70
+ kotlin : KotlinMultiplatformExtension ,
71
+ sourceSetName : String ,
72
+ commonMainSourceSet : KotlinSourceSet ,
73
+ commonTestSourceSet : KotlinSourceSet ,
74
+ ) : NativeInfraExtension(project, kotlin, sourceSetName, commonMainSourceSet, commonTestSourceSet) {
65
75
66
76
private val hostManager = createHostManager()
67
77
@@ -96,15 +106,18 @@ class NativeIdeaInfraExtension(project: Project, kotlin: KotlinMultiplatformExte
96
106
}
97
107
98
108
override fun common (name : String , configure : NativeInfraExtension .() -> Unit ) {
99
- kotlin.sourceSets.create(" ${name} Main" ).dependsOn(mainSourceSet)
100
- kotlin.sourceSets.create(" ${name} Test" ).dependsOn(testSourceSet)
101
- val extension = NativeIdeaInfraExtension (project, kotlin, name)
109
+ val extension = NativeIdeaInfraExtension (project, kotlin, name, mainSourceSet, testSourceSet)
102
110
extension.configure()
103
111
}
104
112
}
105
113
106
- class NativeBuildInfraExtension (project : Project , kotlin : KotlinMultiplatformExtension , sourceSetName : String ) :
107
- NativeInfraExtension (project, kotlin, sourceSetName) {
114
+ class NativeBuildInfraExtension (
115
+ project : Project ,
116
+ kotlin : KotlinMultiplatformExtension ,
117
+ sourceSetName : String ,
118
+ commonMainSourceSet : KotlinSourceSet ,
119
+ commonTestSourceSet : KotlinSourceSet ,
120
+ ) : NativeInfraExtension(project, kotlin, sourceSetName, commonMainSourceSet, commonTestSourceSet) {
108
121
109
122
private val nativePresets = kotlin.presets.filterIsInstance<AbstractKotlinNativeTargetPreset <* >>()
110
123
@@ -131,9 +144,7 @@ class NativeBuildInfraExtension(project: Project, kotlin: KotlinMultiplatformExt
131
144
}
132
145
133
146
override fun common (name : String , configure : NativeInfraExtension .() -> Unit ) {
134
- kotlin.sourceSets.create(" ${name} Main" ).dependsOn(mainSourceSet)
135
- kotlin.sourceSets.create(" ${name} Test" ).dependsOn(testSourceSet)
136
- val extension = NativeBuildInfraExtension (project, kotlin, name)
147
+ val extension = NativeBuildInfraExtension (project, kotlin, name, mainSourceSet, testSourceSet)
137
148
extension.configure()
138
149
}
139
150
}
0 commit comments