Fully convert AbstractNativeKlibBinaryCompatibilityTest to two-stage, use FirPipeline
diff --git a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/K1KlibBinaryCompatibilityTestGenerated.java b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/FirKlibBinaryCompatibilityTestGenerated.java
similarity index 97%
rename from native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/K1KlibBinaryCompatibilityTestGenerated.java
rename to native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/FirKlibBinaryCompatibilityTestGenerated.java
index cb722cc..9165119 100644
--- a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/K1KlibBinaryCompatibilityTestGenerated.java
+++ b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/FirKlibBinaryCompatibilityTestGenerated.java
@@ -8,6 +8,7 @@
 import com.intellij.testFramework.TestDataPath;
 import org.jetbrains.kotlin.test.util.KtTestUtil;
 import org.junit.jupiter.api.Tag;
+import org.jetbrains.kotlin.konan.blackboxtest.support.group.FirPipeline;
 import org.jetbrains.kotlin.test.TestMetadata;
 import org.junit.jupiter.api.Nested;
 import org.junit.jupiter.api.Test;
@@ -19,8 +20,9 @@
 @SuppressWarnings("all")
 @TestMetadata("compiler/testData/binaryCompatibility/klibEvolution")
 @TestDataPath("$PROJECT_ROOT")
-@Tag("k1KlibCompatibility")
-public class K1KlibBinaryCompatibilityTestGenerated extends AbstractNativeKlibBinaryCompatibilityTest {
+@Tag("klibCompatibility")
+@FirPipeline()
+public class FirKlibBinaryCompatibilityTestGenerated extends AbstractNativeKlibBinaryCompatibilityTest {
     @Test
     @TestMetadata("addAbstractMemberBody.kt")
     public void testAddAbstractMemberBody() throws Exception {
diff --git a/native/native.tests/tests/org/jetbrains/kotlin/generators/tests/GenerateNativeTests.kt b/native/native.tests/tests/org/jetbrains/kotlin/generators/tests/GenerateNativeTests.kt
index 7337e93..eb59917 100644
--- a/native/native.tests/tests/org/jetbrains/kotlin/generators/tests/GenerateNativeTests.kt
+++ b/native/native.tests/tests/org/jetbrains/kotlin/generators/tests/GenerateNativeTests.kt
@@ -65,8 +65,8 @@
         // KLIB binary compatibility tests.
         testGroup("native/native.tests/tests-gen", "compiler/testData") {
             testClass<AbstractNativeKlibBinaryCompatibilityTest>(
-                suiteTestClassName = "K1KlibBinaryCompatibilityTestGenerated",
-                annotations = listOf(k1KLibCompatibility())
+                suiteTestClassName = "FirKlibBinaryCompatibilityTestGenerated",
+                annotations = listOf(klibCompatibility(), provider<FirPipeline>())
             ) {
                 model("binaryCompatibility/klibEvolution", recursive = false)
             }
@@ -157,4 +157,4 @@
 private fun k1libContents() = annotation(Tag::class.java, "k1libContents")
 private fun k2libContents() = annotation(Tag::class.java, "k2libContents")
 private fun firKLibContents() = annotation(Tag::class.java, "firKlibContents")
-private fun k1KLibCompatibility() = annotation(Tag::class.java, "k1KlibCompatibility")
+private fun klibCompatibility() = annotation(Tag::class.java, "klib-binary-compatibility")
diff --git a/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/AbstractNativeKlibBinaryCompatibilityTest.kt b/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/AbstractNativeKlibBinaryCompatibilityTest.kt
index db990a7..cc3e701 100644
--- a/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/AbstractNativeKlibBinaryCompatibilityTest.kt
+++ b/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/AbstractNativeKlibBinaryCompatibilityTest.kt
@@ -21,6 +21,7 @@
 import org.jetbrains.kotlin.konan.blackboxtest.support.settings.SimpleTestDirectories
 import org.jetbrains.kotlin.konan.blackboxtest.support.settings.Timeouts
 import org.jetbrains.kotlin.konan.blackboxtest.support.util.*
+import org.jetbrains.kotlin.test.Directives
 import org.jetbrains.kotlin.utils.DFS
 import org.junit.jupiter.api.Tag
 import java.io.File
@@ -42,7 +43,7 @@
     private fun buildKlib(
         binaryCompatibilityTestModule: BinaryCompatibilityTestModule,
         version: Int
-    ) {
+    ): LibraryCompilation {
         val module = binaryCompatibilityTestModule.toLightDependencyWithVersion(version)
         val moduleDependencies = collectDependencies(
             binaryCompatibilityTestModule.dependenciesSymbols,
@@ -63,6 +64,7 @@
         compilation.trigger()
 
         updateModule(module, moduleDependencies)
+        return compilation
     }
 
     private fun buildAndExecuteBinary(
@@ -71,20 +73,20 @@
     ) {
         val binaryVersion = moduleVersions.values.maxOrNull() ?: 2
 
-        buildKlib(mainTestModule, binaryVersion)
-
         val (binarySourceDir, binaryOutputDir) = listOf(BINARY_SOURCE_DIR_NAME, BINARY_OUTPUT_DIR_NAME).map {
             buildDir.resolve(LAUNCHER_MODULE_NAME).resolve(it).apply { mkdirs() }
         }
 
-        val launcherModule = LightDependencyWithVersion(LAUNCHER_MODULE_NAME, binaryVersion).apply {
-            module.files += TestFile.createUncommitted(
-                location = binarySourceDir.resolve(LAUNCHER_FILE_NAME),
-                module = module,
-                text = generateBoxFunctionLauncher("box", expectedResult)
-            )
-        }
-        val launcherDependencies = collectDependencies(mainTestModule.name, binaryVersion)
+        // insert launcher into main module sources
+        org.jetbrains.kotlin.compatibility.binary.TestFile(
+            fileName = binarySourceDir.resolve(LAUNCHER_FILE_NAME).absolutePath,
+            module = mainTestModule,
+            text = generateBoxFunctionLauncher("box", expectedResult),
+            directives = Directives()
+        )
+        val mainLibraryCompilation = buildKlib(mainTestModule, binaryVersion)
+
+        val mainModuleDependencies = collectDependencies(mainTestModule.name, binaryVersion)
         val executableFile = binaryOutputDir.resolve(
             "app." + testRunSettings.get<KotlinNativeTargets>().testTarget.family.exeSuffix
         )
@@ -98,16 +100,22 @@
             emptyList()
         }
 
-        val testCase = mkTestCase(launcherModule, COMPILER_ARGS_FOR_STATIC_CACHE_AND_EXECUTABLE)
+        val testCase = mkTestCase(mainTestModule.toLightDependencyWithVersion(binaryVersion), COMPILER_ARGS_FOR_STATIC_CACHE_AND_EXECUTABLE)
 
+        val includedLibraryDependencies = listOf(mainLibraryCompilation.toCompiledDependency())
+        val libraryDependencies = mainModuleDependencies
+            .filter {
+                // exclude main module from Library dependencies, since it will be used as IncludedLibrary dependency
+                it != LightDependencyWithVersion(mainTestModule.name, binaryVersion)
+            }.map {
+                it.klibFile.toKlib().toDependency()
+            }
         val compilation = ExecutableCompilation(
             settings = testRunSettings,
             freeCompilerArgs = testCase.freeCompilerArgs,
-            sourceModules = testCase.modules,
+            sourceModules = setOf(),  // Fir pipeline requires no sources for executable compilation, see KT-56855
             extras = testCase.extras,
-            dependencies = launcherDependencies.map {
-                it.klibFile.toKlib().toDependency()
-            } + cachedDependencies,
+            dependencies = libraryDependencies + cachedDependencies + includedLibraryDependencies,
             expectedArtifact = TestCompilationArtifact.Executable(executableFile)
         )
 
@@ -283,6 +291,8 @@
     klib = KLIB(this)
 )
 
+private fun TestCompilation<KLIB>.toCompiledDependency() =
+    CompiledDependency(this, TestCompilationDependencyType.IncludedLibrary)
 private fun KLIB.toDependency() =
     ExistingDependency(this, TestCompilationDependencyType.Library)
 private fun KLIBStaticCache.toDependency() =