Provide aggregate link tasks
This commit is contained in:
+34
-15
@@ -7,6 +7,7 @@ package org.jetbrains.kotlin.gradle.dsl
|
|||||||
|
|
||||||
import org.gradle.api.*
|
import org.gradle.api.*
|
||||||
import org.gradle.api.plugins.ExtensionAware
|
import org.gradle.api.plugins.ExtensionAware
|
||||||
|
import org.gradle.util.WrapUtil
|
||||||
import org.jetbrains.kotlin.gradle.plugin.KotlinCompilation
|
import org.jetbrains.kotlin.gradle.plugin.KotlinCompilation
|
||||||
import org.jetbrains.kotlin.gradle.plugin.mpp.*
|
import org.jetbrains.kotlin.gradle.plugin.mpp.*
|
||||||
import org.jetbrains.kotlin.gradle.utils.lowerCamelCaseName
|
import org.jetbrains.kotlin.gradle.utils.lowerCamelCaseName
|
||||||
@@ -44,6 +45,7 @@ open class KotlinNativeBinaryContainer @Inject constructor(
|
|||||||
get() = target.compilations.getByName(KotlinCompilation.MAIN_COMPILATION_NAME)
|
get() = target.compilations.getByName(KotlinCompilation.MAIN_COMPILATION_NAME)
|
||||||
|
|
||||||
private val nameToBinary = mutableMapOf<String, NativeBinary>()
|
private val nameToBinary = mutableMapOf<String, NativeBinary>()
|
||||||
|
internal val prefixGroups: NamedDomainObjectSet<PrefixGroup> = WrapUtil.toNamedDomainObjectSet(PrefixGroup::class.java)
|
||||||
|
|
||||||
// region DSL getters.
|
// region DSL getters.
|
||||||
private fun generateName(prefix: String, buildType: NativeBuildType, outputKindClassifier: String) =
|
private fun generateName(prefix: String, buildType: NativeBuildType, outputKindClassifier: String) =
|
||||||
@@ -116,25 +118,32 @@ open class KotlinNativeBinaryContainer @Inject constructor(
|
|||||||
buildTypes: Collection<NativeBuildType>,
|
buildTypes: Collection<NativeBuildType>,
|
||||||
create: (name: String, baseName: String, buildType: NativeBuildType, compilation: KotlinNativeCompilation) -> T,
|
create: (name: String, baseName: String, buildType: NativeBuildType, compilation: KotlinNativeCompilation) -> T,
|
||||||
configure: T.() -> Unit
|
configure: T.() -> Unit
|
||||||
) = buildTypes.forEach { buildType ->
|
) {
|
||||||
val name = generateName(namePrefix, buildType, outputKind.taskNameClassifier)
|
val prefixGroup = prefixGroups.findByName(namePrefix) ?: PrefixGroup(namePrefix).also {
|
||||||
|
prefixGroups.add(it)
|
||||||
require(name !in nameToBinary) {
|
|
||||||
"Cannot create binary $name: binary with such a name already exists"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
require(outputKind.availableFor(target.konanTarget)) {
|
buildTypes.forEach { buildType ->
|
||||||
"Cannot create binary $name: ${outputKind.taskNameClassifier.decapitalize()} binaries are not available for target ${target.name}"
|
val name = generateName(namePrefix, buildType, outputKind.taskNameClassifier)
|
||||||
}
|
|
||||||
|
|
||||||
val binary = create(name, baseName, buildType, defaultCompilation)
|
require(name !in nameToBinary) {
|
||||||
add(binary)
|
"Cannot create binary $name: binary with such a name already exists"
|
||||||
nameToBinary[binary.name] = binary
|
}
|
||||||
// Allow accessing binaries as properties of the container in Groovy DSL.
|
|
||||||
if (this is ExtensionAware) {
|
require(outputKind.availableFor(target.konanTarget)) {
|
||||||
extensions.add(binary.name, binary)
|
"Cannot create binary $name: ${outputKind.taskNameClassifier.decapitalize()} binaries are not available for target ${target.name}"
|
||||||
|
}
|
||||||
|
|
||||||
|
val binary = create(name, baseName, buildType, defaultCompilation)
|
||||||
|
add(binary)
|
||||||
|
prefixGroup.binaries.add(binary)
|
||||||
|
nameToBinary[binary.name] = binary
|
||||||
|
// Allow accessing binaries as properties of the container in Groovy DSL.
|
||||||
|
if (this is ExtensionAware) {
|
||||||
|
extensions.add(binary.name, binary)
|
||||||
|
}
|
||||||
|
binary.configure()
|
||||||
}
|
}
|
||||||
binary.configure()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
internal fun defaultTestExecutable(
|
internal fun defaultTestExecutable(
|
||||||
@@ -150,4 +159,14 @@ open class KotlinNativeBinaryContainer @Inject constructor(
|
|||||||
configure
|
configure
|
||||||
)
|
)
|
||||||
// endregion.
|
// endregion.
|
||||||
|
|
||||||
|
internal inner class PrefixGroup(
|
||||||
|
private val name: String
|
||||||
|
) : Named {
|
||||||
|
override fun getName(): String = name
|
||||||
|
val binaries: DomainObjectSet<NativeBinary> = WrapUtil.toDomainObjectSet(NativeBinary::class.java)
|
||||||
|
|
||||||
|
val linkTaskName: String
|
||||||
|
get() = lowerCamelCaseName("link", name, target.targetName)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+11
-7
@@ -464,10 +464,7 @@ open class KotlinNativeTargetConfigurator(
|
|||||||
// endregion.
|
// endregion.
|
||||||
|
|
||||||
// region Task creation.
|
// region Task creation.
|
||||||
private fun Project.createLinkTask(binary: NativeBinary) {
|
private fun Project.createLinkTask(target: KotlinNativeTarget, binary: NativeBinary) {
|
||||||
// TODO: drop compilation.linkAllTaskName
|
|
||||||
// TODO: drop compilation.binaryTasks
|
|
||||||
// TODO: Provide a link all task.
|
|
||||||
tasks.create(
|
tasks.create(
|
||||||
binary.linkTaskName,
|
binary.linkTaskName,
|
||||||
KotlinNativeLink::class.java
|
KotlinNativeLink::class.java
|
||||||
@@ -479,6 +476,8 @@ open class KotlinNativeTargetConfigurator(
|
|||||||
enabled = target.konanTarget.enabledOnCurrentHost
|
enabled = target.konanTarget.enabledOnCurrentHost
|
||||||
destinationDir = binary.outputDirectory
|
destinationDir = binary.outputDirectory
|
||||||
addCompilerPlugins()
|
addCompilerPlugins()
|
||||||
|
|
||||||
|
tasks.maybeCreate(target.artifactsTaskName).dependsOn(this)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -531,11 +530,9 @@ open class KotlinNativeTargetConfigurator(
|
|||||||
if (compilation.compilationName == KotlinCompilation.MAIN_COMPILATION_NAME) {
|
if (compilation.compilationName == KotlinCompilation.MAIN_COMPILATION_NAME) {
|
||||||
project.tasks.getByName(compilation.target.artifactsTaskName).apply {
|
project.tasks.getByName(compilation.target.artifactsTaskName).apply {
|
||||||
dependsOn(compileTask)
|
dependsOn(compileTask)
|
||||||
dependsOn(compilation.linkAllTaskName)
|
|
||||||
}
|
}
|
||||||
project.tasks.getByName(LifecycleBasePlugin.ASSEMBLE_TASK_NAME).apply {
|
project.tasks.getByName(LifecycleBasePlugin.ASSEMBLE_TASK_NAME).apply {
|
||||||
dependsOn(compileTask)
|
dependsOn(compileTask)
|
||||||
dependsOn(compilation.linkAllTaskName)
|
|
||||||
}
|
}
|
||||||
createRegularKlibArtifact(compilation, compileTask)
|
createRegularKlibArtifact(compilation, compileTask)
|
||||||
}
|
}
|
||||||
@@ -614,13 +611,20 @@ open class KotlinNativeTargetConfigurator(
|
|||||||
protected fun configureBinaries(target: KotlinNativeTarget) {
|
protected fun configureBinaries(target: KotlinNativeTarget) {
|
||||||
val project = target.project
|
val project = target.project
|
||||||
target.binaries.all {
|
target.binaries.all {
|
||||||
project.createLinkTask(it)
|
project.createLinkTask(target, it)
|
||||||
}
|
}
|
||||||
|
|
||||||
target.binaries.withType(Executable::class.java).all {
|
target.binaries.withType(Executable::class.java).all {
|
||||||
project.createRunTask(it)
|
project.createRunTask(it)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
target.binaries.prefixGroups.all { prefixGroup ->
|
||||||
|
val linkGroupTask = project.tasks.maybeCreate(prefixGroup.linkTaskName)
|
||||||
|
prefixGroup.binaries.all {
|
||||||
|
linkGroupTask.dependsOn(it.linkTaskName)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Create binaries for output kinds declared using the old DSL.
|
// Create binaries for output kinds declared using the old DSL.
|
||||||
project.whenEvaluated {
|
project.whenEvaluated {
|
||||||
target.compilations.all { compilation ->
|
target.compilations.all { compilation ->
|
||||||
|
|||||||
+1
-2
@@ -16,14 +16,13 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinNativeLink
|
|||||||
import org.jetbrains.kotlin.gradle.utils.lowerCamelCaseName
|
import org.jetbrains.kotlin.gradle.utils.lowerCamelCaseName
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
// TODO: Extract API.
|
|
||||||
|
|
||||||
// TODO: Should the baseName be a var?
|
// TODO: Should the baseName be a var?
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A base class representing a final binary produced by the Kotlin/Native compiler
|
* A base class representing a final binary produced by the Kotlin/Native compiler
|
||||||
* @param name - a name of the DSL entity.
|
* @param name - a name of the DSL entity.
|
||||||
* @param baseName - a base name for the output binary file. E.g. for baseName foo we produce binaries foo.kexe, libfoo.so, foo.framework.
|
* @param baseName - a base name for the output binary file. E.g. for baseName foo we produce binaries foo.kexe, libfoo.so, foo.framework.
|
||||||
|
* @param buildType - type of a binary: debug (not optimized, debuggable) or release (optimized, not debuggable)
|
||||||
* @param compilation - a compilation used to produce this binary.
|
* @param compilation - a compilation used to produce this binary.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|||||||
-8
@@ -401,14 +401,6 @@ class KotlinNativeCompilation(
|
|||||||
override val processResourcesTaskName: String
|
override val processResourcesTaskName: String
|
||||||
get() = disambiguateName("processResources")
|
get() = disambiguateName("processResources")
|
||||||
|
|
||||||
// TODO: Add linkAll task and add a deprecation here.
|
|
||||||
val linkAllTaskName: String
|
|
||||||
get() = lowerCamelCaseName(
|
|
||||||
"link",
|
|
||||||
compilationName.takeIf { it != "main" }.orEmpty(),
|
|
||||||
target.disambiguationClassifier
|
|
||||||
)
|
|
||||||
|
|
||||||
fun linkTaskName(kind: NativeOutputKind, buildType: NativeBuildType): String =
|
fun linkTaskName(kind: NativeOutputKind, buildType: NativeBuildType): String =
|
||||||
lowerCamelCaseName(
|
lowerCamelCaseName(
|
||||||
"link",
|
"link",
|
||||||
|
|||||||
+1
-1
@@ -208,7 +208,7 @@ class KotlinNativeTarget(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override val artifactsTaskName: String
|
override val artifactsTaskName: String
|
||||||
get() = disambiguateName("link")
|
get() = disambiguateName("binaries")
|
||||||
|
|
||||||
override val publishable: Boolean
|
override val publishable: Boolean
|
||||||
get() = konanTarget.enabledOnCurrentHost
|
get() = konanTarget.enabledOnCurrentHost
|
||||||
|
|||||||
Reference in New Issue
Block a user