Always create shared-Native metadata compilations
Create the compilations even when all of the targets that the shared-Native source set is compiled for are disabled on the current host. In that case, disable the compilation task Also clear the inputs of the disabled tasks so that when Gradle builds the task graph it doesn't resolve the dependencies. Otherwise, a Gradle build that includes the compile tasks of the disabled targets in the task graph would fail as follows, e.g. on a macOS host with a project containing a mingw target): ``` Could not determine the dependencies of task ':compileKotlinMingwX86' ... Could not resolve all task dependencies for configuration ':mingwX86CompileKlibraries' ... Could not find com.example:my-dependency-mingwx86:1.0 ...
This commit is contained in:
+13
-7
@@ -258,8 +258,9 @@ class KotlinMetadataTargetConfigurator(kotlinPluginVersion: String) :
|
||||
|
||||
val compilationName = sourceSet.name
|
||||
|
||||
val isNativeSourceSet = CompilationSourceSetUtil.compilationsBySourceSets(project).getValue(sourceSet)
|
||||
.all { compilation -> compilation.target is KotlinNativeTarget }
|
||||
val platformCompilations = CompilationSourceSetUtil.compilationsBySourceSets(project).getValue(sourceSet)
|
||||
|
||||
val isNativeSourceSet = platformCompilations.all { compilation -> compilation.target is KotlinNativeTarget }
|
||||
|
||||
val compilationFactory: KotlinCompilationFactory<out AbstractKotlinCompilation<*>> = when {
|
||||
isNativeSourceSet -> KotlinSharedNativeCompilationFactory(target)
|
||||
@@ -275,6 +276,14 @@ class KotlinMetadataTargetConfigurator(kotlinPluginVersion: String) :
|
||||
if (!isHostSpecific) {
|
||||
val metadataContent = project.filesWithUnpackedArchives(this@apply.output.allOutputs, setOf("klib"))
|
||||
allMetadataJar.from(metadataContent) { spec -> spec.into(this@apply.defaultSourceSet.name) }
|
||||
} else {
|
||||
if (platformCompilations.filterIsInstance<KotlinNativeCompilation>().none { it.konanTarget.enabledOnCurrentHost }) {
|
||||
// Then we don't have any platform module to put this compiled source set to, so disable the compilation task:
|
||||
compileKotlinTaskHolder.configure { it.enabled = false }
|
||||
// Also clear the dependency files (classpath) of the compilation so that the host-specific dependencies are
|
||||
// not resolved:
|
||||
compileDependencyFiles = project.files()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -476,11 +485,8 @@ internal fun getPublishedCommonSourceSets(project: Project): Set<KotlinSourceSet
|
||||
|
||||
val sourceSetsUsedInMultipleTargets = compilationsBySourceSet.filterValues { compilations ->
|
||||
compilations.map { it.target.platformType }.distinct().run {
|
||||
size > 1 && toSet() != setOf(KotlinPlatformType.androidJvm, KotlinPlatformType.jvm) || (
|
||||
singleOrNull() == KotlinPlatformType.native &&
|
||||
compilations.map { it.target }.distinct().size > 1 &&
|
||||
compilations.any { (it as AbstractKotlinNativeCompilation).konanTarget.enabledOnCurrentHost }
|
||||
)
|
||||
size > 1 && toSet() != setOf(KotlinPlatformType.androidJvm, KotlinPlatformType.jvm) ||
|
||||
singleOrNull() == KotlinPlatformType.native && compilations.map { it.target }.distinct().size > 1
|
||||
// TODO: platform-shared source sets other than Kotlin/Native ones are not yet supported; support will be needed for JVM, JS
|
||||
}
|
||||
}
|
||||
|
||||
+5
-1
@@ -128,7 +128,11 @@ abstract class AbstractKotlinNativeCompile<T : KotlinCommonToolOptions> : Abstra
|
||||
|
||||
// Inputs and outputs
|
||||
val libraries: FileCollection
|
||||
@InputFiles get() = compilation.compileDependencyFiles.filterOutPublishableInteropLibs(project)
|
||||
@InputFiles get() =
|
||||
// Avoid resolving these dependencies during task graph construction when we can't build the target:
|
||||
if (compilation.konanTarget.enabledOnCurrentHost)
|
||||
compilation.compileDependencyFiles.filterOutPublishableInteropLibs(project)
|
||||
else project.files()
|
||||
|
||||
override fun getClasspath(): FileCollection = libraries
|
||||
override fun setClasspath(configuration: FileCollection?) {
|
||||
|
||||
Reference in New Issue
Block a user