Skip to content

Commit d3b8607

Browse files
homurollSpace Team
authored and
Space Team
committed
[K/N][tests] Fixed CachesAutoBuildTest
In auto-cache mode, the compiler itself chooses the system cache directory, and it is important to not pass it explicitly.
1 parent 084479f commit d3b8607

File tree

3 files changed

+27
-6
lines changed

3 files changed

+27
-6
lines changed

native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/CachesAutoBuildTest.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ class CachesAutoBuildTest : AbstractNativeSimpleTest() {
8282
private fun compileToExecutable(sourcesDir: File, autoCacheFrom: File, cacheDirectories: List<File>, vararg dependencies: KLIB) =
8383
compileToExecutable(
8484
sourcesDir,
85+
tryPassSystemCacheDirectory = false, // With auto-cache mode, the compiler chooses the system cache directory itself.
8586
freeCompilerArgs = TestCompilerArgs(
8687
listOf(
8788
"-Xauto-cache-from=${autoCacheFrom.absolutePath}",

native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/NativeSimpleTestUtils.kt

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,15 +78,30 @@ internal fun AbstractNativeSimpleTest.cinteropToLibrary(
7878

7979
internal fun AbstractNativeSimpleTest.compileToExecutable(
8080
sourcesDir: File,
81+
tryPassSystemCacheDirectory: Boolean,
8182
freeCompilerArgs: TestCompilerArgs,
8283
vararg dependencies: TestCompilationArtifact.KLIB
8384
): TestCompilationResult<out TestCompilationArtifact.Executable> {
8485
val testCase: TestCase = generateTestCaseWithSingleModule(sourcesDir, freeCompilerArgs)
85-
return compileToExecutable(testCase, dependencies.map { it.asLibraryDependency() })
86+
return compileToExecutable(testCase, tryPassSystemCacheDirectory, dependencies.map { it.asLibraryDependency() })
8687
}
8788

88-
internal fun AbstractNativeSimpleTest.compileToExecutable(testCase: TestCase, vararg dependencies: TestCompilationDependency<*>) =
89-
compileToExecutable(testCase, dependencies.asList())
89+
internal fun AbstractNativeSimpleTest.compileToExecutable(
90+
sourcesDir: File,
91+
freeCompilerArgs: TestCompilerArgs,
92+
vararg dependencies: TestCompilationArtifact.KLIB
93+
) = compileToExecutable(sourcesDir, true, freeCompilerArgs, *dependencies)
94+
95+
internal fun AbstractNativeSimpleTest.compileToExecutable(
96+
testCase: TestCase,
97+
tryPassSystemCacheDirectory: Boolean,
98+
vararg dependencies: TestCompilationDependency<*>
99+
) = compileToExecutable(testCase, tryPassSystemCacheDirectory, dependencies.asList())
100+
101+
internal fun AbstractNativeSimpleTest.compileToExecutable(
102+
testCase: TestCase,
103+
vararg dependencies: TestCompilationDependency<*>
104+
) = compileToExecutable(testCase, true, dependencies.asList())
90105

91106
internal fun AbstractNativeSimpleTest.compileToStaticCache(
92107
klib: TestCompilationArtifact.KLIB,
@@ -188,6 +203,7 @@ private fun AbstractNativeSimpleTest.compileToLibrary(
188203

189204
private fun AbstractNativeSimpleTest.compileToExecutable(
190205
testCase: TestCase,
206+
tryPassSystemCacheDirectory: Boolean,
191207
dependencies: List<TestCompilationDependency<*>>
192208
): TestCompilationResult<out TestCompilationArtifact.Executable> {
193209
val compilation = ExecutableCompilation(
@@ -196,7 +212,8 @@ private fun AbstractNativeSimpleTest.compileToExecutable(
196212
sourceModules = testCase.modules,
197213
extras = testCase.extras,
198214
dependencies = dependencies,
199-
expectedArtifact = getExecutableArtifact()
215+
expectedArtifact = getExecutableArtifact(),
216+
tryPassSystemCacheDirectory = tryPassSystemCacheDirectory
200217
)
201218
return compilation.result
202219
}

native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/compilation/TestCompilation.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,8 @@ internal class ExecutableCompilation(
269269
sourceModules: Collection<TestModule>,
270270
private val extras: Extras,
271271
dependencies: Iterable<TestCompilationDependency<*>>,
272-
expectedArtifact: Executable
272+
expectedArtifact: Executable,
273+
val tryPassSystemCacheDirectory: Boolean = true,
273274
) : SourceBasedCompilation<Executable>(
274275
targets = settings.get(),
275276
home = settings.get(),
@@ -322,7 +323,9 @@ internal class ExecutableCompilation(
322323

323324
override fun applyDependencies(argsBuilder: ArgsBuilder): Unit = with(argsBuilder) {
324325
super.applyDependencies(argsBuilder)
325-
cacheMode.staticCacheForDistributionLibrariesRootDir?.let { cacheRootDir -> add("-Xcache-directory=$cacheRootDir") }
326+
cacheMode.staticCacheForDistributionLibrariesRootDir
327+
?.takeIf { tryPassSystemCacheDirectory }
328+
?.let { cacheRootDir -> add("-Xcache-directory=$cacheRootDir") }
326329
add(dependencies.uniqueCacheDirs) { libraryCacheDir -> "-Xcache-directory=${libraryCacheDir.path}" }
327330
}
328331

0 commit comments

Comments
 (0)