[Native][tests] Simplify CacheKind.WithStaticCache setting
This commit is contained in:
+13
-4
@@ -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)))
|
||||
|
||||
+2
-1
@@ -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<CacheKind>().rootCacheDir?.let { rootCacheDir ->
|
||||
add("-Xcache-directory=$rootCacheDir")
|
||||
}
|
||||
}
|
||||
|
||||
+18
-12
@@ -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<WithStaticCache>()?.rootCacheDir
|
||||
|
||||
private fun computeCacheDirName(testTarget: KonanTarget, cacheKind: String, debuggable: Boolean) =
|
||||
"$testTarget${if (debuggable) "-g" else ""}$cacheKind"
|
||||
}
|
||||
}
|
||||
|
||||
internal fun Settings.getRootCacheDirectory(): File? =
|
||||
get<CacheKind>().safeAs<CacheKind.WithStaticCache>()?.getRootCacheDirectory(get(), get(), get())
|
||||
|
||||
Reference in New Issue
Block a user