diff --git a/buildSrc/plugins/src/main/kotlin/org/jetbrains/kotlin/benchmark/CompileBenchmarkingPlugin.kt b/buildSrc/plugins/src/main/kotlin/org/jetbrains/kotlin/benchmark/CompileBenchmarkingPlugin.kt index 492fc3c8ae5..bd10b9481bb 100644 --- a/buildSrc/plugins/src/main/kotlin/org/jetbrains/kotlin/benchmark/CompileBenchmarkingPlugin.kt +++ b/buildSrc/plugins/src/main/kotlin/org/jetbrains/kotlin/benchmark/CompileBenchmarkingPlugin.kt @@ -1,18 +1,37 @@ package org.jetbrains.kotlin.benchmark -import org.gradle.api.Plugin -import org.gradle.api.Project +import groovy.lang.Closure +import org.gradle.api.* import org.gradle.api.tasks.Delete import org.gradle.api.tasks.Exec +import org.gradle.util.ConfigureUtil import org.jetbrains.kotlin.* import javax.inject.Inject -private typealias CommandList = List +class BuildStep (private val _name: String): Named { + override fun getName(): String = _name + lateinit var command: List + + fun command(vararg command: String) { + this.command = command.toList() + } +} + +class BuildStepContainer(project: Project): NamedDomainObjectContainer by project.container(BuildStep::class.java) { + fun step(name: String, configure: Action) = + maybeCreate(name).apply { configure.execute(this) } + + fun step(name: String, configure: Closure) = + step(name, ConfigureUtil.configureUsing(configure)) +} open class CompileBenchmarkExtension @Inject constructor(val project: Project) { var applicationName = project.name var repeatNumber: Int = 1 - var buildSteps: Map = emptyMap() + var buildSteps: BuildStepContainer = BuildStepContainer(project) + + fun buildSteps(configure: Action): Unit = buildSteps.let { configure.execute(it) } + fun buildSteps(configure: Closure): Unit = buildSteps(ConfigureUtil.configureUsing(configure)) } open class CompileBenchmarkingPlugin : Plugin { @@ -43,9 +62,10 @@ open class CompileBenchmarkingPlugin : Plugin { // Compile tasks. afterEvaluate { for (number in 1..repeatNumber) { - buildSteps.forEach { (taskName, command) -> + buildSteps.forEach { step -> + val taskName = step.name tasks.create("$taskName$number", Exec::class.java).apply { - commandLine(command) + commandLine(step.command) isIgnoreExitValue = true konanRun.dependsOn(this) doLast { @@ -65,7 +85,7 @@ open class CompileBenchmarkingPlugin : Plugin { doLast { val nativeCompileTime = getCompileBenchmarkTime( applicationName, - buildSteps.keys, + buildSteps.names, repeatNumber, exitCodes ) diff --git a/performance/helloworld/build.gradle.kts b/performance/helloworld/build.gradle.kts index f3739120976..7eb395f9b70 100644 --- a/performance/helloworld/build.gradle.kts +++ b/performance/helloworld/build.gradle.kts @@ -16,7 +16,9 @@ val binarySuffix = getNativeProgramExtension() compileBenchmark { applicationName = "HelloWorld" repeatNumber = 10 - buildSteps = mapOf( - "runKonanc" to listOf("$dist/bin/konanc$toolSuffix", "$projectDir/src/main/kotlin/main.kt", "-o", "$buildDir/program$binarySuffix") - ) + buildSteps { + step("runKonanc") { + command("$dist/bin/konanc$toolSuffix", "$projectDir/src/main/kotlin/main.kt", "-o", "$buildDir/program$binarySuffix") + } + } } diff --git a/performance/videoplayer/build.gradle.kts b/performance/videoplayer/build.gradle.kts index 8a373327b69..8c505f97de4 100644 --- a/performance/videoplayer/build.gradle.kts +++ b/performance/videoplayer/build.gradle.kts @@ -50,24 +50,31 @@ var includeDirsSdl = when { compileBenchmark { applicationName = "Videoplayer" repeatNumber = 10 - buildSteps = mapOf( - "runCinteropFfmpeg" to listOf("$dist/bin/cinterop$toolSuffix", - "-o", "$dist/../samples/videoplayer/build/classes/kotlin/videoPlayer/main/videoplayer-cinterop-ffmpeg.klib", - "-def", "$dist/../samples/videoplayer/src/nativeInterop/cinterop/ffmpeg.def" - ) + filterDirsFfmpeg + includeDirsFfmpeg, - - "runCinteropSdl" to listOf("$dist/bin/cinterop$toolSuffix", - "-o", "$dist/../samples/videoplayer/build/classes/kotlin/videoPlayer/main/videoplayer-cinterop-sdl.klib", - "-def", "$dist/../samples/videoplayer/src/nativeInterop/cinterop/sdl.def" - ) + includeDirsSdl, - - "runKonanProgram" to listOf("$dist/bin/konanc$toolSuffix", - "-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 - ) + buildSteps { + step("runCinteropFfmpeg") { + command = listOf( + "$dist/bin/cinterop$toolSuffix", + "-o", "$dist/../samples/videoplayer/build/classes/kotlin/videoPlayer/main/videoplayer-cinterop-ffmpeg.klib", + "-def", "$dist/../samples/videoplayer/src/nativeInterop/cinterop/ffmpeg.def" + ) + filterDirsFfmpeg + includeDirsFfmpeg + } + step("runCinteropSdl") { + command = listOf( + "$dist/bin/cinterop$toolSuffix", + "-o", "$dist/../samples/videoplayer/build/classes/kotlin/videoPlayer/main/videoplayer-cinterop-sdl.klib", + "-def", "$dist/../samples/videoplayer/src/nativeInterop/cinterop/sdl.def" + ) + includeDirsSdl + } + step("runKonanProgram") { + command = listOf( + "$dist/bin/konanc$toolSuffix", + "-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 + } + } }