From bb2cf38617ce8079b9831679087e4a25239a8798 Mon Sep 17 00:00:00 2001 From: Vyacheslav Gerasimov Date: Mon, 3 Feb 2020 19:37:05 +0300 Subject: [PATCH] Build: Make :kotlin-stdlib-js-ir buildKLib tasks cacheable --- libraries/stdlib/js-ir/build.gradle.kts | 48 ++++++++++++++++--------- 1 file changed, 32 insertions(+), 16 deletions(-) diff --git a/libraries/stdlib/js-ir/build.gradle.kts b/libraries/stdlib/js-ir/build.gradle.kts index dc8c6a4d383..6a86210cc8b 100644 --- a/libraries/stdlib/js-ir/build.gradle.kts +++ b/libraries/stdlib/js-ir/build.gradle.kts @@ -167,13 +167,29 @@ val reducedRuntimeSources by task { into("$buildDir/reducedRuntime/src") } -fun JavaExec.buildKLib(moduleName: String, sources: List, dependencies: List, outPath: String, commonSources: List) { +fun JavaExec.buildKLib( + moduleName: String, + sources: List, + dependencies: List, + outDir: File, + commonSources: List +) { + + fun File.pathRelativeToWorkingDir(): String = absoluteFile.relativeTo(workingDir).path + inputs.files(sources) - outputs.dir(file(outPath).parent) + .withPathSensitivity(PathSensitivity.RELATIVE) + + outputs.dir(file(outDir)) + outputs.cacheIf { true } + classpath = jsIrKlibCli main = "org.jetbrains.kotlin.ir.backend.js.GenerateJsIrKlibKt" workingDir = rootDir - args = sources.toList() + listOf("-n", moduleName, "-o", outPath) + dependencies.flatMap { listOf("-d", it) } + commonSources.flatMap { listOf("-c", it) } + args = sources.map { it.pathRelativeToWorkingDir() } + + listOf("-n", moduleName, "-o", outDir.pathRelativeToWorkingDir()) + + dependencies.flatMap { listOf("-d", it.pathRelativeToWorkingDir()) } + + commonSources.flatMap { listOf("-c", it.pathRelativeToWorkingDir()) } dependsOn(":compiler:cli-js-klib:jar") passClasspathInJar() @@ -185,10 +201,10 @@ val generateFullRuntimeKLib by eagerTask { dependsOn(fullRuntimeSources) buildKLib(moduleName = "kotlin", - sources = listOf(fullRuntimeSources.get().outputs.files.singleFile.path), + sources = listOf(fullRuntimeSources.get().outputs.files.singleFile), dependencies = emptyList(), - outPath = fullRuntimeDir.absolutePath, - commonSources = listOf("common", "src", "unsigned").map { "$buildDir/fullRuntime/src/libraries/stdlib/$it" } + outDir = fullRuntimeDir, + commonSources = listOf("common", "src", "unsigned").map { file("$buildDir/fullRuntime/src/libraries/stdlib/$it") } ) } @@ -202,20 +218,19 @@ val packFullRuntimeKLib by tasks.registering(Jar::class) { val generateReducedRuntimeKLib by eagerTask { dependsOn(reducedRuntimeSources) - val outPath = buildDir.resolve("reducedRuntime/klib").absolutePath buildKLib(moduleName = "kotlin", - sources = listOf(reducedRuntimeSources.get().outputs.files.singleFile.path), + sources = listOf(reducedRuntimeSources.get().outputs.files.singleFile), dependencies = emptyList(), - outPath = outPath, - commonSources = listOf("common", "src", "unsigned").map { "$buildDir/reducedRuntime/src/libraries/stdlib/$it" } + outDir = buildDir.resolve("reducedRuntime/klib"), + commonSources = listOf("common", "src", "unsigned").map { file("$buildDir/reducedRuntime/src/libraries/stdlib/$it") } ) } val generateWasmRuntimeKLib by eagerTask { buildKLib(moduleName = "kotlin", - sources = listOf("$rootDir/libraries/stdlib/wasm"), + sources = listOf(file("$rootDir/libraries/stdlib/wasm")), dependencies = emptyList(), - outPath = "$buildDir/wasmRuntime/klib", + outDir = file("$buildDir/wasmRuntime/klib"), commonSources = emptyList() ) } @@ -224,15 +239,16 @@ val kotlinTestCommonSources = listOf( "$rootDir/libraries/kotlin.test/annotations-common/src/main", "$rootDir/libraries/kotlin.test/common/src/main" ) + val generateKotlinTestKLib by eagerTask { dependsOn(generateFullRuntimeKLib) buildKLib( moduleName = "kotlin-test", - sources = listOf("$rootDir/libraries/kotlin.test/js/src/main") + kotlinTestCommonSources, - dependencies = listOf("${generateFullRuntimeKLib.outputs.files.singleFile.path}/klib"), - outPath = "$buildDir/kotlin.test/klib", - commonSources = kotlinTestCommonSources + sources = (listOf("$rootDir/libraries/kotlin.test/js/src/main") + kotlinTestCommonSources).map(::file), + dependencies = listOf(generateFullRuntimeKLib.outputs.files.singleFile), + outDir = file("$buildDir/kotlin.test/klib"), + commonSources = kotlinTestCommonSources.map(::file) ) }