[Native][tests] Support three modes for KLIB caches
^KT-50775
This commit is contained in:
+17
-5
@@ -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 {
|
||||
|
||||
+6
-12
@@ -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<A : TestCompilationArtifact> {
|
||||
@@ -248,7 +246,7 @@ internal class ExecutableCompilation(
|
||||
|
||||
override fun applyDependencies(argsBuilder: ArgsBuilder): Unit = with(argsBuilder) {
|
||||
super.applyDependencies(argsBuilder)
|
||||
cacheKind.safeAs<WithStaticCache>()?.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<CacheKind>()
|
||||
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<TestCompilationDependency<*>>.libraryToCache: KLIB
|
||||
get() {
|
||||
val libraries = collectArtifacts<KLIB, TestCompilationDependencyType<KLIB>>()
|
||||
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" }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
-2
@@ -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<CacheKind>() is WithStaticCache)
|
||||
val staticCacheArtifact: KLIBStaticCache? = if (settings.get<CacheKind>().staticCacheRequiredForEveryLibrary)
|
||||
KLIBStaticCache(file = klibArtifact.artifactFileForStaticCache(), klib = klibArtifact)
|
||||
else
|
||||
null // No artifact means no static cache should be compiled.
|
||||
|
||||
+12
-3
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user