diff --git a/kotlin-native/build-tools/src/main/kotlin/org/jetbrains/kotlin/CacheTesting.kt b/kotlin-native/build-tools/src/main/kotlin/org/jetbrains/kotlin/CacheTesting.kt index 04f6a12bc22..80684ba4d7c 100644 --- a/kotlin-native/build-tools/src/main/kotlin/org/jetbrains/kotlin/CacheTesting.kt +++ b/kotlin-native/build-tools/src/main/kotlin/org/jetbrains/kotlin/CacheTesting.kt @@ -14,17 +14,13 @@ class CacheTesting(val buildCacheTask: Task, val compilerArgs: List, val fun configureCacheTesting(project: Project): CacheTesting? { val cacheKindString = project.findProperty("test_with_cache_kind") as String? ?: return null - val isDynamic = when (cacheKindString) { - "dynamic" -> true - "static" -> false + val (cacheKind, makePerFileCache) = when (cacheKindString) { + "dynamic" -> CompilerOutputKind.DYNAMIC_CACHE to false + "static" -> CompilerOutputKind.STATIC_CACHE to false + "static_per_file" -> CompilerOutputKind.STATIC_CACHE to true else -> error(cacheKindString) } - - val cacheKind = if (isDynamic) { - CompilerOutputKind.DYNAMIC_CACHE - } else { - CompilerOutputKind.STATIC_CACHE - } + val isDynamic = cacheKind == CompilerOutputKind.DYNAMIC_CACHE val target = project.testTarget val dist = project.kotlinNativeDist @@ -43,7 +39,7 @@ fun configureCacheTesting(project: Project): CacheTesting? { } val cacheDir = project.file("${project.buildDir}/cache") - val cacheFile = "$cacheDir/stdlib-cache" + val cacheFile = "$cacheDir/stdlib${if (makePerFileCache) "-per-file" else ""}-cache" val stdlib = "$dist/klib/common/stdlib" val compilerArgs = listOf("-Xcached-library=$stdlib,$cacheFile") @@ -54,15 +50,18 @@ fun configureCacheTesting(project: Project): CacheTesting? { dependsOnDist() - commandLine( + val args = mutableListOf( "$dist/bin/konanc", "-p", cacheKind.visibleName, - "-o", "$cacheDir/stdlib-cache", - "-Xmake-cache=$stdlib", + "-Xadd-cache=$stdlib", "-Xcache-directory=$cacheDir", "-no-default-libs", "-nostdlib", "-target", target, "-g" ) + if (makePerFileCache) + args.add("-Xmake-per-file-cache") + + commandLine(args) } return CacheTesting(buildCacheTask, compilerArgs, isDynamic) diff --git a/kotlin-native/tools/kotlin-native-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/plugin/konan/tasks/KonanCacheTask.kt b/kotlin-native/tools/kotlin-native-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/plugin/konan/tasks/KonanCacheTask.kt index 7a766123066..0793b77d9a0 100644 --- a/kotlin-native/tools/kotlin-native-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/plugin/konan/tasks/KonanCacheTask.kt +++ b/kotlin-native/tools/kotlin-native-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/plugin/konan/tasks/KonanCacheTask.kt @@ -39,7 +39,7 @@ open class KonanCacheTask: DefaultTask() { @get:OutputDirectory val cacheFile: File - get() = cacheDirectory.resolve("${klibUniqName}-cache") + get() = cacheDirectory.resolve(if (makePerFileCache) "${klibUniqName}-per-file-cache" else "${klibUniqName}-cache") /** * Note: we can't use this function instead of [klibUniqName] in [cacheFile], @@ -59,6 +59,9 @@ open class KonanCacheTask: DefaultTask() { @get:Input var cacheKind: KonanCacheKind = KonanCacheKind.STATIC + @get:Input + var makePerFileCache: Boolean = false + @get:Input /** Path to a compiler distribution that is used to build this cache. */ val compilerDistributionPath: Property = project.objects.property(File::class.java).apply { @@ -85,13 +88,17 @@ open class KonanCacheTask: DefaultTask() { it.targetByName(target).let(it::loader).additionalCacheFlags } requireNotNull(originalKlib) - val args = listOf( + val args = mutableListOf( "-g", "-target", target, "-produce", cacheKind.outputKind.name.toLowerCase(), "-Xadd-cache=${originalKlib?.absolutePath}", "-Xcache-directory=${cacheDirectory.absolutePath}" - ) + additionalCacheFlags + cachedLibraries.map { "-Xcached-library=${it.key},${it.value}" } + ) + if (makePerFileCache) + args += "-Xmake-per-file-cache" + args += additionalCacheFlags + args += cachedLibraries.map { "-Xcached-library=${it.key},${it.value}" } KonanCliCompilerRunner(project, konanHome = konanHome).run(args) } } \ No newline at end of file