@@ -18,6 +18,7 @@ import org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsIrTarget
1818import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsEnvSpec
1919import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsPlugin
2020import org.jetbrains.kotlin.gradle.targets.js.yarn.YarnRootExtension
21+ import org.jetbrains.kotlin.gradle.targets.js.ir.*
2122
2223buildscript {
2324 repositories {
@@ -239,16 +240,23 @@ val unzipJsShell = tasks.register("jsShellUnzip", Copy::class) {
239240 into(unpackedDir)
240241}
241242
242- fun tryGetBinary (compilation : KotlinJsCompilation , mode : KotlinJsBinaryMode ): JsIrBinary ? =
243- (compilation.target as ? KotlinJsIrTarget )
244- ?.binaries
245- ?.executable(compilation)
246- ?.first { it.mode == mode }
243+ fun Project.getExecutableFile (compilation : KotlinJsIrCompilation , mode : KotlinJsBinaryMode ): Provider <RegularFile > {
244+ val kotlinTarget = compilation.target as KotlinJsIrTarget
245+ val binary = kotlinTarget.binaries.executable(compilation)
246+ .first { it.mode == mode } as JsIrBinary
247+ val extension = if (kotlinTarget.platformType == KotlinPlatformType .wasm) " mjs" else " js"
248+ val outputFileName = binary.linkTask.flatMap { task ->
249+ task.compilerOptions.moduleName.map { " $it .$extension " }
250+ }
251+ val destinationDir = binary.linkSyncTask.flatMap { it.destinationDirectory }
252+ val executableFile = destinationDir.zip(outputFileName) { dir, fileName -> dir.resolve(fileName) }
253+ return project.layout.file(executableFile)
254+ }
247255
248256fun Project.createJsShellExec (
249257 config : BenchmarkConfiguration ,
250258 target : BenchmarkTarget ,
251- compilation : KotlinJsCompilation ,
259+ compilation : KotlinJsIrCompilation ,
252260 taskName : String ,
253261 mode : KotlinJsBinaryMode ,
254262 fileNamePostfix : String ,
@@ -262,12 +270,10 @@ fun Project.createJsShellExec(
262270 val newArgs = mutableListOf<String >()
263271 executable = File (unzipJsShell.get().destinationDir, " js" ).absolutePath
264272
265- val productionBinary = tryGetBinary (compilation, mode) ? : error(" Not found production binary" )
266- dependsOn(productionBinary.linkSyncTask )
273+ val productionBinary = getExecutableFile (compilation, mode) ? : error(" Not found production binary" )
274+ dependsOn(productionBinary)
267275
268- val inputFile = productionBinary.mainFile
269- dependsOn(inputFile)
270- val inputFileAsFile = inputFile.get().asFile
276+ val inputFileAsFile = productionBinary.get().asFile
271277 workingDir = inputFileAsFile.parentFile
272278 if (compilation.target.platformType == KotlinPlatformType .wasm) {
273279 newArgs.add(" --module=${inputFileAsFile.absolutePath} " )
@@ -285,7 +291,7 @@ fun Project.createJsShellExec(
285291fun Project.createJsEngineBenchmarkExecTask (
286292 config : BenchmarkConfiguration ,
287293 target : BenchmarkTarget ,
288- compilation : KotlinJsCompilation ,
294+ compilation : KotlinJsIrCompilation ,
289295 mode : KotlinJsBinaryMode ,
290296) {
291297 val postfix = if (mode == KotlinJsBinaryMode .DEVELOPMENT ) " " else " Opt"
@@ -307,7 +313,7 @@ afterEvaluate {
307313 }
308314 if (compilation != null ) {
309315 target.extension.configurations.forEach { config ->
310- val benchmarkCompilation = compilation.target.compilations.maybeCreate(target.name + BenchmarksPlugin .BENCHMARK_COMPILATION_SUFFIX ) as KotlinJsCompilation
316+ val benchmarkCompilation = compilation.target.compilations.maybeCreate(target.name + BenchmarksPlugin .BENCHMARK_COMPILATION_SUFFIX ) as KotlinJsIrCompilation
311317 createJsEngineBenchmarkExecTask(config, target, benchmarkCompilation, KotlinJsBinaryMode .PRODUCTION )
312318 createJsEngineBenchmarkExecTask(config, target, benchmarkCompilation, KotlinJsBinaryMode .DEVELOPMENT )
313319 }
0 commit comments