From 9e802904059c526ae7c84a2f3233b38a90f429b6 Mon Sep 17 00:00:00 2001 From: Pavel Punegov Date: Mon, 28 Nov 2022 11:21:15 +0000 Subject: [PATCH] [K/N][test] Fix cache testing to use stdlib cache Cache testing should use standard stdlib cache instead of building it. The dependency is set to the stdlib cache task (part of dist build). Merge-request: KT-MR-7830 Merged-by: Pavel Punegov --- .../org/jetbrains/kotlin/CacheTesting.kt | 51 +++++-------------- 1 file changed, 12 insertions(+), 39 deletions(-) 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 80684ba4d7c..926c62ca9c2 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 @@ -2,15 +2,14 @@ package org.jetbrains.kotlin import org.gradle.api.Project import org.gradle.api.Task -import org.gradle.api.tasks.Exec +import org.gradle.api.tasks.TaskProvider import org.jetbrains.kotlin.konan.properties.resolvablePropertyList import org.jetbrains.kotlin.konan.target.CompilerOutputKind import org.jetbrains.kotlin.konan.target.Distribution import org.jetbrains.kotlin.konan.target.HostManager import org.jetbrains.kotlin.konan.target.KonanTarget -import org.jetbrains.kotlin.konan.util.visibleName -class CacheTesting(val buildCacheTask: Task, val compilerArgs: List, val isDynamic: Boolean) +class CacheTesting(val buildCacheTask: TaskProvider, val compilerArgs: List, val isDynamic: Boolean) fun configureCacheTesting(project: Project): CacheTesting? { val cacheKindString = project.findProperty("test_with_cache_kind") as String? ?: return null @@ -20,51 +19,25 @@ fun configureCacheTesting(project: Project): CacheTesting? { "static_per_file" -> CompilerOutputKind.STATIC_CACHE to true else -> error(cacheKindString) } - val isDynamic = cacheKind == CompilerOutputKind.DYNAMIC_CACHE val target = project.testTarget - val dist = project.kotlinNativeDist - - val cacheableTargets = Distribution(dist.absolutePath).properties + val distribution = Distribution(project.kotlinNativeDist.absolutePath) + val cacheableTargets = distribution.properties .resolvablePropertyList("cacheableTargets", HostManager.hostName) .map { KonanTarget.predefinedTargets.getValue(it) } .toSet() check(target in cacheableTargets) { - """ - No cache support for test target $target at host target ${HostManager.host}. - $STDLIB_BUILD_CACHE_TASK_NAME Gradle task can't be created. - """.trimIndent() - + "No cache support for test target $target at host target ${HostManager.host}" } - val cacheDir = project.file("${project.buildDir}/cache") + val cacheDir = "${distribution.klib}/cache/$target-gSTATIC" val cacheFile = "$cacheDir/stdlib${if (makePerFileCache) "-per-file" else ""}-cache" - val stdlib = "$dist/klib/common/stdlib" - val compilerArgs = listOf("-Xcached-library=$stdlib,$cacheFile") + val stdlib = distribution.stdlib - val buildCacheTask = project.tasks.create(STDLIB_BUILD_CACHE_TASK_NAME, Exec::class.java) { - doFirst { - cacheDir.mkdirs() - } - - dependsOnDist() - - val args = mutableListOf( - "$dist/bin/konanc", - "-p", cacheKind.visibleName, - "-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) + return CacheTesting( + buildCacheTask = project.project(":kotlin-native").tasks.named("${target}StdlibCache"), + compilerArgs = listOf("-Xcached-library=$stdlib,$cacheFile"), + isDynamic = cacheKind == CompilerOutputKind.DYNAMIC_CACHE + ) } - -private const val STDLIB_BUILD_CACHE_TASK_NAME = "buildStdlibCache"