[Native][tests] Simplify CacheKind.WithStaticCache setting
This commit is contained in:
+13
-4
@@ -76,8 +76,10 @@ class NativeBlackBoxTestSupport : BeforeEachCallback {
|
|||||||
val nativeHome = computeNativeHome()
|
val nativeHome = computeNativeHome()
|
||||||
val hostManager = HostManager(distribution = Distribution(nativeHome.path), experimental = false)
|
val hostManager = HostManager(distribution = Distribution(nativeHome.path), experimental = false)
|
||||||
|
|
||||||
|
val nativeTargets = computeNativeTargets(hostManager)
|
||||||
|
|
||||||
TestProcessSettings(
|
TestProcessSettings(
|
||||||
computeNativeTargets(hostManager),
|
nativeTargets,
|
||||||
nativeHome,
|
nativeHome,
|
||||||
computeNativeClassLoader(),
|
computeNativeClassLoader(),
|
||||||
computeTestMode(),
|
computeTestMode(),
|
||||||
@@ -85,7 +87,7 @@ class NativeBlackBoxTestSupport : BeforeEachCallback {
|
|||||||
memoryModel,
|
memoryModel,
|
||||||
threadStateChecker,
|
threadStateChecker,
|
||||||
gcType,
|
gcType,
|
||||||
CacheKind::class to computeCacheKind(),
|
CacheKind::class to computeCacheKind(nativeHome, nativeTargets, optimizationMode),
|
||||||
computeBaseDirs(),
|
computeBaseDirs(),
|
||||||
computeTimeouts()
|
computeTimeouts()
|
||||||
)
|
)
|
||||||
@@ -127,9 +129,16 @@ class NativeBlackBoxTestSupport : BeforeEachCallback {
|
|||||||
|
|
||||||
private fun computeGCType(): GCType = enumSystemProperty(GC_TYPE, GCType.values(), default = GCType.UNSPECIFIED)
|
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)
|
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)))
|
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.allDependencies
|
||||||
import org.jetbrains.kotlin.konan.blackboxtest.support.TestModule.Companion.allFriends
|
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.*
|
||||||
|
import org.jetbrains.kotlin.konan.blackboxtest.support.settings.CacheKind.Companion.rootCacheDir
|
||||||
import org.jetbrains.kotlin.konan.blackboxtest.support.util.*
|
import org.jetbrains.kotlin.konan.blackboxtest.support.util.*
|
||||||
import org.jetbrains.kotlin.test.services.JUnit5Assertions.fail
|
import org.jetbrains.kotlin.test.services.JUnit5Assertions.fail
|
||||||
import java.io.*
|
import java.io.*
|
||||||
@@ -71,7 +72,7 @@ internal class TestCompilationFactory {
|
|||||||
add(testRunnerArg)
|
add(testRunnerArg)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
settings.getRootCacheDirectory()?.let { rootCacheDir ->
|
settings.get<CacheKind>().rootCacheDir?.let { rootCacheDir ->
|
||||||
add("-Xcache-directory=$rootCacheDir")
|
add("-Xcache-directory=$rootCacheDir")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+18
-12
@@ -103,24 +103,30 @@ internal class Timeouts(val executionTimeout: Duration)
|
|||||||
internal sealed interface CacheKind {
|
internal sealed interface CacheKind {
|
||||||
object WithoutCache : CacheKind
|
object WithoutCache : CacheKind
|
||||||
|
|
||||||
object WithStaticCache : CacheKind {
|
class WithStaticCache(
|
||||||
fun getRootCacheDirectory(
|
kotlinNativeHome: KotlinNativeHome,
|
||||||
kotlinNativeHome: KotlinNativeHome,
|
kotlinNativeTargets: KotlinNativeTargets,
|
||||||
kotlinNativeTargets: KotlinNativeTargets,
|
optimizationMode: OptimizationMode
|
||||||
optimizationMode: OptimizationMode
|
) : CacheKind {
|
||||||
): File? = kotlinNativeHome.dir
|
val rootCacheDir: File? = kotlinNativeHome.dir
|
||||||
.resolve("klib/cache")
|
.resolve("klib/cache")
|
||||||
.resolve(computeCacheDirName(kotlinNativeTargets.testTarget, CACHE_KIND, optimizationMode == OptimizationMode.DEBUG))
|
.resolve(
|
||||||
.takeIf { it.exists() }
|
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 {
|
companion object {
|
||||||
|
val CacheKind.rootCacheDir: File? get() = safeAs<WithStaticCache>()?.rootCacheDir
|
||||||
|
|
||||||
private fun computeCacheDirName(testTarget: KonanTarget, cacheKind: String, debuggable: Boolean) =
|
private fun computeCacheDirName(testTarget: KonanTarget, cacheKind: String, debuggable: Boolean) =
|
||||||
"$testTarget${if (debuggable) "-g" else ""}$cacheKind"
|
"$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