Add Native stdlib to intermediate source set dependencies
Also fix the dependsOn source set IDs not matcing those in the IDE.
This commit is contained in:
committed by
Sergey Igushkin
parent
1ccda6a8d4
commit
bcabbcf3e1
+1
-1
@@ -910,7 +910,7 @@ open class KotlinMPPGradleProjectResolver : AbstractProjectResolverExtension() {
|
|||||||
sourceSetInfo.gradleModuleId = getModuleId(resolverCtx, gradleModule)
|
sourceSetInfo.gradleModuleId = getModuleId(resolverCtx, gradleModule)
|
||||||
sourceSetInfo.actualPlatforms.addSimplePlatforms(listOf(compilation.platform))
|
sourceSetInfo.actualPlatforms.addSimplePlatforms(listOf(compilation.platform))
|
||||||
sourceSetInfo.isTestModule = compilation.isTestModule
|
sourceSetInfo.isTestModule = compilation.isTestModule
|
||||||
sourceSetInfo.dependsOn = compilation.sourceSets.flatMap { it.dependsOnSourceSets }.map { gradleModule.name + "_" + it }.distinct().toList()
|
sourceSetInfo.dependsOn = compilation.sourceSets.flatMap { it.dependsOnSourceSets }.map { getModuleId(resolverCtx, gradleModule) + ":" + it }.distinct().toList()
|
||||||
sourceSetInfo.compilerArguments =
|
sourceSetInfo.compilerArguments =
|
||||||
createCompilerArguments(compilation.arguments.currentArguments.toList(), compilation.platform).also {
|
createCompilerArguments(compilation.arguments.currentArguments.toList(), compilation.platform).also {
|
||||||
it.multiPlatform = true
|
it.multiPlatform = true
|
||||||
|
|||||||
+37
-10
@@ -3,13 +3,16 @@
|
|||||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@file:Suppress("PackageDirectoryMismatch") // Old package for compatibility
|
@file:Suppress("PackageDirectoryMismatch")
|
||||||
|
|
||||||
|
// Old package for compatibility
|
||||||
|
|
||||||
package org.jetbrains.kotlin.gradle.plugin.mpp
|
package org.jetbrains.kotlin.gradle.plugin.mpp
|
||||||
|
|
||||||
import org.gradle.api.Project
|
import org.gradle.api.Project
|
||||||
import org.gradle.api.artifacts.Dependency
|
import org.gradle.api.artifacts.Dependency
|
||||||
import org.jetbrains.kotlin.compilerRunner.konanHome
|
import org.jetbrains.kotlin.compilerRunner.konanHome
|
||||||
|
import org.jetbrains.kotlin.gradle.dsl.kotlinExtension
|
||||||
import org.jetbrains.kotlin.gradle.plugin.*
|
import org.jetbrains.kotlin.gradle.plugin.*
|
||||||
import org.jetbrains.kotlin.gradle.plugin.PropertiesProvider
|
import org.jetbrains.kotlin.gradle.plugin.PropertiesProvider
|
||||||
import org.jetbrains.kotlin.gradle.targets.native.DisabledNativeTargetsReporter
|
import org.jetbrains.kotlin.gradle.targets.native.DisabledNativeTargetsReporter
|
||||||
@@ -69,7 +72,7 @@ abstract class AbstractKotlinNativeTargetPreset<T : KotlinNativeTarget>(
|
|||||||
filesList?.map { dir -> dependencies.create(files(dir)) } ?: emptyList()
|
filesList?.map { dir -> dependencies.create(files(dir)) } ?: emptyList()
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract fun createTargetConfigurator() : KotlinTargetConfigurator<T>
|
protected abstract fun createTargetConfigurator(): KotlinTargetConfigurator<T>
|
||||||
|
|
||||||
protected abstract fun instantiateTarget(name: String): T
|
protected abstract fun instantiateTarget(name: String): T
|
||||||
|
|
||||||
@@ -87,8 +90,20 @@ abstract class AbstractKotlinNativeTargetPreset<T : KotlinNativeTarget>(
|
|||||||
|
|
||||||
createTargetConfigurator().configureTarget(result)
|
createTargetConfigurator().configureTarget(result)
|
||||||
|
|
||||||
// Allow IDE to resolve the libraries provided by the compiler by adding them into dependencies.
|
addDependenciesOnLibrariesFromDistribution(result)
|
||||||
|
|
||||||
|
if (!konanTarget.enabledOnCurrentHost) {
|
||||||
|
with(HostManager()) {
|
||||||
|
val supportedHosts = enabledByHost.filterValues { konanTarget in it }.keys
|
||||||
|
DisabledNativeTargetsReporter.reportDisabledTarget(project, result, supportedHosts)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
// Allow IDE to resolve the libraries provided by the compiler by adding them into dependencies.
|
||||||
|
private fun addDependenciesOnLibrariesFromDistribution(result: T) {
|
||||||
result.compilations.all { compilation ->
|
result.compilations.all { compilation ->
|
||||||
val target = compilation.konanTarget
|
val target = compilation.konanTarget
|
||||||
project.whenEvaluated {
|
project.whenEvaluated {
|
||||||
@@ -103,14 +118,26 @@ abstract class AbstractKotlinNativeTargetPreset<T : KotlinNativeTarget>(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!konanTarget.enabledOnCurrentHost) {
|
// Add dependencies to stdlib-native for intermediate single-backend source-sets (like 'allNative')
|
||||||
with(HostManager()) {
|
project.whenEvaluated {
|
||||||
val supportedHosts = enabledByHost.filterValues { konanTarget in it }.keys
|
val compilationsBySourceSets = CompilationSourceSetUtil.compilationsBySourceSets(this)
|
||||||
DisabledNativeTargetsReporter.reportDisabledTarget(project, result, supportedHosts)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return result
|
fun KotlinSourceSet.isIntermediateNativeSourceSet(): Boolean {
|
||||||
|
val compilations = compilationsBySourceSets[this] ?: return false
|
||||||
|
|
||||||
|
if (compilations.size <= 1) return false // intermediate source-sets participate at least in two compilations
|
||||||
|
|
||||||
|
return compilations.all { it.target.platformType == KotlinPlatformType.native }
|
||||||
|
}
|
||||||
|
|
||||||
|
val stdlib = defaultLibs(stdlibOnly = true).single()
|
||||||
|
|
||||||
|
project.kotlinExtension.sourceSets
|
||||||
|
.filter { it.isIntermediateNativeSourceSet() }
|
||||||
|
.forEach {
|
||||||
|
it.dependencies { implementation(stdlib) }
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|||||||
Reference in New Issue
Block a user