gradle-plugin: Allow passing additional command line options
This commit is contained in:
+39
-2
@@ -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 <Phase>`|Disable backend phase |
|
||||
|`--enable <Phase> `|Enable backend phase |
|
||||
|`--list_phases `|List all backend phases |
|
||||
|`--time `|Report execution time for compiler phases|
|
||||
|`--verbose <Phase>`|Trace phase execution |
|
||||
|`-verbose `|Enable verbose logging output |
|
||||
|
||||
##### Cinterop additional options
|
||||
|Key |Description |
|
||||
|--------------------|----------------------------------------------------|
|
||||
|`-verbose <boolean>`|Increase verbosity |
|
||||
|`-shims <boolean>` |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'
|
||||
}
|
||||
}
|
||||
|
||||
+10
-40
@@ -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<KonanInteropConfig>()
|
||||
|
||||
@Input val extraOpts = mutableListOf<String>()
|
||||
|
||||
internal var _linkerOpts = mutableListOf<String>()
|
||||
val linkerOpts: List<String>
|
||||
@Input get() = mutableListOf<String>().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<Any>) {
|
||||
values.mapTo(compilationTask.extraOpts) { it.toString() }
|
||||
}
|
||||
}
|
||||
|
||||
+10
-19
@@ -25,25 +25,8 @@ import org.gradle.api.tasks.*
|
||||
import java.io.File
|
||||
|
||||
/**
|
||||
* What we can:
|
||||
*
|
||||
* konanInterop {
|
||||
* pkgName {
|
||||
* defFile <def-file>
|
||||
* pkg <package with stubs>
|
||||
* target <target: linux/macbook/iphone/iphone_sim>
|
||||
* compilerOpts <Options for native stubs compilation>
|
||||
* linkerOpts <Options for native stubs >
|
||||
* headers <headers to process>
|
||||
* includeDirs <directories where headers are located>
|
||||
* linkFiles <files which will be linked with native stubs>
|
||||
* dumpParameters <Option to print parameters of task before execution>
|
||||
* }
|
||||
*
|
||||
* // TODO: add configuration for konan compiler
|
||||
* }
|
||||
* A task executing cinterop tool with the given args and compiling the stubs produced by this tool.
|
||||
*/
|
||||
|
||||
open class KonanInteropTask: KonanTargetableTask() {
|
||||
|
||||
internal companion object {
|
||||
@@ -86,6 +69,7 @@ open class KonanInteropTask: KonanTargetableTask() {
|
||||
@Input var dumpParameters: Boolean = false
|
||||
@Input val compilerOpts = mutableListOf<String>()
|
||||
@Input val linkerOpts = mutableListOf<String>()
|
||||
@Input val extraOpts = mutableListOf<String>()
|
||||
|
||||
// TODO: Check if we can use only one FileCollection instead of set.
|
||||
@InputFiles val headers = mutableSetOf<FileCollection>()
|
||||
@@ -122,7 +106,7 @@ open class KonanInteropTask: KonanTargetableTask() {
|
||||
manifest ?.let {addArg("-manifest", it)}
|
||||
|
||||
addArgIfNotNull("-target", target)
|
||||
addArgIfNotNull("-def", defFile?.canonicalPath)
|
||||
addArgIfNotNull("-def", defFile.canonicalPath)
|
||||
addArg("-pkg", pkg ?: libName)
|
||||
|
||||
addFileArgs("-h", headers)
|
||||
@@ -138,6 +122,8 @@ open class KonanInteropTask: KonanTargetableTask() {
|
||||
linkerOpts.forEach {
|
||||
addArg("-lopt", it)
|
||||
}
|
||||
|
||||
addAll(extraOpts)
|
||||
}
|
||||
|
||||
}
|
||||
@@ -222,5 +208,10 @@ open class KonanInteropConfig(
|
||||
}
|
||||
|
||||
fun dependsOn(dependency: Any) = generateStubsTask.dependsOn(dependency)
|
||||
|
||||
fun extraOpts(vararg values: Any) = extraOpts(values.asList())
|
||||
fun extraOpts(values: List<Any>) {
|
||||
values.mapTo(generateStubsTask.extraOpts) { it.toString() }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+2
@@ -113,6 +113,7 @@ class IncrementalSpecification extends BaseKonanSpecification {
|
||||
"enableAssertions" | "()"
|
||||
"enableDebug" | "true"
|
||||
"outputName" | "'foo'"
|
||||
"extraOpts" | "'--time'"
|
||||
}
|
||||
|
||||
def 'inputFiles change for a compilation task should cause only recompilation'() {
|
||||
@@ -220,6 +221,7 @@ class IncrementalSpecification extends BaseKonanSpecification {
|
||||
"compilerOpts" | "'-g'"
|
||||
"linkerOpts" | "'--help'"
|
||||
"includeDirs" | "'src'"
|
||||
"extraOpts" | "'-shims', 'false'"
|
||||
}
|
||||
|
||||
def 'defFile change for an interop task should cause recompilation and interop reprocessing'() {
|
||||
|
||||
Reference in New Issue
Block a user