From 7aa92eaa2594ff27e891088b4e2ebf8416239791 Mon Sep 17 00:00:00 2001 From: Ilya Matveev Date: Mon, 21 May 2018 18:46:04 +0700 Subject: [PATCH] [gradle-plugin] Re-add an aggregate task to run all executables --- GRADLE_PLUGIN.md | 8 ++++---- backend.native/tests/build.gradle | 2 +- samples/tensorflow/build.gradle | 2 +- samples/torch/build.gradle | 2 +- .../org/jetbrains/kotlin/gradle/plugin/KonanPlugin.kt | 11 ++++++++++- .../src/test/kotlin/TaskTests.kt | 11 ++++++++--- 6 files changed, 25 insertions(+), 11 deletions(-) diff --git a/GRADLE_PLUGIN.md b/GRADLE_PLUGIN.md index a8fff86115b..ecb6b184a60 100644 --- a/GRADLE_PLUGIN.md +++ b/GRADLE_PLUGIN.md @@ -259,7 +259,7 @@ See more about multiplatform projects [here](https://kotlinlang.org/docs/referen The Kotlin/Native plugin creates the following tasks: -* __compileKonan__. The plugin creates such a task for each target declared in `konan.targets` list and +* __compileKonan\\__. The plugin creates such a task for each target declared in `konan.targets` list and for each an artifact defined in a `konanArtifacts` block. Such a task may have different properties depending on the artifact type: ##### Properties available for a compiler task (executable, library or bitcode building task): @@ -298,7 +298,7 @@ for each an artifact defined in a `konanArtifacts` block. Such a task may have d |`linkFiles `|`Collection`|Additional files linked with the stubs | -* __compileKonan__. Aggregate task allowing one to build an artifact for several targets. By default it builds +* __compileKonan\__. Aggregate task allowing one to build an artifact for several targets. By default it builds the artifact for all supported targets declared for the project. One may change this behavior by specifying the space-separated target list in `konan.build.targets` project property: @@ -311,13 +311,13 @@ target list in `konan.build.targets` project property: * __compileKonan__. Aggregate task to build all the Kotlin/Native artifacts for all available targets. `konan.build.targets` project property also may be used to override the target list. The task has no properties to use by a build script. -* __run__. Such a task is created for each executable supported by current host and allows one to run this +* __run\__. Such a task is created for each executable supported by current host and allows one to run this executable. The task is an instance of Gradle's [`Exec`](https://docs.gradle.org/current/dsl/org.gradle.api.tasks.Exec.html) so it supports all settings provided by `Exec`. Additionally, run parameters may be passed to the task using the `runArgs` project property: ``` - ./gradlew run -PrunArgs='foo bar' + ./gradlew runFoo -PrunArgs='foo bar' ``` The plugin also edits the default `build` and `clean` tasks so that the first one allows one to build all the artifacts supported diff --git a/backend.native/tests/build.gradle b/backend.native/tests/build.gradle index 810b3188b5d..91049b27b14 100644 --- a/backend.native/tests/build.gradle +++ b/backend.native/tests/build.gradle @@ -155,7 +155,7 @@ def tasksOf(Closure filter) { .matching { filter(it) && it.enabled && (prefix != null ? it.name.startsWith(prefix) : true) } } -task run { +run { def tasks = tasksOf { it instanceof KonanTest && it.inDevelopersRun } dependsOn(tasks) diff --git a/samples/tensorflow/build.gradle b/samples/tensorflow/build.gradle index 213c98484bc..3eca29c23ee 100644 --- a/samples/tensorflow/build.gradle +++ b/samples/tensorflow/build.gradle @@ -25,7 +25,7 @@ konanArtifacts { } } -runTensorflow.dependsOn 'warning' +tasks.findByName("runTensorflow")?.dependsOn 'warning' task warning { doLast { diff --git a/samples/torch/build.gradle b/samples/torch/build.gradle index a0e4ec1e271..34b929e696a 100644 --- a/samples/torch/build.gradle +++ b/samples/torch/build.gradle @@ -25,7 +25,7 @@ konanArtifacts { } } -runTorch.dependsOn 'warning' +tasks.findByName("runTorch")?.dependsOn 'warning' task warning { doLast { diff --git a/tools/kotlin-native-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/plugin/KonanPlugin.kt b/tools/kotlin-native-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/plugin/KonanPlugin.kt index 53237a6603c..ee125812c24 100644 --- a/tools/kotlin-native-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/plugin/KonanPlugin.kt +++ b/tools/kotlin-native-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/plugin/KonanPlugin.kt @@ -341,7 +341,16 @@ class KonanPlugin @Inject constructor(private val registry: ToolingModelBuilderR doLast { project.cleanKonan() } } - //project.gradle.experimentalFeatures.enable() + val runTask = project.getOrCreateTask("run") + project.afterEvaluate { + project.konanArtifactsContainer + .filterIsInstance(KonanProgram::class.java) + .forEach { program -> + program.forEach { compile -> + compile.runTask?.let { runTask.dependsOn(it) } + } + } + } // Enable multiplatform support project.pluginManager.apply(KotlinNativePlatformPlugin::class.java) diff --git a/tools/kotlin-native-gradle-plugin/src/test/kotlin/TaskTests.kt b/tools/kotlin-native-gradle-plugin/src/test/kotlin/TaskTests.kt index f671bf7c8b4..c4814278ca1 100644 --- a/tools/kotlin-native-gradle-plugin/src/test/kotlin/TaskTests.kt +++ b/tools/kotlin-native-gradle-plugin/src/test/kotlin/TaskTests.kt @@ -50,11 +50,16 @@ class TaskTests { listOf("src", "bar", "kotlin"), "main.kt", "fun main(args: Array) = println(\"Run Bar: \${args[0]}, \${args[1]}\")") - val result = project.createRunner() + val resultFoo = project.createRunner() .withArguments("runFoo", "-PrunArgs=arg1 arg2") .build() + val resultAll = project.createRunner() + .withArguments("run", "-PrunArgs=arg1 arg2") + .build() - assertTrue(result.output.contains("Run Foo: arg1, arg2"), "No Foo output!") - assertTrue(!result.output.contains("Run Bar: "), "There is Bar output!") + assertTrue(resultFoo.output.contains("Run Foo: arg1, arg2"), "No Foo output for 'runFoo'") + assertFalse(resultFoo.output.contains("Run Bar: "), "There is Bar output for 'runFoo'") + assertTrue(resultAll.output.contains("Run Foo: arg1, arg2"), "No Foo output for 'run'") + assertTrue(resultAll.output.contains("Run Bar: arg1, arg2"), "No Bar output for 'run'") } } \ No newline at end of file