Refactor: add Project.getMetadataCompilationForSourceSet extension.
This commit is contained in:
+8
-4
@@ -18,6 +18,7 @@ import org.gradle.api.tasks.bundling.Zip
|
|||||||
import org.jetbrains.kotlin.gradle.dsl.KotlinCommonOptions
|
import org.jetbrains.kotlin.gradle.dsl.KotlinCommonOptions
|
||||||
import org.jetbrains.kotlin.gradle.dsl.kotlinExtension
|
import org.jetbrains.kotlin.gradle.dsl.kotlinExtension
|
||||||
import org.jetbrains.kotlin.gradle.dsl.multiplatformExtension
|
import org.jetbrains.kotlin.gradle.dsl.multiplatformExtension
|
||||||
|
import org.jetbrains.kotlin.gradle.dsl.multiplatformExtensionOrNull
|
||||||
import org.jetbrains.kotlin.gradle.plugin.*
|
import org.jetbrains.kotlin.gradle.plugin.*
|
||||||
import org.jetbrains.kotlin.gradle.plugin.mpp.*
|
import org.jetbrains.kotlin.gradle.plugin.mpp.*
|
||||||
import org.jetbrains.kotlin.gradle.plugin.sources.*
|
import org.jetbrains.kotlin.gradle.plugin.sources.*
|
||||||
@@ -403,7 +404,6 @@ class KotlinMetadataTargetConfigurator(kotlinPluginVersion: String) :
|
|||||||
// and their dependencies metadata transformed for compilation:
|
// and their dependencies metadata transformed for compilation:
|
||||||
return project.files(
|
return project.files(
|
||||||
project.provider {
|
project.provider {
|
||||||
val metadataTarget = compilation.target
|
|
||||||
val sourceSet = compilation.defaultSourceSet
|
val sourceSet = compilation.defaultSourceSet
|
||||||
|
|
||||||
val transformationTaskHolders = sourceSet.getSourceSetHierarchy().mapNotNull { hierarchySourceSet ->
|
val transformationTaskHolders = sourceSet.getSourceSetHierarchy().mapNotNull { hierarchySourceSet ->
|
||||||
@@ -424,8 +424,8 @@ class KotlinMetadataTargetConfigurator(kotlinPluginVersion: String) :
|
|||||||
transformationTaskHolders.flatMap { it.get().filesByResolution.toList() }.toMap()
|
transformationTaskHolders.flatMap { it.get().filesByResolution.toList() }.toMap()
|
||||||
|
|
||||||
val dependsOnCompilationOutputs = sourceSet.getSourceSetHierarchy().mapNotNull { hierarchySourceSet ->
|
val dependsOnCompilationOutputs = sourceSet.getSourceSetHierarchy().mapNotNull { hierarchySourceSet ->
|
||||||
val dependencyCompilation = metadataTarget.compilations.getByName(hierarchySourceSet.name)
|
val dependencyCompilation = project.getMetadataCompilationForSourceSet(hierarchySourceSet)
|
||||||
dependencyCompilation.output.classesDirs.takeIf { hierarchySourceSet != sourceSet }
|
dependencyCompilation?.output?.classesDirs.takeIf { hierarchySourceSet != sourceSet }
|
||||||
}
|
}
|
||||||
|
|
||||||
val artifactView = fromFiles.incoming.artifactView { view ->
|
val artifactView = fromFiles.incoming.artifactView { view ->
|
||||||
@@ -540,4 +540,8 @@ internal fun Project.filesWithUnpackedArchives(from: FileCollection, extensions:
|
|||||||
if (it.exists()) project.zipTree(it) else null
|
if (it.exists()) project.zipTree(it) else null
|
||||||
} else it
|
} else it
|
||||||
}
|
}
|
||||||
}).builtBy(from)
|
}).builtBy(from)
|
||||||
|
|
||||||
|
internal fun Project.getMetadataCompilationForSourceSet(sourceSet: KotlinSourceSet): AbstractKotlinCompilation<*>? {
|
||||||
|
return multiplatformExtension.metadata().compilations.findByName(sourceSet.name)
|
||||||
|
}
|
||||||
+2
-1
@@ -21,6 +21,7 @@ import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet
|
|||||||
import org.jetbrains.kotlin.gradle.plugin.KotlinTarget
|
import org.jetbrains.kotlin.gradle.plugin.KotlinTarget
|
||||||
import org.jetbrains.kotlin.gradle.plugin.sources.getSourceSetHierarchy
|
import org.jetbrains.kotlin.gradle.plugin.sources.getSourceSetHierarchy
|
||||||
import org.jetbrains.kotlin.gradle.plugin.sources.getVisibleSourceSetsFromAssociateCompilations
|
import org.jetbrains.kotlin.gradle.plugin.sources.getVisibleSourceSetsFromAssociateCompilations
|
||||||
|
import org.jetbrains.kotlin.gradle.targets.metadata.getMetadataCompilationForSourceSet
|
||||||
import org.jetbrains.kotlin.gradle.tasks.KotlinNativeCompile
|
import org.jetbrains.kotlin.gradle.tasks.KotlinNativeCompile
|
||||||
import org.jetbrains.kotlin.gradle.utils.SingleWarningPerBuild
|
import org.jetbrains.kotlin.gradle.utils.SingleWarningPerBuild
|
||||||
import org.jetbrains.kotlin.gradle.utils.lowerCamelCaseName
|
import org.jetbrains.kotlin.gradle.utils.lowerCamelCaseName
|
||||||
@@ -117,6 +118,6 @@ class KotlinSharedNativeCompilation(override val target: KotlinMetadataTarget, v
|
|||||||
addAll(defaultSourceSet.getSourceSetHierarchy())
|
addAll(defaultSourceSet.getSourceSetHierarchy())
|
||||||
remove(defaultSourceSet)
|
remove(defaultSourceSet)
|
||||||
}
|
}
|
||||||
project.files(friendSourceSets.mapNotNull { target.compilations.findByName(it.name)?.output?.classesDirs })
|
project.files(friendSourceSets.mapNotNull { project.getMetadataCompilationForSourceSet(it)?.output?.classesDirs })
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
+2
-2
@@ -17,8 +17,8 @@ import org.jetbrains.kotlin.gradle.dsl.KotlinNativeBinaryContainer
|
|||||||
import org.jetbrains.kotlin.gradle.dsl.kotlinExtension
|
import org.jetbrains.kotlin.gradle.dsl.kotlinExtension
|
||||||
import org.jetbrains.kotlin.gradle.dsl.multiplatformExtension
|
import org.jetbrains.kotlin.gradle.dsl.multiplatformExtension
|
||||||
import org.jetbrains.kotlin.gradle.plugin.*
|
import org.jetbrains.kotlin.gradle.plugin.*
|
||||||
|
import org.jetbrains.kotlin.gradle.targets.metadata.*
|
||||||
import org.jetbrains.kotlin.gradle.targets.metadata.filesWithUnpackedArchives
|
import org.jetbrains.kotlin.gradle.targets.metadata.filesWithUnpackedArchives
|
||||||
import org.jetbrains.kotlin.gradle.targets.metadata.getPublishedCommonSourceSets
|
|
||||||
import org.jetbrains.kotlin.gradle.targets.metadata.isKotlinGranularMetadataEnabled
|
import org.jetbrains.kotlin.gradle.targets.metadata.isKotlinGranularMetadataEnabled
|
||||||
import org.jetbrains.kotlin.gradle.targets.native.KotlinNativeBinaryTestRun
|
import org.jetbrains.kotlin.gradle.targets.native.KotlinNativeBinaryTestRun
|
||||||
import org.jetbrains.kotlin.gradle.targets.native.KotlinNativeHostTestRun
|
import org.jetbrains.kotlin.gradle.targets.native.KotlinNativeHostTestRun
|
||||||
@@ -71,7 +71,7 @@ open class KotlinNativeTarget @Inject constructor(
|
|||||||
metadataJar.onlyIf { this@KotlinNativeTarget.publishable }
|
metadataJar.onlyIf { this@KotlinNativeTarget.publishable }
|
||||||
|
|
||||||
val metadataCompilations = hostSpecificSourceSets.mapNotNull {
|
val metadataCompilations = hostSpecificSourceSets.mapNotNull {
|
||||||
project.multiplatformExtension.metadata().compilations.findByName(it.name)
|
project.getMetadataCompilationForSourceSet(it)
|
||||||
}
|
}
|
||||||
|
|
||||||
metadataCompilations.forEach {
|
metadataCompilations.forEach {
|
||||||
|
|||||||
Reference in New Issue
Block a user