diff --git a/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/NativeTestSupport.kt b/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/NativeTestSupport.kt index bf63feba5e6..6d319ca8e21 100644 --- a/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/NativeTestSupport.kt +++ b/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/NativeTestSupport.kt @@ -156,11 +156,23 @@ private object NativeTestSupport { kotlinNativeTargets: KotlinNativeTargets, optimizationMode: OptimizationMode ): CacheKind { - val useCache = systemProperty(USE_CACHE, String::toBooleanStrictOrNull, default = true) - return if (useCache) - CacheKind.WithStaticCache(kotlinNativeHome, kotlinNativeTargets, optimizationMode) - else - CacheKind.WithoutCache + // Compatibility stuff (initially, the property was boolean): + val legacyUseCache = System.getProperty(USE_CACHE)?.let(String::toBooleanStrictOrNull) + if (legacyUseCache != null) { + return if (legacyUseCache) + CacheKind.WithStaticCache(kotlinNativeHome, kotlinNativeTargets, optimizationMode, false) + else + CacheKind.WithoutCache + } + + val staticCacheRequiredForEveryLibrary = + when (enumSystemProperty(USE_CACHE, CacheKind.Alias.values(), default = CacheKind.Alias.ONLY_DIST)) { + CacheKind.Alias.NO -> return CacheKind.WithoutCache + CacheKind.Alias.ONLY_DIST -> false + CacheKind.Alias.EVERYWHERE -> true + } + + return CacheKind.WithStaticCache(kotlinNativeHome, kotlinNativeTargets, optimizationMode, staticCacheRequiredForEveryLibrary) } private fun computeBaseDirs(): BaseDirs { diff --git a/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/compilation/TestCompilation.kt b/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/compilation/TestCompilation.kt index cd9a79cecf9..943fbdbf95a 100644 --- a/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/compilation/TestCompilation.kt +++ b/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/compilation/TestCompilation.kt @@ -11,13 +11,11 @@ import org.jetbrains.kotlin.konan.blackboxtest.support.TestCase.* import org.jetbrains.kotlin.konan.blackboxtest.support.compilation.TestCompilationArtifact.* import org.jetbrains.kotlin.konan.blackboxtest.support.compilation.TestCompilationDependencyType.* import org.jetbrains.kotlin.konan.blackboxtest.support.settings.* -import org.jetbrains.kotlin.konan.blackboxtest.support.settings.CacheKind.WithStaticCache import org.jetbrains.kotlin.konan.blackboxtest.support.util.ArgsBuilder import org.jetbrains.kotlin.konan.blackboxtest.support.util.buildArgs import org.jetbrains.kotlin.konan.blackboxtest.support.util.flatMapToSet import org.jetbrains.kotlin.konan.properties.resolvablePropertyList import org.jetbrains.kotlin.test.services.JUnit5Assertions.fail -import org.jetbrains.kotlin.utils.addToStdlib.safeAs import java.io.File internal abstract class TestCompilation { @@ -248,7 +246,7 @@ internal class ExecutableCompilation( override fun applyDependencies(argsBuilder: ArgsBuilder): Unit = with(argsBuilder) { super.applyDependencies(argsBuilder) - cacheKind.safeAs()?.rootCacheDir?.let { rootCacheDir -> add("-Xcache-directory=$rootCacheDir") } + cacheKind.staticCacheRootDir?.let { cacheRootDir -> add("-Xcache-directory=$cacheRootDir") } add(dependencies.cachedLibraries) { (libraryCacheDir, _) -> "-Xcache-directory=${libraryCacheDir.path}" } } } @@ -270,12 +268,9 @@ internal class StaticCacheCompilation( private val cacheDir = expectedArtifact.file - private val rootCacheDir: File = run { + private val cacheRootDir: File = run { val cacheKind = settings.get() - val staticCacheKind = cacheKind as? WithStaticCache ?: fail { - "${WithStaticCache::class.java} is expected as the current cache kind in ${StaticCacheCompilation::class.java}, found: $cacheKind" - } - staticCacheKind.rootCacheDir ?: fail { "No root cache directory found" } + cacheKind.staticCacheRootDir ?: fail { "No cache root directory found for cache kind $cacheKind" } } override fun doBeforeCompile() { @@ -290,7 +285,7 @@ internal class StaticCacheCompilation( add( "-Xadd-cache=${dependencies.libraryToCache.path}", "-Xcache-directory=${cacheDir.path}", - "-Xcache-directory=$rootCacheDir" + "-Xcache-directory=$cacheRootDir" ) } @@ -307,9 +302,8 @@ internal class StaticCacheCompilation( private val Iterable>.libraryToCache: KLIB get() { val libraries = collectArtifacts>() - return libraries.singleOrNull() ?: fail { - "Only one library is expected as input for ${StaticCacheCompilation::class.java}, found: $libraries" - } + return libraries.singleOrNull() + ?: fail { "Only one library is expected as input for ${StaticCacheCompilation::class.java}, found: $libraries" } } } } diff --git a/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/compilation/TestCompilationFactory.kt b/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/compilation/TestCompilationFactory.kt index dd520a9cbc3..5c19b3875cc 100644 --- a/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/compilation/TestCompilationFactory.kt +++ b/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/compilation/TestCompilationFactory.kt @@ -15,7 +15,6 @@ import org.jetbrains.kotlin.konan.blackboxtest.support.compilation.TestCompilati import org.jetbrains.kotlin.konan.blackboxtest.support.compilation.TestCompilationDependencyType.* import org.jetbrains.kotlin.konan.blackboxtest.support.settings.Binaries import org.jetbrains.kotlin.konan.blackboxtest.support.settings.CacheKind -import org.jetbrains.kotlin.konan.blackboxtest.support.settings.CacheKind.WithStaticCache import org.jetbrains.kotlin.konan.blackboxtest.support.settings.KotlinNativeTargets import org.jetbrains.kotlin.konan.blackboxtest.support.settings.Settings import org.jetbrains.kotlin.konan.blackboxtest.support.util.* @@ -78,7 +77,7 @@ internal class TestCompilationFactory { val dependencies = collectDependencies(sourceModules, freeCompilerArgs, settings) val klibArtifact = KLIB(settings.artifactFileForKlib(sourceModule, freeCompilerArgs)) - val staticCacheArtifact: KLIBStaticCache? = if (settings.get() is WithStaticCache) + val staticCacheArtifact: KLIBStaticCache? = if (settings.get().staticCacheRequiredForEveryLibrary) KLIBStaticCache(file = klibArtifact.artifactFileForStaticCache(), klib = klibArtifact) else null // No artifact means no static cache should be compiled. 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 e89a0dd3db7..b54f141c195 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 @@ -106,14 +106,21 @@ internal class Timeouts(val executionTimeout: Duration) * Used cache kind. */ internal sealed interface CacheKind { - object WithoutCache : CacheKind + val staticCacheRootDir: File? + val staticCacheRequiredForEveryLibrary: Boolean + + object WithoutCache : CacheKind { + override val staticCacheRootDir: File? get() = null + override val staticCacheRequiredForEveryLibrary get() = false + } class WithStaticCache( kotlinNativeHome: KotlinNativeHome, kotlinNativeTargets: KotlinNativeTargets, - optimizationMode: OptimizationMode + optimizationMode: OptimizationMode, + override val staticCacheRequiredForEveryLibrary: Boolean ) : CacheKind { - val rootCacheDir: File? = kotlinNativeHome.dir + override val staticCacheRootDir: File? = kotlinNativeHome.dir .resolve("klib/cache") .resolve( computeCacheDirName( @@ -128,6 +135,8 @@ internal sealed interface CacheKind { } } + enum class Alias { NO, ONLY_DIST, EVERYWHERE } + companion object { private fun computeCacheDirName(testTarget: KonanTarget, cacheKind: String, debuggable: Boolean) = "$testTarget${if (debuggable) "-g" else ""}$cacheKind"