diff --git a/native/native.tests/tests/org/jetbrains/kotlin/konan/test/blackbox/NativeSimpleTestUtils.kt b/native/native.tests/tests/org/jetbrains/kotlin/konan/test/blackbox/NativeSimpleTestUtils.kt index 22895e2b35d5a..4a646a906e319 100644 --- a/native/native.tests/tests/org/jetbrains/kotlin/konan/test/blackbox/NativeSimpleTestUtils.kt +++ b/native/native.tests/tests/org/jetbrains/kotlin/konan/test/blackbox/NativeSimpleTestUtils.kt @@ -141,17 +141,31 @@ internal fun AbstractNativeSimpleTest.cinteropToLibrary( outputDir: File, freeCompilerArgs: TestCompilerArgs ): TestCompilationResult { - val testCase: TestCase = generateCInteropTestCaseFromSingleDefFile(defFile, freeCompilerArgs) + val args = freeCompilerArgs + cinteropModulesCachePathArguments(freeCompilerArgs.cinteropArgs, outputDir) + val testCase: TestCase = generateCInteropTestCaseFromSingleDefFile(defFile, args) return CInteropCompilation( classLoader = testRunSettings.get(), targets = targets, - freeCompilerArgs = freeCompilerArgs, + freeCompilerArgs = args, defFile = testCase.modules.single().files.single().location, dependencies = emptyList(), expectedArtifact = getLibraryArtifact(testCase, outputDir) ).result } +private fun cinteropModulesCachePathArguments( + cinteropArgs: List, + outputDir: File, +) = if (cinteropArgs.contains("-fmodules") && cinteropArgs.none { it.startsWith(FMODULES_CACHE_PATH_EQ) }) { + // Don't reuse the system-wide module cache to make the test run more predictably. + // See e.g. https://youtrack.jetbrains.com/issue/KT-68254. + TestCInteropArgs("-compiler-option", "$FMODULES_CACHE_PATH_EQ$outputDir/modulesCachePath") +} else { + TestCompilerArgs.EMPTY +} + +private const val FMODULES_CACHE_PATH_EQ = "-fmodules-cache-path=" + internal class CompiledExecutable( val testCase: TestCase, val compilationResult: TestCompilationResult.Success