[K/N][build] Supported per-file caches in K/N tests
This commit is contained in:
@@ -14,17 +14,13 @@ class CacheTesting(val buildCacheTask: Task, val compilerArgs: List<String>, val
|
|||||||
|
|
||||||
fun configureCacheTesting(project: Project): CacheTesting? {
|
fun configureCacheTesting(project: Project): CacheTesting? {
|
||||||
val cacheKindString = project.findProperty("test_with_cache_kind") as String? ?: return null
|
val cacheKindString = project.findProperty("test_with_cache_kind") as String? ?: return null
|
||||||
val isDynamic = when (cacheKindString) {
|
val (cacheKind, makePerFileCache) = when (cacheKindString) {
|
||||||
"dynamic" -> true
|
"dynamic" -> CompilerOutputKind.DYNAMIC_CACHE to false
|
||||||
"static" -> false
|
"static" -> CompilerOutputKind.STATIC_CACHE to false
|
||||||
|
"static_per_file" -> CompilerOutputKind.STATIC_CACHE to true
|
||||||
else -> error(cacheKindString)
|
else -> error(cacheKindString)
|
||||||
}
|
}
|
||||||
|
val isDynamic = cacheKind == CompilerOutputKind.DYNAMIC_CACHE
|
||||||
val cacheKind = if (isDynamic) {
|
|
||||||
CompilerOutputKind.DYNAMIC_CACHE
|
|
||||||
} else {
|
|
||||||
CompilerOutputKind.STATIC_CACHE
|
|
||||||
}
|
|
||||||
|
|
||||||
val target = project.testTarget
|
val target = project.testTarget
|
||||||
val dist = project.kotlinNativeDist
|
val dist = project.kotlinNativeDist
|
||||||
@@ -43,7 +39,7 @@ fun configureCacheTesting(project: Project): CacheTesting? {
|
|||||||
}
|
}
|
||||||
|
|
||||||
val cacheDir = project.file("${project.buildDir}/cache")
|
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 stdlib = "$dist/klib/common/stdlib"
|
||||||
val compilerArgs = listOf("-Xcached-library=$stdlib,$cacheFile")
|
val compilerArgs = listOf("-Xcached-library=$stdlib,$cacheFile")
|
||||||
|
|
||||||
@@ -54,15 +50,18 @@ fun configureCacheTesting(project: Project): CacheTesting? {
|
|||||||
|
|
||||||
dependsOnDist()
|
dependsOnDist()
|
||||||
|
|
||||||
commandLine(
|
val args = mutableListOf(
|
||||||
"$dist/bin/konanc",
|
"$dist/bin/konanc",
|
||||||
"-p", cacheKind.visibleName,
|
"-p", cacheKind.visibleName,
|
||||||
"-o", "$cacheDir/stdlib-cache",
|
"-Xadd-cache=$stdlib", "-Xcache-directory=$cacheDir",
|
||||||
"-Xmake-cache=$stdlib",
|
|
||||||
"-no-default-libs", "-nostdlib",
|
"-no-default-libs", "-nostdlib",
|
||||||
"-target", target,
|
"-target", target,
|
||||||
"-g"
|
"-g"
|
||||||
)
|
)
|
||||||
|
if (makePerFileCache)
|
||||||
|
args.add("-Xmake-per-file-cache")
|
||||||
|
|
||||||
|
commandLine(args)
|
||||||
}
|
}
|
||||||
|
|
||||||
return CacheTesting(buildCacheTask, compilerArgs, isDynamic)
|
return CacheTesting(buildCacheTask, compilerArgs, isDynamic)
|
||||||
|
|||||||
+10
-3
@@ -39,7 +39,7 @@ open class KonanCacheTask: DefaultTask() {
|
|||||||
|
|
||||||
@get:OutputDirectory
|
@get:OutputDirectory
|
||||||
val cacheFile: File
|
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],
|
* Note: we can't use this function instead of [klibUniqName] in [cacheFile],
|
||||||
@@ -59,6 +59,9 @@ open class KonanCacheTask: DefaultTask() {
|
|||||||
@get:Input
|
@get:Input
|
||||||
var cacheKind: KonanCacheKind = KonanCacheKind.STATIC
|
var cacheKind: KonanCacheKind = KonanCacheKind.STATIC
|
||||||
|
|
||||||
|
@get:Input
|
||||||
|
var makePerFileCache: Boolean = false
|
||||||
|
|
||||||
@get:Input
|
@get:Input
|
||||||
/** Path to a compiler distribution that is used to build this cache. */
|
/** Path to a compiler distribution that is used to build this cache. */
|
||||||
val compilerDistributionPath: Property<File> = project.objects.property(File::class.java).apply {
|
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
|
it.targetByName(target).let(it::loader).additionalCacheFlags
|
||||||
}
|
}
|
||||||
requireNotNull(originalKlib)
|
requireNotNull(originalKlib)
|
||||||
val args = listOf(
|
val args = mutableListOf(
|
||||||
"-g",
|
"-g",
|
||||||
"-target", target,
|
"-target", target,
|
||||||
"-produce", cacheKind.outputKind.name.toLowerCase(),
|
"-produce", cacheKind.outputKind.name.toLowerCase(),
|
||||||
"-Xadd-cache=${originalKlib?.absolutePath}",
|
"-Xadd-cache=${originalKlib?.absolutePath}",
|
||||||
"-Xcache-directory=${cacheDirectory.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)
|
KonanCliCompilerRunner(project, konanHome = konanHome).run(args)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user