diff --git a/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/LoggedData.kt b/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/LoggedData.kt index 9787036b53f..137f3cd2b18 100644 --- a/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/LoggedData.kt +++ b/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/LoggedData.kt @@ -81,13 +81,15 @@ internal abstract class LoggedData { } } - class CompilerCall( + abstract class CompilerCall : LoggedData() + + class RealCompilerCall( private val parameters: CompilerParameters, private val exitCode: ExitCode, private val compilerOutput: String, private val compilerOutputHasErrors: Boolean, private val duration: Duration - ) : LoggedData() { + ) : CompilerCall() { override fun computeText(): String { val problems = listOfNotNull( "- Non-zero exit code".takeIf { exitCode != ExitCode.OK }, @@ -112,6 +114,10 @@ internal abstract class LoggedData { } } + class NoopCompilerCall(val artifactFile: File) : CompilerCall() { + override fun computeText() = "No compiler call performed for external (given) artifact $artifactFile" + } + class CompilerCallUnexpectedFailure(parameters: CompilerParameters, throwable: Throwable) : UnexpectedFailure(parameters, throwable) class TestRunParameters( 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 691ace3e187..c234120fb5e 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 @@ -89,7 +89,7 @@ internal abstract class BasicCompilation( ) val loggedCompilerCall = - LoggedData.CompilerCall(loggedCompilerParameters, exitCode, compilerOutput, compilerOutputHasErrors, duration) + LoggedData.RealCompilerCall(loggedCompilerParameters, exitCode, compilerOutput, compilerOutputHasErrors, duration) val result = if (exitCode != ExitCode.OK || compilerOutputHasErrors) TestCompilationResult.CompilerFailure(loggedCompilerCall) @@ -185,6 +185,10 @@ internal class LibraryCompilation( } } +internal class GivenLibraryCompilation(givenArtifact: KLIB) : TestCompilation() { + override val result = TestCompilationResult.Success(givenArtifact, LoggedData.NoopCompilerCall(givenArtifact.klibFile)) +} + internal class ExecutableCompilation( settings: Settings, freeCompilerArgs: TestCompilerArgs, diff --git a/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/compilation/TestCompilationFactory.kt b/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/compilation/TestCompilationFactory.kt index 1949cc5bc1f..09ae5a44e77 100644 --- a/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/compilation/TestCompilationFactory.kt +++ b/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/compilation/TestCompilationFactory.kt @@ -141,22 +141,27 @@ internal class TestCompilationFactory { val dependencies = collectDependencies(sourceModules, freeCompilerArgs, settings) val klibArtifact = KLIB(settings.artifactFileForKlib(sourceModules, freeCompilerArgs)) + val isGivenKlibArtifact = sourceModules.singleOrNull() is TestModule.Given + val staticCacheArtifactAndOptions: Pair? = when (produceStaticCache) { is ProduceStaticCache.No -> null // No artifact means no static cache should be compiled. is ProduceStaticCache.Yes -> KLIBStaticCache( - cacheDir = settings.cacheDirForStaticCache(klibArtifact), + cacheDir = settings.cacheDirForStaticCache(klibArtifact, isGivenKlibArtifact), klib = klibArtifact ) to produceStaticCache.options } return cachedKlibCompilations.computeIfAbsent(cacheKey) { - val klibCompilation = LibraryCompilation( - settings = settings, - freeCompilerArgs = freeCompilerArgs, - sourceModules = sourceModules, - dependencies = dependencies.forKlib(), - expectedArtifact = klibArtifact - ) + val klibCompilation = if (isGivenKlibArtifact) + GivenLibraryCompilation(klibArtifact) + else + LibraryCompilation( + settings = settings, + freeCompilerArgs = freeCompilerArgs, + sourceModules = sourceModules, + dependencies = dependencies.forKlib(), + expectedArtifact = klibArtifact + ) val staticCacheCompilation: StaticCacheCompilation? = staticCacheArtifactAndOptions?.let { (staticCacheArtifact, staticCacheOptions) -> @@ -227,19 +232,20 @@ internal class TestCompilationFactory { assertTrue(modules.none { module -> module is TestModule.Shared }) { "Can't compile shared module together with any other module" } + assertTrue(modules.none { module -> module is TestModule.Given }) { + "Can't compile given module together with any other module" + } multiModuleArtifactFile(modules, "klib") } } - private fun Settings.cacheDirForStaticCache(klibArtifact: KLIB): File { - val binaries = get() - - val artifactBaseDir = if (klibArtifact.klibFile.startsWith(binaries.testBinariesDir)) { + private fun Settings.cacheDirForStaticCache(klibArtifact: KLIB, isGivenKlibArtifact: Boolean): File { + val artifactBaseDir = if (isGivenKlibArtifact) { + // Special case for the given (external) KLIB artifacts. + get().givenBinariesDir + } else { // The KLIB artifact is located inside the build dir. This means it was built just a moment ago. klibArtifact.klibFile.parentFile - } else { - // Special case for the given (external) KLIB artifacts. - binaries.givenBinariesDir } return artifactBaseDir.resolve(STATIC_CACHE_DIR_NAME).apply { mkdirs() } diff --git a/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/compilation/TestCompilationResult.kt b/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/compilation/TestCompilationResult.kt index a5715311388..d42598df830 100644 --- a/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/compilation/TestCompilationResult.kt +++ b/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/compilation/TestCompilationResult.kt @@ -18,7 +18,7 @@ internal sealed interface TestCompilationResult { data class Success(val resultingArtifact: A, override val loggedData: LoggedData.CompilerCall) : ImmediateResult - data class CompilerFailure(override val loggedData: LoggedData.CompilerCall) : Failure + data class CompilerFailure(override val loggedData: LoggedData.RealCompilerCall) : Failure data class UnexpectedFailure(override val loggedData: LoggedData.CompilerCallUnexpectedFailure) : Failure data class DependencyFailures(val causes: Set) : TestCompilationResult