[gradle-plugin] Provide aggregate assemble tasks
This commit is contained in:
+1
@@ -70,6 +70,7 @@ abstract class AbstractKotlinNativeBinary(
|
|||||||
val sourceSet: KotlinNativeSourceSet
|
val sourceSet: KotlinNativeSourceSet
|
||||||
get() = component.sources
|
get() = component.sources
|
||||||
|
|
||||||
|
val buildType: KotlinNativeBuildType get() = identity.buildType
|
||||||
open val debuggable: Boolean get() = identity.isDebuggable
|
open val debuggable: Boolean get() = identity.isDebuggable
|
||||||
open val optimized: Boolean get() = identity.isOptimized
|
open val optimized: Boolean get() = identity.isOptimized
|
||||||
|
|
||||||
|
|||||||
+18
-19
@@ -7,26 +7,25 @@ import org.gradle.language.cpp.internal.NativeVariantIdentity
|
|||||||
import org.jetbrains.kotlin.konan.target.KonanTarget
|
import org.jetbrains.kotlin.konan.target.KonanTarget
|
||||||
|
|
||||||
open class KotlinNativeVariantIdentity(
|
open class KotlinNativeVariantIdentity(
|
||||||
name: String,
|
name: String,
|
||||||
baseName: Provider<String>,
|
baseName: Provider<String>,
|
||||||
group: Provider<String>,
|
group: Provider<String>,
|
||||||
version: Provider<String>,
|
version: Provider<String>,
|
||||||
val konanTarget: KonanTarget,
|
val konanTarget: KonanTarget,
|
||||||
debuggable: Boolean,
|
val buildType: KotlinNativeBuildType,
|
||||||
optimized: Boolean,
|
linkUsage: UsageContext?,
|
||||||
linkUsage: UsageContext?,
|
runtimeUsage: UsageContext?,
|
||||||
runtimeUsage: UsageContext?,
|
objects: ObjectFactory
|
||||||
objects: ObjectFactory
|
|
||||||
) : NativeVariantIdentity(
|
) : NativeVariantIdentity(
|
||||||
name,
|
name,
|
||||||
baseName,
|
baseName,
|
||||||
group,
|
group,
|
||||||
version,
|
version,
|
||||||
debuggable,
|
buildType.debuggable,
|
||||||
optimized,
|
buildType.optimized,
|
||||||
konanTarget.getGradleOSFamily(objects),
|
konanTarget.getGradleOSFamily(objects),
|
||||||
linkUsage,
|
linkUsage,
|
||||||
runtimeUsage
|
runtimeUsage
|
||||||
) {
|
) {
|
||||||
val targetPlatform = DefaultKotlinNativePlatform(konanTarget)
|
val targetPlatform = DefaultKotlinNativePlatform(konanTarget)
|
||||||
}
|
}
|
||||||
+31
-1
@@ -2,6 +2,7 @@ package org.jetbrains.kotlin.gradle.plugin.experimental.plugins
|
|||||||
|
|
||||||
import org.gradle.api.DefaultTask
|
import org.gradle.api.DefaultTask
|
||||||
import org.gradle.api.Plugin
|
import org.gradle.api.Plugin
|
||||||
|
import org.gradle.api.Task
|
||||||
import org.gradle.api.component.SoftwareComponentContainer
|
import org.gradle.api.component.SoftwareComponentContainer
|
||||||
import org.gradle.api.file.DirectoryProperty
|
import org.gradle.api.file.DirectoryProperty
|
||||||
import org.gradle.api.internal.FeaturePreviews
|
import org.gradle.api.internal.FeaturePreviews
|
||||||
@@ -59,16 +60,28 @@ class KotlinNativeBasePlugin: Plugin<ProjectInternal> {
|
|||||||
private val KonanTarget.canRunOnHost: Boolean
|
private val KonanTarget.canRunOnHost: Boolean
|
||||||
get() = this == HostManager.host
|
get() = this == HostManager.host
|
||||||
|
|
||||||
|
|
||||||
private fun addCompilationTasks(
|
private fun addCompilationTasks(
|
||||||
tasks: TaskContainer,
|
tasks: TaskContainer,
|
||||||
components: SoftwareComponentContainer,
|
components: SoftwareComponentContainer,
|
||||||
buildDirectory: DirectoryProperty,
|
buildDirectory: DirectoryProperty,
|
||||||
providers: ProviderFactory
|
providers: ProviderFactory
|
||||||
) {
|
) {
|
||||||
|
val assembleTask = tasks.getByName(LifecycleBasePlugin.ASSEMBLE_TASK_NAME)
|
||||||
|
val typeToAssemble = mutableMapOf<KotlinNativeBuildType, Task>()
|
||||||
|
val targetToAssemble = mutableMapOf<KonanTarget, Task>()
|
||||||
|
|
||||||
|
fun TaskContainer.createSpecialAssembleTask(name: String, description: String) = create(name) {
|
||||||
|
it.group = BasePlugin.BUILD_GROUP
|
||||||
|
it.description = description
|
||||||
|
assembleTask.dependsOn(it)
|
||||||
|
}
|
||||||
|
|
||||||
components.withType(AbstractKotlinNativeBinary::class.java) { binary ->
|
components.withType(AbstractKotlinNativeBinary::class.java) { binary ->
|
||||||
val names = binary.names
|
val names = binary.names
|
||||||
val target = binary.konanTarget
|
val target = binary.konanTarget
|
||||||
val kind = binary.kind
|
val kind = binary.kind
|
||||||
|
val buildType = binary.buildType
|
||||||
|
|
||||||
val compileTask = tasks.create(
|
val compileTask = tasks.create(
|
||||||
names.getCompileTaskName(LANGUAGE_NAME),
|
names.getCompileTaskName(LANGUAGE_NAME),
|
||||||
@@ -95,6 +108,7 @@ class KotlinNativeBasePlugin: Plugin<ProjectInternal> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (binary is KotlinNativeTestExecutableImpl) {
|
if (binary is KotlinNativeTestExecutableImpl) {
|
||||||
|
// Generate a task for test execution.
|
||||||
val taskName = binary.names.getTaskName("run")
|
val taskName = binary.names.getTaskName("run")
|
||||||
val testTask = if (target.canRunOnHost) {
|
val testTask = if (target.canRunOnHost) {
|
||||||
tasks.createRunTestTask(taskName, binary, compileTask)
|
tasks.createRunTestTask(taskName, binary, compileTask)
|
||||||
@@ -104,6 +118,23 @@ class KotlinNativeBasePlugin: Plugin<ProjectInternal> {
|
|||||||
tasks.createDummyTestTask(taskName, target)
|
tasks.createDummyTestTask(taskName, target)
|
||||||
}
|
}
|
||||||
binary.runTask.set(testTask)
|
binary.runTask.set(testTask)
|
||||||
|
} else {
|
||||||
|
// Add dependency for assemble tasks.
|
||||||
|
targetToAssemble.getOrPut(target) {
|
||||||
|
tasks.createSpecialAssembleTask(
|
||||||
|
"assembleAll${target.name.capitalize()}",
|
||||||
|
"Compiles all Kotlin/Native binaries for target '${target.name}'"
|
||||||
|
)
|
||||||
|
}.dependsOn(compileTask)
|
||||||
|
|
||||||
|
typeToAssemble.getOrPut(buildType) {
|
||||||
|
val buildTypeName = buildType.name
|
||||||
|
tasks.createSpecialAssembleTask(
|
||||||
|
"assembleAll${buildTypeName.capitalize()}",
|
||||||
|
"Compiles all ${buildTypeName} Kotlin/Native binaries for all targets"
|
||||||
|
)
|
||||||
|
}.dependsOn(compileTask)
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -146,7 +177,6 @@ class KotlinNativeBasePlugin: Plugin<ProjectInternal> {
|
|||||||
checkGradleVersion()
|
checkGradleVersion()
|
||||||
addCompilerDownloadingTask()
|
addCompilerDownloadingTask()
|
||||||
|
|
||||||
// Create compile tasks
|
|
||||||
addCompilationTasks(tasks, components, layout.buildDirectory, providers)
|
addCompilationTasks(tasks, components, layout.buildDirectory, providers)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+22
-22
@@ -105,8 +105,7 @@ class KotlinNativePlugin @Inject constructor(val attributesFactory: ImmutableAtt
|
|||||||
variantName,
|
variantName,
|
||||||
component.baseName,
|
component.baseName,
|
||||||
group, version, target,
|
group, version, target,
|
||||||
buildType.debuggable,
|
buildType,
|
||||||
buildType.optimized,
|
|
||||||
linkUsageContext,
|
linkUsageContext,
|
||||||
runtimeUsageContext,
|
runtimeUsageContext,
|
||||||
objects
|
objects
|
||||||
@@ -153,8 +152,7 @@ class KotlinNativePlugin @Inject constructor(val attributesFactory: ImmutableAtt
|
|||||||
variantName,
|
variantName,
|
||||||
component.getBaseName(),
|
component.getBaseName(),
|
||||||
group, version, target,
|
group, version, target,
|
||||||
buildType.debuggable,
|
buildType,
|
||||||
buildType.optimized,
|
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
objects
|
objects
|
||||||
@@ -169,6 +167,25 @@ class KotlinNativePlugin @Inject constructor(val attributesFactory: ImmutableAtt
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun Project.setUpMavenPublish() = pluginManager.withPlugin("maven-publish") {
|
||||||
|
val publishingExtension = project.extensions.getByType(PublishingExtension::class.java)
|
||||||
|
val components = project.components.withType(KotlinNativeMainComponent::class.java)
|
||||||
|
publishingExtension.publications.forEach { publication ->
|
||||||
|
(publication as? MavenPublication)?.apply {
|
||||||
|
val component = components.find {
|
||||||
|
it.name == publication.name
|
||||||
|
|| publication.name.startsWith("${it.name}Release")
|
||||||
|
|| publication.name.startsWith("${it.name}Debug")
|
||||||
|
}
|
||||||
|
component?.let {
|
||||||
|
it.poms.forEach {
|
||||||
|
publication.pom(it)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override fun apply(project: ProjectInternal): Unit = with(project) {
|
override fun apply(project: ProjectInternal): Unit = with(project) {
|
||||||
pluginManager.apply(KotlinNativeBasePlugin::class.java)
|
pluginManager.apply(KotlinNativeBasePlugin::class.java)
|
||||||
pluginManager.apply(NativeTestingBasePlugin::class.java)
|
pluginManager.apply(NativeTestingBasePlugin::class.java)
|
||||||
@@ -214,24 +231,7 @@ class KotlinNativePlugin @Inject constructor(val attributesFactory: ImmutableAtt
|
|||||||
|
|
||||||
addBinariesForMainComponents(group, version)
|
addBinariesForMainComponents(group, version)
|
||||||
addBinariesForTestComponents(group, version)
|
addBinariesForTestComponents(group, version)
|
||||||
pluginManager.withPlugin("maven-publish") {
|
setUpMavenPublish()
|
||||||
val publishingExtension = project.extensions.getByType(PublishingExtension::class.java)
|
|
||||||
val components = project.components.withType(KotlinNativeMainComponent::class.java)
|
|
||||||
publishingExtension.publications.forEach { publication ->
|
|
||||||
(publication as? MavenPublication)?.apply {
|
|
||||||
val component = components.find {
|
|
||||||
it.name == publication.name
|
|
||||||
|| publication.name.startsWith("${it.name}Release")
|
|
||||||
|| publication.name.startsWith("${it.name}Debug")
|
|
||||||
}
|
|
||||||
component?.let {
|
|
||||||
it.poms.forEach {
|
|
||||||
publication.pom(it)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,8 +4,10 @@ import org.gradle.api.Plugin
|
|||||||
import org.gradle.api.Project
|
import org.gradle.api.Project
|
||||||
import org.gradle.api.internal.project.ProjectInternal
|
import org.gradle.api.internal.project.ProjectInternal
|
||||||
import org.gradle.testfixtures.ProjectBuilder
|
import org.gradle.testfixtures.ProjectBuilder
|
||||||
|
import org.gradle.testkit.runner.BuildResult
|
||||||
import org.gradle.testkit.runner.TaskOutcome
|
import org.gradle.testkit.runner.TaskOutcome
|
||||||
import org.jetbrains.kotlin.gradle.plugin.experimental.internal.KotlinNativeMainComponent
|
import org.jetbrains.kotlin.gradle.plugin.experimental.internal.KotlinNativeMainComponent
|
||||||
|
import org.jetbrains.kotlin.gradle.plugin.experimental.internal.OutputKind
|
||||||
import org.jetbrains.kotlin.gradle.plugin.experimental.plugins.KotlinNativePlugin
|
import org.jetbrains.kotlin.gradle.plugin.experimental.plugins.KotlinNativePlugin
|
||||||
import org.jetbrains.kotlin.konan.target.HostManager
|
import org.jetbrains.kotlin.konan.target.HostManager
|
||||||
import org.jetbrains.kotlin.konan.target.KonanTarget
|
import org.jetbrains.kotlin.konan.target.KonanTarget
|
||||||
@@ -411,4 +413,55 @@ class ExperimentalPluginTests {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun assertCompileOutcome(result: BuildResult, compileTasks: Collection<String>, expectedOutcome: TaskOutcome) {
|
||||||
|
compileTasks.forEach { taskName ->
|
||||||
|
val task = result.task(taskName)
|
||||||
|
assertNotNull(task, "Task '$taskName' was not executed") {
|
||||||
|
assertEquals(
|
||||||
|
it.outcome,
|
||||||
|
expectedOutcome,
|
||||||
|
"Task '$taskName' has incorrect outcome. Expected: $expectedOutcome, actual: ${it.outcome}"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `Compilation should be up-to-date if there is no changes`() {
|
||||||
|
val project = KonanProject.create(projectDirectory).apply {
|
||||||
|
buildFile.writeText("""
|
||||||
|
plugins { id 'kotlin-native' }
|
||||||
|
|
||||||
|
sourceSets.main {
|
||||||
|
component {
|
||||||
|
outputKinds = [ EXECUTABLE, KLIBRARY, FRAMEWORK ]
|
||||||
|
target 'host', 'wasm32'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
""".trimIndent())
|
||||||
|
}
|
||||||
|
|
||||||
|
val outputKinds = arrayOf(OutputKind.EXECUTABLE, OutputKind.KLIBRARY, OutputKind.FRAMEWORK)
|
||||||
|
val buildTypes = arrayOf("Debug", "Release")
|
||||||
|
val targets = arrayOf(HostManager.host, KonanTarget.WASM32)
|
||||||
|
|
||||||
|
val compileTasks = targets.flatMap { target ->
|
||||||
|
outputKinds.filter { it.availableFor(target) }.flatMap { kind ->
|
||||||
|
buildTypes.map { type ->
|
||||||
|
":compile${type}${kind.name.toLowerCase().capitalize()}${target.name.capitalize()}KotlinNative"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
val ttt = project.createRunner().withArguments("tasks").build()
|
||||||
|
println(ttt.output)
|
||||||
|
|
||||||
|
val result1 = project.createRunner().withArguments("assemble").build()
|
||||||
|
assertCompileOutcome(result1, compileTasks, TaskOutcome.SUCCESS)
|
||||||
|
|
||||||
|
val result2 = project.createRunner().withArguments("assemble").build()
|
||||||
|
assertCompileOutcome(result2, compileTasks, TaskOutcome.UP_TO_DATE)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user