3
3
*/
4
4
5
5
apply plugin : ' org.jetbrains.kotlin.multiplatform'
6
- apply from : rootProject. file(" gradle/targets.gradle" )
7
6
apply from : rootProject. file(" gradle/compile-jvm-multiplatform.gradle" )
8
7
apply from : rootProject. file(" gradle/compile-common.gradle" )
9
8
apply from : rootProject. file(" gradle/compile-js-multiplatform.gradle" )
10
9
apply from : rootProject. file(" gradle/compile-native-multiplatform.gradle" )
11
10
apply from : rootProject. file(' gradle/publish-npm-js.gradle' )
12
11
12
+ /* ==========================================================================
13
+ Configure source sets structure for kotlinx-coroutines-core:
14
+
15
+ TARGETS SOURCE SETS
16
+ ------- ----------------------------------------------
17
+
18
+ js -----------------------------------------------------+
19
+ |
20
+ V
21
+ jvm -------------------------------> concurrent ---> common
22
+ ^
23
+ ios \ |
24
+ macos | ---> nativeDarwin ---> native --+
25
+ tvos | ^
26
+ watchos / |
27
+ |
28
+ linux \ ---> nativeOther -------+
29
+ mingw /
30
+
31
+ ========================================================================== */
32
+
33
+ project. ext. sourceSetSuffixes = [" Main" , " Test" ]
34
+
35
+ void defineSourceSet (newName , dependsOn , includedInPred ) {
36
+ for (suffix in project. ext. sourceSetSuffixes) {
37
+ def newSS = kotlin. sourceSets. maybeCreate(newName + suffix)
38
+ for (dep in dependsOn) {
39
+ newSS. dependsOn(kotlin. sourceSets[dep + suffix])
40
+ }
41
+ for (curSS in kotlin. sourceSets) {
42
+ def curName = curSS. name
43
+ if (curName. endsWith(suffix)) {
44
+ def prefix = curName. substring(0 , curName. length() - suffix. length())
45
+ if (includedInPred(prefix)) curSS. dependsOn(newSS)
46
+ }
47
+ }
48
+ }
49
+ }
50
+
51
+ static boolean isNativeDarwin (String name ) { return [" ios" , " macos" , " tvos" , " watchos" ]. any { name. startsWith(it) } }
52
+ static boolean isNativeOther (String name ) { return [" linux" , " mingw" ]. any { name. startsWith(it) } }
53
+
54
+ defineSourceSet(" concurrent" , [" common" ]) { it in [" jvm" , " native" ] }
55
+ defineSourceSet(" nativeDarwin" , [" native" ]) { isNativeDarwin(it) }
56
+ defineSourceSet(" nativeOther" , [" native" ]) { isNativeOther(it) }
57
+
58
+ /* ========================================================================== */
59
+
13
60
/*
14
61
* All platform plugins and configuration magic happens here instead of build.gradle
15
62
* because JMV-only projects depend on core, thus core should always be initialized before configuration.
@@ -18,7 +65,7 @@ kotlin {
18
65
configure(sourceSets) {
19
66
def srcDir = name. endsWith(' Main' ) ? ' src' : ' test'
20
67
def platform = name[0 .. -5 ]
21
- kotlin. srcDir " $platform /$srcDir "
68
+ kotlin. srcDirs = [ " $platform /$srcDir " ]
22
69
if (name == " jvmMain" ) {
23
70
resources. srcDirs = [" $platform /resources" ]
24
71
} else if (name == " jvmTest" ) {
@@ -31,12 +78,18 @@ kotlin {
31
78
}
32
79
33
80
configure(targets) {
34
- def targetName = it. name
35
- compilations. all { compilation ->
36
- def compileTask = tasks. getByName(compilation. compileKotlinTaskName)
37
- // binary compatibility support
38
- if (targetName. contains(" jvm" ) && compilation. compilationName == " main" ) {
39
- compileTask. kotlinOptions. freeCompilerArgs + = [" -Xdump-declarations-to=${ buildDir} /visibilities.json" ]
81
+ // Configure additional binaries and test runs -- one for each OS
82
+ if ([" macos" , " linux" , " mingw" ]. any { name. startsWith(it) }) {
83
+ binaries {
84
+ // Test for memory leaks using a special entry point that does not exit but returns from main
85
+ binaries. getTest(" DEBUG" ). freeCompilerArgs + = [" -e" , " kotlinx.coroutines.mainNoExit" ]
86
+ // Configure a separate test where code runs in background
87
+ test(" background" , [org.jetbrains.kotlin.gradle.plugin.mpp.NativeBuildType . DEBUG ]) {
88
+ freeCompilerArgs + = [" -e" , " kotlinx.coroutines.mainBackground" ]
89
+ }
90
+ }
91
+ testRuns {
92
+ background { setExecutionSourceFrom(binaries. backgroundDebugTest) }
40
93
}
41
94
}
42
95
}
@@ -54,23 +107,52 @@ compileKotlinMetadata {
54
107
}
55
108
}
56
109
110
+ // :KLUDGE: Idea.active: This is needed to workaround resolve problems after importing this project to IDEA
111
+ def configureNativeSourceSetPreset (name , preset ) {
112
+ def hostMainCompilation = project. kotlin. targetFromPreset(preset). compilations. main
113
+ // Look for platform libraries in "implementation" for default source set
114
+ def implementationConfiguration = configurations[hostMainCompilation. defaultSourceSet. implementationMetadataConfigurationName]
115
+ // Now find the libraries: Finds platform libs & stdlib, but platform declarations are still not resolved due to IDE bugs
116
+ def hostNativePlatformLibs = files(
117
+ provider {
118
+ implementationConfiguration. findAll {
119
+ it. path. endsWith(" .klib" ) || it. absolutePath. contains(" klib${ File.separator} platform" ) || it. absolutePath. contains(" stdlib" )
120
+ }
121
+ }
122
+ )
123
+ // Add all those dependencies
124
+ for (suffix in sourceSetSuffixes) {
125
+ configure(kotlin. sourceSets[name + suffix]) {
126
+ dependencies. add(implementationMetadataConfigurationName, hostNativePlatformLibs)
127
+ }
128
+ }
129
+ }
130
+
131
+ // :KLUDGE: Idea.active: Configure platform libraries for native source sets when working in IDEA
132
+ if (Idea . active) {
133
+ def manager = project. ext. hostManager
134
+ def linuxPreset = kotlin. presets. linuxX64
135
+ def macosPreset = kotlin. presets. macosX64
136
+ // linux should be always available (cross-compilation capable) -- use it as default
137
+ assert manager. isEnabled(linuxPreset. konanTarget)
138
+ // use macOS libs for nativeDarwin if available
139
+ def macosAvailable = manager. isEnabled(macosPreset. konanTarget)
140
+ // configure source sets
141
+ configureNativeSourceSetPreset(" native" , linuxPreset)
142
+ configureNativeSourceSetPreset(" nativeOther" , linuxPreset)
143
+ configureNativeSourceSetPreset(" nativeDarwin" , macosAvailable ? macosPreset : linuxPreset)
144
+ }
145
+
57
146
kotlin. sourceSets {
58
147
jvmMain. dependencies {
59
148
compileOnly " com.google.android:annotations:4.1.1.4"
60
149
}
61
150
62
151
jvmTest. dependencies {
63
- // This is a workaround for https://youtrack.jetbrains.com/issue/KT-39037
64
- def excludingCurrentProject = { dependency ->
65
- def result = project. dependencies. create(dependency)
66
- result. exclude(module : project. name)
67
- return result
68
- }
69
-
70
- api(excludingCurrentProject(" org.jetbrains.kotlinx:lincheck:$lincheck_version " ))
152
+ api " org.jetbrains.kotlinx:lincheck:$lincheck_version "
71
153
api " org.jetbrains.kotlinx:kotlinx-knit-test:$knit_version "
72
154
api " com.esotericsoftware:kryo:4.0.0"
73
- implementation(excludingCurrentProject( project(" :android-unit-tests" )) )
155
+ implementation project(" :android-unit-tests" )
74
156
}
75
157
}
76
158
@@ -97,7 +179,7 @@ jvmTest {
97
179
enableAssertions = true
98
180
systemProperty ' java.security.manager' , ' kotlinx.coroutines.TestSecurityManager'
99
181
// 'stress' is required to be able to run all subpackage tests like ":jvmTests --tests "*channels*" -Pstress=true"
100
- if (! project . ext . ideaActive && rootProject. properties[' stress' ] == null ) {
182
+ if (! Idea . active && rootProject. properties[' stress' ] == null ) {
101
183
exclude ' **/*StressTest.*'
102
184
}
103
185
systemProperty ' kotlinx.coroutines.scheduler.keep.alive.sec' , ' 100000' // any unpark problem hangs test
0 commit comments