From 2f463f740f1dfcea8bbe07451fd75ae4450ddeec Mon Sep 17 00:00:00 2001 From: Igor Chevdar Date: Thu, 3 Aug 2023 18:26:34 +0300 Subject: [PATCH] [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. --- .../konan/blackboxtest/CachesAutoBuildTest.kt | 1 + .../blackboxtest/IncrementalCompilationTest.kt | 2 +- .../konan/blackboxtest/NativeSimpleTestUtils.kt | 14 ++++++++++---- .../support/compilation/TestCompilation.kt | 7 +++++-- 4 files changed, 17 insertions(+), 7 deletions(-) diff --git a/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/CachesAutoBuildTest.kt b/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/CachesAutoBuildTest.kt index c995648b9e7..6af8c1fe8c7 100644 --- a/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/CachesAutoBuildTest.kt +++ b/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/CachesAutoBuildTest.kt @@ -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}", diff --git a/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/IncrementalCompilationTest.kt b/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/IncrementalCompilationTest.kt index 9ea7ce31d1a..b638f7df1fe 100644 --- a/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/IncrementalCompilationTest.kt +++ b/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/IncrementalCompilationTest.kt @@ -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() diff --git a/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/NativeSimpleTestUtils.kt b/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/NativeSimpleTestUtils.kt index dfb91e73cc7..a5acf3d82eb 100644 --- a/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/NativeSimpleTestUtils.kt +++ b/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/NativeSimpleTestUtils.kt @@ -81,6 +81,7 @@ internal class ExecutableBuilder( test: AbstractNativeSimpleTest, rootDir: File, targetSrc: String, + val tryPassSystemCacheDirectory: Boolean, dependencies: List ) : ArtifactBuilder(test, rootDir, targetSrc, dependencies) { private val freeCompilerArgs = mutableListOf() @@ -92,6 +93,7 @@ internal class ExecutableBuilder( override fun build(sourcesDir: File, outputDir: File, dependencies: List) = 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 ): 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> ): TestCompilationResult { 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 } diff --git a/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/compilation/TestCompilation.kt b/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/compilation/TestCompilation.kt index da3cd471afe..3592d065e36 100644 --- a/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/compilation/TestCompilation.kt +++ b/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/compilation/TestCompilation.kt @@ -302,7 +302,8 @@ internal class ExecutableCompilation( sourceModules: Collection, private val extras: Extras, dependencies: Iterable>, - expectedArtifact: Executable + expectedArtifact: Executable, + val tryPassSystemCacheDirectory: Boolean = true, ) : SourceBasedCompilation( 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}" } }