[gradle-plugin] Re-add an aggregate task to run all executables

This commit is contained in:
Ilya Matveev
2018-05-21 18:46:04 +07:00
committed by ilmat192
parent b0d65642e4
commit 7aa92eaa25
6 changed files with 25 additions and 11 deletions
+4 -4
View File
@@ -259,7 +259,7 @@ See more about multiplatform projects [here](https://kotlinlang.org/docs/referen
The Kotlin/Native plugin creates the following tasks:
* __compileKonan<ArtifactName><Target>__. The plugin creates such a task for each target declared in `konan.targets` list and
* __compileKonan\<ArtifactName>\<Target>__. 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<FileCollection>`|Additional files linked with the stubs |
* __compileKonan<ArtifactName>__. Aggregate task allowing one to build an artifact for several targets. By default it builds
* __compileKonan\<ArtifactName>__. 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<ArtifactName>__. Such a task is created for each executable supported by current host and allows one to run this
* __run\<ArtifactName>__. 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
+1 -1
View File
@@ -155,7 +155,7 @@ def tasksOf(Closure<Task> 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)
+1 -1
View File
@@ -25,7 +25,7 @@ konanArtifacts {
}
}
runTensorflow.dependsOn 'warning'
tasks.findByName("runTensorflow")?.dependsOn 'warning'
task warning {
doLast {
+1 -1
View File
@@ -25,7 +25,7 @@ konanArtifacts {
}
}
runTorch.dependsOn 'warning'
tasks.findByName("runTorch")?.dependsOn 'warning'
task warning {
doLast {
@@ -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)
@@ -50,11 +50,16 @@ class TaskTests {
listOf("src", "bar", "kotlin"),
"main.kt",
"fun main(args: Array<String>) = 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'")
}
}