diff --git a/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/NativeBlackBoxTestSupport.kt b/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/NativeBlackBoxTestSupport.kt index 808ca0707ca..3fb7d63e241 100644 --- a/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/NativeBlackBoxTestSupport.kt +++ b/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/NativeBlackBoxTestSupport.kt @@ -76,8 +76,10 @@ class NativeBlackBoxTestSupport : BeforeEachCallback { val nativeHome = computeNativeHome() val hostManager = HostManager(distribution = Distribution(nativeHome.path), experimental = false) + val nativeTargets = computeNativeTargets(hostManager) + TestProcessSettings( - computeNativeTargets(hostManager), + nativeTargets, nativeHome, computeNativeClassLoader(), computeTestMode(), @@ -85,7 +87,7 @@ class NativeBlackBoxTestSupport : BeforeEachCallback { memoryModel, threadStateChecker, gcType, - CacheKind::class to computeCacheKind(), + CacheKind::class to computeCacheKind(nativeHome, nativeTargets, optimizationMode), computeBaseDirs(), computeTimeouts() ) @@ -127,9 +129,16 @@ class NativeBlackBoxTestSupport : BeforeEachCallback { private fun computeGCType(): GCType = enumSystemProperty(GC_TYPE, GCType.values(), default = GCType.UNSPECIFIED) - private fun computeCacheKind(): CacheKind { + private fun computeCacheKind( + kotlinNativeHome: KotlinNativeHome, + kotlinNativeTargets: KotlinNativeTargets, + optimizationMode: OptimizationMode + ): CacheKind { val useCache = systemProperty(USE_CACHE, String::toBooleanStrictOrNull, default = true) - return if (useCache) CacheKind.WithStaticCache else CacheKind.WithoutCache + return if (useCache) + CacheKind.WithStaticCache(kotlinNativeHome, kotlinNativeTargets, optimizationMode) + else + CacheKind.WithoutCache } private fun computeBaseDirs(): BaseDirs = BaseDirs(File(requiredEnvironmentVariable(PROJECT_BUILD_DIR))) diff --git a/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/TestCompiler.kt b/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/TestCompiler.kt index 461b3b253e4..9b42588f374 100644 --- a/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/TestCompiler.kt +++ b/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/TestCompiler.kt @@ -17,6 +17,7 @@ import org.jetbrains.kotlin.konan.blackboxtest.support.TestCompilationResult.Com import org.jetbrains.kotlin.konan.blackboxtest.support.TestModule.Companion.allDependencies import org.jetbrains.kotlin.konan.blackboxtest.support.TestModule.Companion.allFriends import org.jetbrains.kotlin.konan.blackboxtest.support.settings.* +import org.jetbrains.kotlin.konan.blackboxtest.support.settings.CacheKind.Companion.rootCacheDir import org.jetbrains.kotlin.konan.blackboxtest.support.util.* import org.jetbrains.kotlin.test.services.JUnit5Assertions.fail import java.io.* @@ -71,7 +72,7 @@ internal class TestCompilationFactory { add(testRunnerArg) } } - settings.getRootCacheDirectory()?.let { rootCacheDir -> + settings.get().rootCacheDir?.let { rootCacheDir -> add("-Xcache-directory=$rootCacheDir") } } diff --git a/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/settings/TestProcessSettings.kt b/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/settings/TestProcessSettings.kt index 7358eb6c806..8b01cebc772 100644 --- a/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/settings/TestProcessSettings.kt +++ b/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/settings/TestProcessSettings.kt @@ -103,24 +103,30 @@ internal class Timeouts(val executionTimeout: Duration) internal sealed interface CacheKind { object WithoutCache : CacheKind - object WithStaticCache : CacheKind { - fun getRootCacheDirectory( - kotlinNativeHome: KotlinNativeHome, - kotlinNativeTargets: KotlinNativeTargets, - optimizationMode: OptimizationMode - ): File? = kotlinNativeHome.dir + class WithStaticCache( + kotlinNativeHome: KotlinNativeHome, + kotlinNativeTargets: KotlinNativeTargets, + optimizationMode: OptimizationMode + ) : CacheKind { + val rootCacheDir: File? = kotlinNativeHome.dir .resolve("klib/cache") - .resolve(computeCacheDirName(kotlinNativeTargets.testTarget, CACHE_KIND, optimizationMode == OptimizationMode.DEBUG)) - .takeIf { it.exists() } + .resolve( + computeCacheDirName( + testTarget = kotlinNativeTargets.testTarget, + cacheKind = CACHE_KIND, + debuggable = optimizationMode == OptimizationMode.DEBUG + ) + ).takeIf { it.exists() } - private const val CACHE_KIND = "STATIC" + companion object { + private const val CACHE_KIND = "STATIC" + } } companion object { + val CacheKind.rootCacheDir: File? get() = safeAs()?.rootCacheDir + private fun computeCacheDirName(testTarget: KonanTarget, cacheKind: String, debuggable: Boolean) = "$testTarget${if (debuggable) "-g" else ""}$cacheKind" } } - -internal fun Settings.getRootCacheDirectory(): File? = - get().safeAs()?.getRootCacheDirectory(get(), get(), get())