[K/N][build] Supported per-file caches in K/N tests

This commit is contained in:
Igor Chevdar
2022-04-11 15:17:02 +05:00
committed by Space
parent 030e3b306f
commit 228141aeea
2 changed files with 22 additions and 16 deletions
@@ -14,17 +14,13 @@ class CacheTesting(val buildCacheTask: Task, val compilerArgs: List<String>, val
fun configureCacheTesting(project: Project): CacheTesting? {
val cacheKindString = project.findProperty("test_with_cache_kind") as String? ?: return null
val isDynamic = when (cacheKindString) {
"dynamic" -> true
"static" -> false
val (cacheKind, makePerFileCache) = when (cacheKindString) {
"dynamic" -> CompilerOutputKind.DYNAMIC_CACHE to false
"static" -> CompilerOutputKind.STATIC_CACHE to false
"static_per_file" -> CompilerOutputKind.STATIC_CACHE to true
else -> error(cacheKindString)
}
val cacheKind = if (isDynamic) {
CompilerOutputKind.DYNAMIC_CACHE
} else {
CompilerOutputKind.STATIC_CACHE
}
val isDynamic = cacheKind == CompilerOutputKind.DYNAMIC_CACHE
val target = project.testTarget
val dist = project.kotlinNativeDist
@@ -43,7 +39,7 @@ fun configureCacheTesting(project: Project): CacheTesting? {
}
val cacheDir = project.file("${project.buildDir}/cache")
val cacheFile = "$cacheDir/stdlib-cache"
val cacheFile = "$cacheDir/stdlib${if (makePerFileCache) "-per-file" else ""}-cache"
val stdlib = "$dist/klib/common/stdlib"
val compilerArgs = listOf("-Xcached-library=$stdlib,$cacheFile")
@@ -54,15 +50,18 @@ fun configureCacheTesting(project: Project): CacheTesting? {
dependsOnDist()
commandLine(
val args = mutableListOf(
"$dist/bin/konanc",
"-p", cacheKind.visibleName,
"-o", "$cacheDir/stdlib-cache",
"-Xmake-cache=$stdlib",
"-Xadd-cache=$stdlib", "-Xcache-directory=$cacheDir",
"-no-default-libs", "-nostdlib",
"-target", target,
"-g"
)
if (makePerFileCache)
args.add("-Xmake-per-file-cache")
commandLine(args)
}
return CacheTesting(buildCacheTask, compilerArgs, isDynamic)
@@ -39,7 +39,7 @@ open class KonanCacheTask: DefaultTask() {
@get:OutputDirectory
val cacheFile: File
get() = cacheDirectory.resolve("${klibUniqName}-cache")
get() = cacheDirectory.resolve(if (makePerFileCache) "${klibUniqName}-per-file-cache" else "${klibUniqName}-cache")
/**
* Note: we can't use this function instead of [klibUniqName] in [cacheFile],
@@ -59,6 +59,9 @@ open class KonanCacheTask: DefaultTask() {
@get:Input
var cacheKind: KonanCacheKind = KonanCacheKind.STATIC
@get:Input
var makePerFileCache: Boolean = false
@get:Input
/** Path to a compiler distribution that is used to build this cache. */
val compilerDistributionPath: Property<File> = project.objects.property(File::class.java).apply {
@@ -85,13 +88,17 @@ open class KonanCacheTask: DefaultTask() {
it.targetByName(target).let(it::loader).additionalCacheFlags
}
requireNotNull(originalKlib)
val args = listOf(
val args = mutableListOf(
"-g",
"-target", target,
"-produce", cacheKind.outputKind.name.toLowerCase(),
"-Xadd-cache=${originalKlib?.absolutePath}",
"-Xcache-directory=${cacheDirectory.absolutePath}"
) + additionalCacheFlags + cachedLibraries.map { "-Xcached-library=${it.key},${it.value}" }
)
if (makePerFileCache)
args += "-Xmake-per-file-cache"
args += additionalCacheFlags
args += cachedLibraries.map { "-Xcached-library=${it.key},${it.value}" }
KonanCliCompilerRunner(project, konanHome = konanHome).run(args)
}
}