[K/N][tests] Fixed CachesAutoBuildTest & IncrementalCompilationTest

In auto-cache mode, the compiler itself chooses the system cache directory,
and it is important to not pass it explicitly.
This commit is contained in:
Igor Chevdar
2023-08-03 18:26:34 +03:00
committed by Space Team
parent 3b626ea97c
commit 2f463f740f
4 changed files with 17 additions and 7 deletions
@@ -83,6 +83,7 @@ class CachesAutoBuildTest : AbstractNativeSimpleTest() {
autoCacheDir.mkdirs()
return compileToExecutable(
sourcesDir,
tryPassSystemCacheDirectory = false, // With auto-cache mode, the compiler chooses the system cache directory itself.
freeCompilerArgs = TestCompilerArgs(
listOf(
"-Xauto-cache-from=${autoCacheFrom.absolutePath}",
@@ -502,7 +502,7 @@ class IncrementalCompilationTest : AbstractNativeSimpleTest() {
targetSrc: String,
vararg dependencies: TestCompilationArtifact.KLIB,
block: ExecutableBuilder.() -> Unit
) = with(ExecutableBuilder(this@IncrementalCompilationTest, rootDir, targetSrc, dependencies.asList())) {
) = with(ExecutableBuilder(this@IncrementalCompilationTest, rootDir, targetSrc, false, dependencies.asList())) {
externalLibsDir.mkdirs()
icCacheDir.mkdirs()
autoCacheDir.mkdirs()
@@ -81,6 +81,7 @@ internal class ExecutableBuilder(
test: AbstractNativeSimpleTest,
rootDir: File,
targetSrc: String,
val tryPassSystemCacheDirectory: Boolean,
dependencies: List<TestCompilationArtifact.KLIB>
) : ArtifactBuilder<CompiledExecutable>(test, rootDir, targetSrc, dependencies) {
private val freeCompilerArgs = mutableListOf<String>()
@@ -92,6 +93,7 @@ internal class ExecutableBuilder(
override fun build(sourcesDir: File, outputDir: File, dependencies: List<TestCompilationArtifact.KLIB>) =
test.compileToExecutable(
sourcesDir,
tryPassSystemCacheDirectory,
freeCompilerArgs = if (freeCompilerArgs.isEmpty()) TestCompilerArgs.EMPTY else TestCompilerArgs(freeCompilerArgs),
dependencies
)
@@ -159,22 +161,24 @@ internal class CompiledExecutable(
internal fun AbstractNativeSimpleTest.compileToExecutable(
sourcesDir: File,
tryPassSystemCacheDirectory: Boolean,
freeCompilerArgs: TestCompilerArgs,
vararg dependencies: TestCompilationArtifact.KLIB
) = compileToExecutable(sourcesDir, freeCompilerArgs, dependencies.asList())
) = compileToExecutable(sourcesDir, tryPassSystemCacheDirectory, freeCompilerArgs, dependencies.asList())
internal fun AbstractNativeSimpleTest.compileToExecutable(
sourcesDir: File,
tryPassSystemCacheDirectory: Boolean,
freeCompilerArgs: TestCompilerArgs,
dependencies: List<TestCompilationArtifact.KLIB>
): CompiledExecutable {
val testCase: TestCase = generateTestCaseWithSingleModule(sourcesDir, freeCompilerArgs)
val compilationResult = compileToExecutable(testCase, dependencies.map { it.asLibraryDependency() })
val compilationResult = compileToExecutable(testCase, tryPassSystemCacheDirectory, dependencies.map { it.asLibraryDependency() })
return CompiledExecutable(testCase, compilationResult.assertSuccess())
}
internal fun AbstractNativeSimpleTest.compileToExecutable(testCase: TestCase, vararg dependencies: TestCompilationDependency<*>) =
compileToExecutable(testCase, dependencies.asList())
compileToExecutable(testCase, true, dependencies.asList())
internal fun AbstractNativeSimpleTest.compileToStaticCache(
klib: TestCompilationArtifact.KLIB,
@@ -280,6 +284,7 @@ private fun AbstractNativeSimpleTest.compileToLibrary(
private fun AbstractNativeSimpleTest.compileToExecutable(
testCase: TestCase,
tryPassSystemCacheDirectory: Boolean,
dependencies: List<TestCompilationDependency<*>>
): TestCompilationResult<out TestCompilationArtifact.Executable> {
val compilation = ExecutableCompilation(
@@ -288,7 +293,8 @@ private fun AbstractNativeSimpleTest.compileToExecutable(
sourceModules = testCase.modules,
extras = testCase.extras,
dependencies = dependencies,
expectedArtifact = getExecutableArtifact()
expectedArtifact = getExecutableArtifact(),
tryPassSystemCacheDirectory = tryPassSystemCacheDirectory
)
return compilation.result
}
@@ -302,7 +302,8 @@ internal class ExecutableCompilation(
sourceModules: Collection<TestModule>,
private val extras: Extras,
dependencies: Iterable<TestCompilationDependency<*>>,
expectedArtifact: Executable
expectedArtifact: Executable,
val tryPassSystemCacheDirectory: Boolean = true,
) : SourceBasedCompilation<Executable>(
targets = settings.get(),
home = settings.get(),
@@ -355,7 +356,9 @@ internal class ExecutableCompilation(
override fun applyDependencies(argsBuilder: ArgsBuilder): Unit = with(argsBuilder) {
super.applyDependencies(argsBuilder)
cacheMode.staticCacheForDistributionLibrariesRootDir?.let { cacheRootDir -> add("-Xcache-directory=$cacheRootDir") }
cacheMode.staticCacheForDistributionLibrariesRootDir
?.takeIf { tryPassSystemCacheDirectory }
?.let { cacheRootDir -> add("-Xcache-directory=$cacheRootDir") }
add(dependencies.uniqueCacheDirs) { libraryCacheDir -> "-Xcache-directory=${libraryCacheDir.path}" }
}