From d2c8fd18e991635b109fcd05e16888ca36b81b1d Mon Sep 17 00:00:00 2001 From: Ilya Matveev Date: Thu, 24 Aug 2017 11:20:12 +0700 Subject: [PATCH] gradle-plugin: Allow passing additional command line options --- GRADLE_PLUGIN.md | 41 ++++++++++++++- .../kotlin/gradle/plugin/KonanCompileTask.kt | 50 ++++--------------- .../kotlin/gradle/plugin/KonanInteropTask.kt | 29 ++++------- .../test/IncrementalSpecification.groovy | 2 + 4 files changed, 61 insertions(+), 61 deletions(-) diff --git a/GRADLE_PLUGIN.md b/GRADLE_PLUGIN.md index 723dc7f2f31..467f645d207 100644 --- a/GRADLE_PLUGIN.md +++ b/GRADLE_PLUGIN.md @@ -93,7 +93,38 @@ You also can use an interop from another project: } } -### Tasks +## Additional options + +You can also pass additional command line keys to the compiler or cinterop tool using the `extraOpts` expression +available an artifact or interop block. For example this sample enables a verbose output for a link and bitcode +generation stages and prints execution time for all compiler phases: + + konanArtifacts + foo { + extraOpts '--verbose', 'linker', '--verbose', 'bitcode', '--time' + } + } + +Any command line key supported by the according tool (compiler or cinterop) can be used. Some of them are listed in the +tables below. + +##### Compiler additional options +|Key |Description | +|-------------------|-----------------------------------------| +|`--disable `|Disable backend phase | +|`--enable `|Enable backend phase | +|`--list_phases `|List all backend phases | +|`--time `|Report execution time for compiler phases| +|`--verbose `|Trace phase execution | +|`-verbose `|Enable verbose logging output | + +##### Cinterop additional options +|Key |Description | +|--------------------|----------------------------------------------------| +|`-verbose `|Increase verbosity | +|`-shims ` |Add generation of shims tracing native library calls| + +## Tasks The Kotlin/Native plugin creates the following tasks: @@ -173,7 +204,7 @@ The plugin also edits the default `build` and `clean` tasks so that the first on supported (it's dependent on the `compileKonan` task) and the second one removes the files created by the Kotlin/Native build. -#### Task graph +### Task graph A task dependency structure is simple. Consider a following project: @@ -244,6 +275,9 @@ For this project the task graph will be the following: // Add the `anotherTask` to the compilation task dependencies. dependsOn anotherTask + + // Pass additional command line options to the compiler. + extraOpts '--time', '--verbose', 'linker' } } @@ -266,5 +300,8 @@ For this project the task graph will be the following: // Add the `anotherTask` to the stub generation task dependencies. dependsOn anotherTask + + // Pass additional command line options to the cinterop tool. + extraOpts '-shims', 'true' } } diff --git a/tools/kotlin-native-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/plugin/KonanCompileTask.kt b/tools/kotlin-native-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/plugin/KonanCompileTask.kt index 388795f74a6..2bf0a0930cd 100644 --- a/tools/kotlin-native-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/plugin/KonanCompileTask.kt +++ b/tools/kotlin-native-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/plugin/KonanCompileTask.kt @@ -25,47 +25,8 @@ import org.gradle.api.tasks.* import java.io.File /** - * We can the following: - * - * konanArtifacts { - * - * artifactName1 { - * - * inputFiles "files" "to" "be" "compiled" - * - * outputDir "path/to/output/dir" - * - * library "path/to/library" - * library File("Library") - * - * nativeLibrary "path/to/library" - * nativeLibrary File("Library") - * - * noStdLib - * produce "library"|"program"|"bitcode" - * enableOptimization - * - * linkerOpts "linker" "args" - * target "target" - * - * languageVersion "version" - * apiVersion "version" - * - * } - * - * artifactName2 { - * - * extends artifactName1 - * - * inputDir "someDir" - * outputDir "someDir" - * } - * - * } + * A task compiling the target executable/library using Kotlin/Native compiler */ - - -// TODO: Make the task class nested for config with properties accessible for outer users. open class KonanCompileTask: KonanTargetableTask() { companion object { @@ -115,6 +76,8 @@ open class KonanCompileTask: KonanTargetableTask() { @Internal val interops = mutableSetOf() + @Input val extraOpts = mutableListOf() + internal var _linkerOpts = mutableListOf() val linkerOpts: List @Input get() = mutableListOf().apply { @@ -168,6 +131,8 @@ open class KonanCompileTask: KonanTargetableTask() { addKey("-opt", enableOptimization) addKey("-ea", enableAssertions) + addAll(extraOpts) + inputFiles.flatMap { it.files }.filter { it.name.endsWith(".kt") }.mapTo(this) { it.canonicalPath } } @@ -326,4 +291,9 @@ open class KonanCompileConfig( } fun dependsOn(dependency: Any) = compilationTask.dependsOn(dependency) + + fun extraOpts(vararg values: Any) = extraOpts(values.asList()) + fun extraOpts(values: List) { + values.mapTo(compilationTask.extraOpts) { it.toString() } + } } diff --git a/tools/kotlin-native-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/plugin/KonanInteropTask.kt b/tools/kotlin-native-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/plugin/KonanInteropTask.kt index 03a7f0771dd..357a50ddad9 100644 --- a/tools/kotlin-native-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/plugin/KonanInteropTask.kt +++ b/tools/kotlin-native-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/plugin/KonanInteropTask.kt @@ -25,25 +25,8 @@ import org.gradle.api.tasks.* import java.io.File /** - * What we can: - * - * konanInterop { - * pkgName { - * defFile - * pkg - * target - * compilerOpts - * linkerOpts - * headers - * includeDirs - * linkFiles - * dumpParameters