Benchmarks: Add DSL for build steps
This commit is contained in:
committed by
Ilya Matveev
parent
31d9874c5b
commit
b2fbe5d721
+27
-7
@@ -1,18 +1,37 @@
|
|||||||
package org.jetbrains.kotlin.benchmark
|
package org.jetbrains.kotlin.benchmark
|
||||||
|
|
||||||
import org.gradle.api.Plugin
|
import groovy.lang.Closure
|
||||||
import org.gradle.api.Project
|
import org.gradle.api.*
|
||||||
import org.gradle.api.tasks.Delete
|
import org.gradle.api.tasks.Delete
|
||||||
import org.gradle.api.tasks.Exec
|
import org.gradle.api.tasks.Exec
|
||||||
|
import org.gradle.util.ConfigureUtil
|
||||||
import org.jetbrains.kotlin.*
|
import org.jetbrains.kotlin.*
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
private typealias CommandList = List<String>
|
class BuildStep (private val _name: String): Named {
|
||||||
|
override fun getName(): String = _name
|
||||||
|
lateinit var command: List<String>
|
||||||
|
|
||||||
|
fun command(vararg command: String) {
|
||||||
|
this.command = command.toList()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class BuildStepContainer(project: Project): NamedDomainObjectContainer<BuildStep> by project.container(BuildStep::class.java) {
|
||||||
|
fun step(name: String, configure: Action<BuildStep>) =
|
||||||
|
maybeCreate(name).apply { configure.execute(this) }
|
||||||
|
|
||||||
|
fun step(name: String, configure: Closure<Unit>) =
|
||||||
|
step(name, ConfigureUtil.configureUsing(configure))
|
||||||
|
}
|
||||||
|
|
||||||
open class CompileBenchmarkExtension @Inject constructor(val project: Project) {
|
open class CompileBenchmarkExtension @Inject constructor(val project: Project) {
|
||||||
var applicationName = project.name
|
var applicationName = project.name
|
||||||
var repeatNumber: Int = 1
|
var repeatNumber: Int = 1
|
||||||
var buildSteps: Map<String, CommandList> = emptyMap()
|
var buildSteps: BuildStepContainer = BuildStepContainer(project)
|
||||||
|
|
||||||
|
fun buildSteps(configure: Action<BuildStepContainer>): Unit = buildSteps.let { configure.execute(it) }
|
||||||
|
fun buildSteps(configure: Closure<Unit>): Unit = buildSteps(ConfigureUtil.configureUsing(configure))
|
||||||
}
|
}
|
||||||
|
|
||||||
open class CompileBenchmarkingPlugin : Plugin<Project> {
|
open class CompileBenchmarkingPlugin : Plugin<Project> {
|
||||||
@@ -43,9 +62,10 @@ open class CompileBenchmarkingPlugin : Plugin<Project> {
|
|||||||
// Compile tasks.
|
// Compile tasks.
|
||||||
afterEvaluate {
|
afterEvaluate {
|
||||||
for (number in 1..repeatNumber) {
|
for (number in 1..repeatNumber) {
|
||||||
buildSteps.forEach { (taskName, command) ->
|
buildSteps.forEach { step ->
|
||||||
|
val taskName = step.name
|
||||||
tasks.create("$taskName$number", Exec::class.java).apply {
|
tasks.create("$taskName$number", Exec::class.java).apply {
|
||||||
commandLine(command)
|
commandLine(step.command)
|
||||||
isIgnoreExitValue = true
|
isIgnoreExitValue = true
|
||||||
konanRun.dependsOn(this)
|
konanRun.dependsOn(this)
|
||||||
doLast {
|
doLast {
|
||||||
@@ -65,7 +85,7 @@ open class CompileBenchmarkingPlugin : Plugin<Project> {
|
|||||||
doLast {
|
doLast {
|
||||||
val nativeCompileTime = getCompileBenchmarkTime(
|
val nativeCompileTime = getCompileBenchmarkTime(
|
||||||
applicationName,
|
applicationName,
|
||||||
buildSteps.keys,
|
buildSteps.names,
|
||||||
repeatNumber,
|
repeatNumber,
|
||||||
exitCodes
|
exitCodes
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -16,7 +16,9 @@ val binarySuffix = getNativeProgramExtension()
|
|||||||
compileBenchmark {
|
compileBenchmark {
|
||||||
applicationName = "HelloWorld"
|
applicationName = "HelloWorld"
|
||||||
repeatNumber = 10
|
repeatNumber = 10
|
||||||
buildSteps = mapOf(
|
buildSteps {
|
||||||
"runKonanc" to listOf("$dist/bin/konanc$toolSuffix", "$projectDir/src/main/kotlin/main.kt", "-o", "$buildDir/program$binarySuffix")
|
step("runKonanc") {
|
||||||
)
|
command("$dist/bin/konanc$toolSuffix", "$projectDir/src/main/kotlin/main.kt", "-o", "$buildDir/program$binarySuffix")
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -50,24 +50,31 @@ var includeDirsSdl = when {
|
|||||||
compileBenchmark {
|
compileBenchmark {
|
||||||
applicationName = "Videoplayer"
|
applicationName = "Videoplayer"
|
||||||
repeatNumber = 10
|
repeatNumber = 10
|
||||||
buildSteps = mapOf(
|
buildSteps {
|
||||||
"runCinteropFfmpeg" to listOf("$dist/bin/cinterop$toolSuffix",
|
step("runCinteropFfmpeg") {
|
||||||
"-o", "$dist/../samples/videoplayer/build/classes/kotlin/videoPlayer/main/videoplayer-cinterop-ffmpeg.klib",
|
command = listOf(
|
||||||
"-def", "$dist/../samples/videoplayer/src/nativeInterop/cinterop/ffmpeg.def"
|
"$dist/bin/cinterop$toolSuffix",
|
||||||
) + filterDirsFfmpeg + includeDirsFfmpeg,
|
"-o", "$dist/../samples/videoplayer/build/classes/kotlin/videoPlayer/main/videoplayer-cinterop-ffmpeg.klib",
|
||||||
|
"-def", "$dist/../samples/videoplayer/src/nativeInterop/cinterop/ffmpeg.def"
|
||||||
"runCinteropSdl" to listOf("$dist/bin/cinterop$toolSuffix",
|
) + filterDirsFfmpeg + includeDirsFfmpeg
|
||||||
"-o", "$dist/../samples/videoplayer/build/classes/kotlin/videoPlayer/main/videoplayer-cinterop-sdl.klib",
|
}
|
||||||
"-def", "$dist/../samples/videoplayer/src/nativeInterop/cinterop/sdl.def"
|
step("runCinteropSdl") {
|
||||||
) + includeDirsSdl,
|
command = listOf(
|
||||||
|
"$dist/bin/cinterop$toolSuffix",
|
||||||
"runKonanProgram" to listOf("$dist/bin/konanc$toolSuffix",
|
"-o", "$dist/../samples/videoplayer/build/classes/kotlin/videoPlayer/main/videoplayer-cinterop-sdl.klib",
|
||||||
"-ea", "-p", "program",
|
"-def", "$dist/../samples/videoplayer/src/nativeInterop/cinterop/sdl.def"
|
||||||
"-o", "${buildDir.absolutePath}/program$binarySuffix",
|
) + includeDirsSdl
|
||||||
"-l", "$dist/../samples/videoplayer/build/classes/kotlin/videoPlayer/main/videoplayer-cinterop-ffmpeg.klib",
|
}
|
||||||
"-l", "$dist/../samples/videoplayer/build/classes/kotlin/videoPlayer/main/videoplayer-cinterop-sdl.klib",
|
step("runKonanProgram") {
|
||||||
"-Xmulti-platform", "$dist/../samples/videoplayer/src/videoPlayerMain/kotlin",
|
command = listOf(
|
||||||
"-entry", "sample.videoplayer.main"
|
"$dist/bin/konanc$toolSuffix",
|
||||||
) + linkerOpts
|
"-ea", "-p", "program",
|
||||||
)
|
"-o", "${buildDir.absolutePath}/program$binarySuffix",
|
||||||
|
"-l", "$dist/../samples/videoplayer/build/classes/kotlin/videoPlayer/main/videoplayer-cinterop-ffmpeg.klib",
|
||||||
|
"-l", "$dist/../samples/videoplayer/build/classes/kotlin/videoPlayer/main/videoplayer-cinterop-sdl.klib",
|
||||||
|
"-Xmulti-platform", "$dist/../samples/videoplayer/src/videoPlayerMain/kotlin",
|
||||||
|
"-entry", "sample.videoplayer.main"
|
||||||
|
) + linkerOpts
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user