[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() autoCacheDir.mkdirs()
return compileToExecutable( return compileToExecutable(
sourcesDir, sourcesDir,
tryPassSystemCacheDirectory = false, // With auto-cache mode, the compiler chooses the system cache directory itself.
freeCompilerArgs = TestCompilerArgs( freeCompilerArgs = TestCompilerArgs(
listOf( listOf(
"-Xauto-cache-from=${autoCacheFrom.absolutePath}", "-Xauto-cache-from=${autoCacheFrom.absolutePath}",
@@ -502,7 +502,7 @@ class IncrementalCompilationTest : AbstractNativeSimpleTest() {
targetSrc: String, targetSrc: String,
vararg dependencies: TestCompilationArtifact.KLIB, vararg dependencies: TestCompilationArtifact.KLIB,
block: ExecutableBuilder.() -> Unit block: ExecutableBuilder.() -> Unit
) = with(ExecutableBuilder(this@IncrementalCompilationTest, rootDir, targetSrc, dependencies.asList())) { ) = with(ExecutableBuilder(this@IncrementalCompilationTest, rootDir, targetSrc, false, dependencies.asList())) {
externalLibsDir.mkdirs() externalLibsDir.mkdirs()
icCacheDir.mkdirs() icCacheDir.mkdirs()
autoCacheDir.mkdirs() autoCacheDir.mkdirs()
@@ -81,6 +81,7 @@ internal class ExecutableBuilder(
test: AbstractNativeSimpleTest, test: AbstractNativeSimpleTest,
rootDir: File, rootDir: File,
targetSrc: String, targetSrc: String,
val tryPassSystemCacheDirectory: Boolean,
dependencies: List<TestCompilationArtifact.KLIB> dependencies: List<TestCompilationArtifact.KLIB>
) : ArtifactBuilder<CompiledExecutable>(test, rootDir, targetSrc, dependencies) { ) : ArtifactBuilder<CompiledExecutable>(test, rootDir, targetSrc, dependencies) {
private val freeCompilerArgs = mutableListOf<String>() private val freeCompilerArgs = mutableListOf<String>()
@@ -92,6 +93,7 @@ internal class ExecutableBuilder(
override fun build(sourcesDir: File, outputDir: File, dependencies: List<TestCompilationArtifact.KLIB>) = override fun build(sourcesDir: File, outputDir: File, dependencies: List<TestCompilationArtifact.KLIB>) =
test.compileToExecutable( test.compileToExecutable(
sourcesDir, sourcesDir,
tryPassSystemCacheDirectory,
freeCompilerArgs = if (freeCompilerArgs.isEmpty()) TestCompilerArgs.EMPTY else TestCompilerArgs(freeCompilerArgs), freeCompilerArgs = if (freeCompilerArgs.isEmpty()) TestCompilerArgs.EMPTY else TestCompilerArgs(freeCompilerArgs),
dependencies dependencies
) )
@@ -159,22 +161,24 @@ internal class CompiledExecutable(
internal fun AbstractNativeSimpleTest.compileToExecutable( internal fun AbstractNativeSimpleTest.compileToExecutable(
sourcesDir: File, sourcesDir: File,
tryPassSystemCacheDirectory: Boolean,
freeCompilerArgs: TestCompilerArgs, freeCompilerArgs: TestCompilerArgs,
vararg dependencies: TestCompilationArtifact.KLIB vararg dependencies: TestCompilationArtifact.KLIB
) = compileToExecutable(sourcesDir, freeCompilerArgs, dependencies.asList()) ) = compileToExecutable(sourcesDir, tryPassSystemCacheDirectory, freeCompilerArgs, dependencies.asList())
internal fun AbstractNativeSimpleTest.compileToExecutable( internal fun AbstractNativeSimpleTest.compileToExecutable(
sourcesDir: File, sourcesDir: File,
tryPassSystemCacheDirectory: Boolean,
freeCompilerArgs: TestCompilerArgs, freeCompilerArgs: TestCompilerArgs,
dependencies: List<TestCompilationArtifact.KLIB> dependencies: List<TestCompilationArtifact.KLIB>
): CompiledExecutable { ): CompiledExecutable {
val testCase: TestCase = generateTestCaseWithSingleModule(sourcesDir, freeCompilerArgs) 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()) return CompiledExecutable(testCase, compilationResult.assertSuccess())
} }
internal fun AbstractNativeSimpleTest.compileToExecutable(testCase: TestCase, vararg dependencies: TestCompilationDependency<*>) = internal fun AbstractNativeSimpleTest.compileToExecutable(testCase: TestCase, vararg dependencies: TestCompilationDependency<*>) =
compileToExecutable(testCase, dependencies.asList()) compileToExecutable(testCase, true, dependencies.asList())
internal fun AbstractNativeSimpleTest.compileToStaticCache( internal fun AbstractNativeSimpleTest.compileToStaticCache(
klib: TestCompilationArtifact.KLIB, klib: TestCompilationArtifact.KLIB,
@@ -280,6 +284,7 @@ private fun AbstractNativeSimpleTest.compileToLibrary(
private fun AbstractNativeSimpleTest.compileToExecutable( private fun AbstractNativeSimpleTest.compileToExecutable(
testCase: TestCase, testCase: TestCase,
tryPassSystemCacheDirectory: Boolean,
dependencies: List<TestCompilationDependency<*>> dependencies: List<TestCompilationDependency<*>>
): TestCompilationResult<out TestCompilationArtifact.Executable> { ): TestCompilationResult<out TestCompilationArtifact.Executable> {
val compilation = ExecutableCompilation( val compilation = ExecutableCompilation(
@@ -288,7 +293,8 @@ private fun AbstractNativeSimpleTest.compileToExecutable(
sourceModules = testCase.modules, sourceModules = testCase.modules,
extras = testCase.extras, extras = testCase.extras,
dependencies = dependencies, dependencies = dependencies,
expectedArtifact = getExecutableArtifact() expectedArtifact = getExecutableArtifact(),
tryPassSystemCacheDirectory = tryPassSystemCacheDirectory
) )
return compilation.result return compilation.result
} }
@@ -302,7 +302,8 @@ internal class ExecutableCompilation(
sourceModules: Collection<TestModule>, sourceModules: Collection<TestModule>,
private val extras: Extras, private val extras: Extras,
dependencies: Iterable<TestCompilationDependency<*>>, dependencies: Iterable<TestCompilationDependency<*>>,
expectedArtifact: Executable expectedArtifact: Executable,
val tryPassSystemCacheDirectory: Boolean = true,
) : SourceBasedCompilation<Executable>( ) : SourceBasedCompilation<Executable>(
targets = settings.get(), targets = settings.get(),
home = settings.get(), home = settings.get(),
@@ -355,7 +356,9 @@ internal class ExecutableCompilation(
override fun applyDependencies(argsBuilder: ArgsBuilder): Unit = with(argsBuilder) { override fun applyDependencies(argsBuilder: ArgsBuilder): Unit = with(argsBuilder) {
super.applyDependencies(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}" } add(dependencies.uniqueCacheDirs) { libraryCacheDir -> "-Xcache-directory=${libraryCacheDir.path}" }
} }