[PL][tests] K/JS: Avoid any unexpected warnings to appear in tests

This commit is contained in:
Dmitriy Dolovov
2023-07-12 11:45:16 +02:00
committed by Space Team
parent 715aba3d18
commit 938146749d
12 changed files with 71 additions and 58 deletions
+7 -7
View File
@@ -74,33 +74,33 @@ fun box() = abiTest {
} }
// Shortcuts: // Shortcuts:
private inline fun TestBuilder.success(expectedOutcome: String, noinline block: () -> Any) = private fun TestBuilder.success(expectedOutcome: String, block: () -> Any) =
expectSuccess(expectedOutcome) { block().toString() } expectSuccess(expectedOutcome) { block().toString() }
private inline fun TestBuilder.successViaException(testExceptionId: String, noinline block: () -> Unit) = private fun TestBuilder.successViaException(testExceptionId: String, block: () -> Unit) =
expectFailure(custom { (it as? TestException)?.id == testExceptionId }, block) expectFailure(custom { (it as? TestException)?.id == testExceptionId }, block)
private inline fun TestBuilder.inaccessible(className: String, noinline block: () -> Unit) = expectFailure( private fun TestBuilder.inaccessible(className: String, block: () -> Unit) = expectFailure(
linkage("Constructor '$className.<init>' can not be called: Private constructor declared in module <lib1> can not be accessed in module <lib2>"), linkage("Constructor '$className.<init>' can not be called: Private constructor declared in module <lib1> can not be accessed in module <lib2>"),
block block
) )
private inline fun TestBuilder.unlinkedSymbolInValueParameter(signature: String, noinline block: () -> Unit) { private fun TestBuilder.unlinkedSymbolInValueParameter(signature: String, block: () -> Unit) {
val functionName = signature.removePrefix("/").replace('.', '_') + "_valueParameter" val functionName = signature.removePrefix("/").replace('.', '_') + "_valueParameter"
unlinkedSymbol(signature, functionName, block) unlinkedSymbol(signature, functionName, block)
} }
private inline fun TestBuilder.unlinkedSymbolInReturnType(signature: String, noinline block: () -> Unit) { private fun TestBuilder.unlinkedSymbolInReturnType(signature: String, block: () -> Unit) {
val functionName = signature.removePrefix("/").replace('.', '_') + "_returnType" val functionName = signature.removePrefix("/").replace('.', '_') + "_returnType"
unlinkedSymbol(signature, functionName, block) unlinkedSymbol(signature, functionName, block)
} }
private inline fun TestBuilder.unlinkedConstructorSymbol(signature: String, noinline block: () -> Unit) { private fun TestBuilder.unlinkedConstructorSymbol(signature: String, block: () -> Unit) {
val constructorName = signature.removePrefix("/").split('.').takeLast(2).joinToString(".") val constructorName = signature.removePrefix("/").split('.').takeLast(2).joinToString(".")
expectFailure(linkage("Constructor '$constructorName' can not be called: No constructor found for symbol '$signature'"), block) expectFailure(linkage("Constructor '$constructorName' can not be called: No constructor found for symbol '$signature'"), block)
} }
private inline fun TestBuilder.unlinkedSymbol(signature: String, functionName: String, noinline block: () -> Unit) { private fun TestBuilder.unlinkedSymbol(signature: String, functionName: String, block: () -> Unit) {
// Need to slightly adjust the expected IR linkage error message. Reason: When Lazy IR is used the type of the // Need to slightly adjust the expected IR linkage error message. Reason: When Lazy IR is used the type of the
// symbol is determined more accurately. // symbol is determined more accurately.
val symbolKind = if ("InnerClass" in functionName && testMode.lazyIr.usedEverywhere) val symbolKind = if ("InnerClass" in functionName && testMode.lazyIr.usedEverywhere)
@@ -51,15 +51,15 @@ fun box() = abiTest {
} }
// Shortcuts: // Shortcuts:
private inline fun TestBuilder.success(expectedOutcome: String, noinline block: () -> String) = private fun TestBuilder.success(expectedOutcome: String, block: () -> String) =
expectSuccess(expectedOutcome, block) expectSuccess(expectedOutcome, block)
private inline fun TestBuilder.unlinkedSymbol(signature: String, noinline block: () -> Unit) { private fun TestBuilder.unlinkedSymbol(signature: String, block: () -> Unit) {
val functionName = signature.removePrefix("/").substringAfterLast(".") val functionName = signature.removePrefix("/").substringAfterLast(".")
expectFailure(linkage("Function '$functionName' can not be called: No function found for symbol '$signature'"), block) expectFailure(linkage("Function '$functionName' can not be called: No function found for symbol '$signature'"), block)
} }
private inline fun TestBuilder.unlinkedTopLevelPrivateSymbol(signature: String, noinline block: () -> Unit) { private fun TestBuilder.unlinkedTopLevelPrivateSymbol(signature: String, block: () -> Unit) {
if (testMode.lazyIr.usedEverywhere) { if (testMode.lazyIr.usedEverywhere) {
val functionName = signature.removePrefix("/").substringAfterLast(".") val functionName = signature.removePrefix("/").substringAfterLast(".")
expectFailure(linkage("Function '$functionName' can not be called: Private function declared in module <lib1> can not be accessed in module <main>"), block) expectFailure(linkage("Function '$functionName' can not be called: Private function declared in module <lib1> can not be accessed in module <main>"), block)
@@ -67,7 +67,7 @@ private inline fun TestBuilder.unlinkedTopLevelPrivateSymbol(signature: String,
unlinkedSymbol(signature, block) unlinkedSymbol(signature, block)
} }
private inline fun TestBuilder.inaccessible(functionName: String, noinline block: () -> Unit) = expectFailure( private fun TestBuilder.inaccessible(functionName: String, block: () -> Unit) = expectFailure(
linkage("Function '$functionName' can not be called: Private function declared in module <lib1> can not be accessed in module <main>"), linkage("Function '$functionName' can not be called: Private function declared in module <lib1> can not be accessed in module <main>"),
block block
) )
@@ -114,15 +114,15 @@ fun box() = abiTest {
} }
// Shortcuts: // Shortcuts:
private inline fun TestBuilder.success(expectedOutcome: String, noinline block: () -> String) = private fun TestBuilder.success(expectedOutcome: String, block: () -> String) =
expectSuccess(expectedOutcome, block) expectSuccess(expectedOutcome, block)
private inline fun TestBuilder.unlinkedSymbol(signature: String, noinline block: () -> Unit) { private fun TestBuilder.unlinkedSymbol(signature: String, block: () -> Unit) {
val accessorName = signature.removePrefix("/").split('.').takeLast(2).joinToString(".") val accessorName = signature.removePrefix("/").split('.').takeLast(2).joinToString(".")
expectFailure(linkage("Property accessor '$accessorName' can not be called: No property accessor found for symbol '$signature'"), block) expectFailure(linkage("Property accessor '$accessorName' can not be called: No property accessor found for symbol '$signature'"), block)
} }
private inline fun TestBuilder.unlinkedTopLevelPrivateSymbol(signature: String, noinline block: () -> Unit) { private fun TestBuilder.unlinkedTopLevelPrivateSymbol(signature: String, block: () -> Unit) {
if (testMode.lazyIr.usedEverywhere) { if (testMode.lazyIr.usedEverywhere) {
val accessorName = signature.removePrefix("/").split('.').takeLast(2).joinToString(".") val accessorName = signature.removePrefix("/").split('.').takeLast(2).joinToString(".")
expectFailure(linkage("Property accessor '$accessorName' can not be called: Private property accessor declared in module <lib1> can not be accessed in module <main>"), block) expectFailure(linkage("Property accessor '$accessorName' can not be called: Private property accessor declared in module <lib1> can not be accessed in module <main>"), block)
@@ -130,7 +130,7 @@ private inline fun TestBuilder.unlinkedTopLevelPrivateSymbol(signature: String,
unlinkedSymbol(signature, block) unlinkedSymbol(signature, block)
} }
private inline fun TestBuilder.inaccessible(accessorName: String, noinline block: () -> Unit) = expectFailure( private fun TestBuilder.inaccessible(accessorName: String, block: () -> Unit) = expectFailure(
linkage("Property accessor '$accessorName' can not be called: Private property accessor declared in module <lib1> can not be accessed in module <main>"), linkage("Property accessor '$accessorName' can not be called: Private property accessor declared in module <lib1> can not be accessed in module <main>"),
block block
) )
@@ -1,3 +1,4 @@
@file:Suppress("NOTHING_TO_INLINE")
fun getClassToEnumFoo(): ClassToEnum.Foo = ClassToEnum.Foo() fun getClassToEnumFoo(): ClassToEnum.Foo = ClassToEnum.Foo()
inline fun getClassToEnumFooInline(): ClassToEnum.Foo = ClassToEnum.Foo() inline fun getClassToEnumFooInline(): ClassToEnum.Foo = ClassToEnum.Foo()
+1 -1
View File
@@ -27,5 +27,5 @@ fun box() = abiTest {
expectSuccess("RegularClassInheritedFromExternalInterfaceInheritedFromOpenExternalClass.abstractFunction") { rcifeiifoec.abstractFunction() } expectSuccess("RegularClassInheritedFromExternalInterfaceInheritedFromOpenExternalClass.abstractFunction") { rcifeiifoec.abstractFunction() }
} }
private inline fun TestBuilder.expectRuntimeFailure(errorMessage: String, noinline block: () -> Any) = private fun TestBuilder.expectRuntimeFailure(errorMessage: String, block: () -> Any) =
expectFailure(custom { throwable -> throwable !is Exception && throwable.message == errorMessage }) { block() } expectFailure(custom { throwable -> throwable !is Exception && throwable.message == errorMessage }) { block() }
@@ -129,8 +129,8 @@ class OpenClassImpl : OpenClass() {
override fun openNonInlineToInlineFunction(x: Int): String = "OpenClassImpl.openNonInlineToInlineFunction($x)" override fun openNonInlineToInlineFunction(x: Int): String = "OpenClassImpl.openNonInlineToInlineFunction($x)"
override fun openNonInlineToInlineFunctionWithDelegation(x: Int): String = super.openNonInlineToInlineFunctionWithDelegation(x) + " called from OpenClassImpl.openNonInlineToInlineFunctionWithDelegation($x)" override fun openNonInlineToInlineFunctionWithDelegation(x: Int): String = super.openNonInlineToInlineFunctionWithDelegation(x) + " called from OpenClassImpl.openNonInlineToInlineFunctionWithDelegation($x)"
fun newInlineFunction1(x: Int): String = "OpenClassImpl.newInlineFunction1($x)" // overrides accidentally appeared inline function fun newInlineFunction1(x: Int): String = "OpenClassImpl.newInlineFunction1($x)" // overrides accidentally appeared inline function
inline fun newInlineFunction2(x: Int): String = "OpenClassImpl.newInlineFunction2($x)" // overrides accidentally appeared inline function @Suppress("NOTHING_TO_INLINE") inline fun newInlineFunction2(x: Int): String = "OpenClassImpl.newInlineFunction2($x)" // overrides accidentally appeared inline function
inline fun newNonInlineFunction(x: Int): String = "OpenClassImpl.newNonInlineFunction($x)" // overrides accidentally appeared non-inline function @Suppress("NOTHING_TO_INLINE") inline fun newNonInlineFunction(x: Int): String = "OpenClassImpl.newNonInlineFunction($x)" // overrides accidentally appeared non-inline function
} }
fun suspendToNonSuspendFunctionInInterface(i: Interface, x: Int): String = runCoroutine { i.suspendToNonSuspendFunction(x) } fun suspendToNonSuspendFunctionInInterface(i: Interface, x: Int): String = runCoroutine { i.suspendToNonSuspendFunction(x) }
@@ -1,3 +1,5 @@
@file:Suppress("NOTHING_TO_INLINE")
fun getInterfaceToAbstractClass() = object : InterfaceToAbstractClass {} fun getInterfaceToAbstractClass() = object : InterfaceToAbstractClass {}
inline fun getInterfaceToAbstractClassInline() = object : InterfaceToAbstractClass {} inline fun getInterfaceToAbstractClassInline() = object : InterfaceToAbstractClass {}
fun getInterfaceToAbstractClassAsAny(): Any = object : InterfaceToAbstractClass {} fun getInterfaceToAbstractClassAsAny(): Any = object : InterfaceToAbstractClass {}
+2 -2
View File
@@ -5,8 +5,8 @@ fun readRemovedOrNormalProperty(removed: Boolean): String = if (removed) removed
fun readRemovedOrNormalPropertyOnObject1(removed: Boolean): String = if (removed) A().removedProperty1 else A().property1 fun readRemovedOrNormalPropertyOnObject1(removed: Boolean): String = if (removed) A().removedProperty1 else A().property1
fun readRemovedOrNormalPropertyOnObject2(removed: Boolean): String = if (removed) A().removedProperty2 else A().property2 fun readRemovedOrNormalPropertyOnObject2(removed: Boolean): String = if (removed) A().removedProperty2 else A().property2
inline fun callInlinedRemovedFunction() = removedFunction() @Suppress("NOTHING_TO_INLINE") inline fun callInlinedRemovedFunction() = removedFunction()
inline fun readInlinedRemovedProperty() = removedProperty @Suppress("NOTHING_TO_INLINE") inline fun readInlinedRemovedProperty() = removedProperty
class C2 : C() { class C2 : C() {
override fun removedOpenFunction(): String = "O" // does not call super override fun removedOpenFunction(): String = "O" // does not call super
+2
View File
@@ -1,3 +1,5 @@
@file:Suppress("NOTHING_TO_INLINE")
fun createRemovedClass() { fun createRemovedClass() {
check(RemovedClass().toString() != "Yellow Submarine") check(RemovedClass().toString() != "Yellow Submarine")
} }
@@ -26,8 +26,8 @@ object PartialLinkageTestUtils {
// Build a KLIB from a module. // Build a KLIB from a module.
fun buildKlib(moduleName: String, buildDirs: ModuleBuildDirs, dependencies: Dependencies, klibFile: File) fun buildKlib(moduleName: String, buildDirs: ModuleBuildDirs, dependencies: Dependencies, klibFile: File)
// Build a binary (executable) file given the main KLIB and dependencies. // Build a binary (executable) file given the main KLIB and the rest of dependencies.
fun buildBinaryAndRun(mainModuleKlibFile: File, dependencies: Dependencies) fun buildBinaryAndRun(mainModule: Dependency, otherDependencies: Dependencies)
// Take measures if the build directory is non-empty before the compilation // Take measures if the build directory is non-empty before the compilation
// (ex: backup the previously generated artifacts stored in the build directory). // (ex: backup the previously generated artifacts stored in the build directory).
@@ -163,9 +163,8 @@ object PartialLinkageTestUtils {
val mainModuleKlibFile = modulesMap[MAIN_MODULE_NAME]?.klibFile ?: fail { "No main module $MAIN_MODULE_NAME found" } val mainModuleKlibFile = modulesMap[MAIN_MODULE_NAME]?.klibFile ?: fail { "No main module $MAIN_MODULE_NAME found" }
val mainModuleDependency = Dependency(MAIN_MODULE_NAME, mainModuleKlibFile) val mainModuleDependency = Dependency(MAIN_MODULE_NAME, mainModuleKlibFile)
binaryDependencies = binaryDependencies.mergeWith(Dependencies(setOf(mainModuleDependency), emptySet()))
buildBinaryAndRun(mainModuleKlibFile, binaryDependencies) buildBinaryAndRun(mainModuleDependency, binaryDependencies)
} }
private fun copySources(from: File, to: File, patchSourceFile: ((String) -> String)? = null) { private fun copySources(from: File, to: File, patchSourceFile: ((String) -> String)? = null) {
@@ -13,6 +13,7 @@ import org.jetbrains.kotlin.ir.backend.js.*
import org.jetbrains.kotlin.js.testOld.V8IrJsTestChecker import org.jetbrains.kotlin.js.testOld.V8IrJsTestChecker
import org.jetbrains.kotlin.klib.PartialLinkageTestUtils import org.jetbrains.kotlin.klib.PartialLinkageTestUtils
import org.jetbrains.kotlin.klib.PartialLinkageTestUtils.Dependencies import org.jetbrains.kotlin.klib.PartialLinkageTestUtils.Dependencies
import org.jetbrains.kotlin.klib.PartialLinkageTestUtils.Dependency
import org.jetbrains.kotlin.klib.PartialLinkageTestUtils.MAIN_MODULE_NAME import org.jetbrains.kotlin.klib.PartialLinkageTestUtils.MAIN_MODULE_NAME
import org.jetbrains.kotlin.klib.PartialLinkageTestUtils.ModuleBuildDirs import org.jetbrains.kotlin.klib.PartialLinkageTestUtils.ModuleBuildDirs
import org.junit.jupiter.api.AfterEach import org.junit.jupiter.api.AfterEach
@@ -60,8 +61,8 @@ abstract class AbstractJsPartialLinkageTestCase(private val compilerType: Compil
klibFile: File, klibFile: File,
) = this@AbstractJsPartialLinkageTestCase.buildKlib(moduleName, buildDirs, dependencies, klibFile) ) = this@AbstractJsPartialLinkageTestCase.buildKlib(moduleName, buildDirs, dependencies, klibFile)
override fun buildBinaryAndRun(mainModuleKlibFile: File, dependencies: Dependencies) = override fun buildBinaryAndRun(mainModule: Dependency, otherDependencies: Dependencies) =
this@AbstractJsPartialLinkageTestCase.buildBinaryAndRun(mainModuleKlibFile, dependencies) this@AbstractJsPartialLinkageTestCase.buildBinaryAndRun(mainModule, otherDependencies)
override fun onNonEmptyBuildDirectory(directory: File) { override fun onNonEmptyBuildDirectory(directory: File) {
directory.listFiles()?.forEach(File::deleteRecursively) directory.listFiles()?.forEach(File::deleteRecursively)
@@ -110,19 +111,24 @@ abstract class AbstractJsPartialLinkageTestCase(private val compilerType: Compil
listOf( listOf(
"-Xir-produce-klib-file", "-Xir-produce-klib-file",
"-ir-output-dir", klibFile.parentFile.absolutePath, "-ir-output-dir", klibFile.parentFile.absolutePath,
"-ir-output-name", moduleName "-ir-output-name", moduleName,
"-Werror" // Halt on any unexpected warning.
), ),
dependencies.toCompilerArgs(), dependencies.toCompilerArgs(),
listOf("-language-version", "2.0").takeIf { compilerType.useFir }, listOf(
"-language-version", "2.0",
"-Xsuppress-version-warnings" // Don't fail on language version warnings.
).takeIf { compilerType.useFir },
kotlinSourceFilePaths kotlinSourceFilePaths
) )
} }
private fun buildBinaryAndRun(mainModuleKlibFile: File, allDependencies: Dependencies) { private fun buildBinaryAndRun(mainModule: Dependency, otherDependencies: Dependencies) {
// The modules in `Dependencies.regularDependencies` are already in topological order. // The modules in `Dependencies.regularDependencies` are already in topological order.
// It is important to pass the provided and the produced JS files to Node in exactly the same order. // It is important to pass the provided and the produced JS files to Node in exactly the same order.
val knownModulesInTopologicalOrder: List<ModuleDetails> = allDependencies.regularDependencies.map { dependency -> val knownModulesInTopologicalOrder: List<ModuleDetails> = buildList {
ModuleDetails(name = dependency.moduleName, outputDir = dependency.libraryFile.parentFile) otherDependencies.regularDependencies.mapTo(this, ::ModuleDetails)
this += ModuleDetails(mainModule)
} }
val knownModuleNames: Set<ModuleName> = knownModulesInTopologicalOrder.mapTo(hashSetOf(), ModuleDetails::name) val knownModuleNames: Set<ModuleName> = knownModulesInTopologicalOrder.mapTo(hashSetOf(), ModuleDetails::name)
@@ -133,20 +139,19 @@ abstract class AbstractJsPartialLinkageTestCase(private val compilerType: Compil
"-Xir-produce-js", "-Xir-produce-js",
"-Xir-per-module", "-Xir-per-module",
"-module-kind", "plain", "-module-kind", "plain",
"-Xinclude=${mainModuleKlibFile.absolutePath}", "-Xinclude=${mainModule.libraryFile.absolutePath}",
"-ir-output-dir", binariesDir.absolutePath, "-ir-output-dir", binariesDir.absolutePath,
"-ir-output-name", MAIN_MODULE_NAME "-ir-output-name", MAIN_MODULE_NAME,
// IMPORTANT: Omitting PL arguments here. The default PL mode should be in effect.
// "-Xpartial-linkage=enable", "-Xpartial-linkage-loglevel=INFO",
"-Werror"
), ),
listOf( listOf(
"-Xcache-directory", "-Xcache-directory",
buildDir.resolve("libs-cache").absolutePath buildDir.resolve("libs-cache").absolutePath
).takeIf { compilerType.useIc }, ).takeIf { compilerType.useIc },
allDependencies.toCompilerArgs(), otherDependencies.toCompilerArgs(),
listOf("-Xes-classes").takeIf { compilerType.es6Mode }, listOf("-Xes-classes").takeIf { compilerType.es6Mode }
listOf(
"-Xpartial-linkage=enable",
"-Xpartial-linkage-loglevel=WARNING"
)
) )
// All JS files produced during the compiler call. // All JS files produced during the compiler call.
@@ -225,4 +230,6 @@ abstract class AbstractJsPartialLinkageTestCase(private val compilerType: Compil
} }
private typealias ModuleName = String private typealias ModuleName = String
private class ModuleDetails(val name: ModuleName, val outputDir: File) private class ModuleDetails(val name: ModuleName, val outputDir: File) {
constructor(dependency: Dependency) : this(dependency.moduleName, dependency.libraryFile.parentFile)
}
@@ -9,6 +9,7 @@ import com.intellij.testFramework.TestDataFile
import org.jetbrains.kotlin.codegen.ProjectInfo import org.jetbrains.kotlin.codegen.ProjectInfo
import org.jetbrains.kotlin.klib.PartialLinkageTestUtils import org.jetbrains.kotlin.klib.PartialLinkageTestUtils
import org.jetbrains.kotlin.klib.PartialLinkageTestUtils.Dependencies import org.jetbrains.kotlin.klib.PartialLinkageTestUtils.Dependencies
import org.jetbrains.kotlin.klib.PartialLinkageTestUtils.Dependency
import org.jetbrains.kotlin.klib.PartialLinkageTestUtils.MAIN_MODULE_NAME import org.jetbrains.kotlin.klib.PartialLinkageTestUtils.MAIN_MODULE_NAME
import org.jetbrains.kotlin.klib.PartialLinkageTestUtils.ModuleBuildDirs import org.jetbrains.kotlin.klib.PartialLinkageTestUtils.ModuleBuildDirs
import org.jetbrains.kotlin.konan.blackboxtest.support.* import org.jetbrains.kotlin.konan.blackboxtest.support.*
@@ -62,8 +63,8 @@ abstract class AbstractNativePartialLinkageTest : AbstractNativeSimpleTest() {
klibFile: File klibFile: File
) = this@AbstractNativePartialLinkageTest.buildKlib(moduleName, buildDirs.sourceDir, dependencies, klibFile) ) = this@AbstractNativePartialLinkageTest.buildKlib(moduleName, buildDirs.sourceDir, dependencies, klibFile)
override fun buildBinaryAndRun(mainModuleKlibFile: File, dependencies: Dependencies) = override fun buildBinaryAndRun(mainModule: Dependency, otherDependencies: Dependencies) =
this@AbstractNativePartialLinkageTest.buildBinaryAndRun(dependencies) this@AbstractNativePartialLinkageTest.buildBinaryAndRun(mainModule, otherDependencies)
override fun onNonEmptyBuildDirectory(directory: File) = backupDirectoryContents(directory) override fun onNonEmptyBuildDirectory(directory: File) = backupDirectoryContents(directory)
@@ -103,7 +104,7 @@ abstract class AbstractNativePartialLinkageTest : AbstractNativeSimpleTest() {
settings = testRunSettings, settings = testRunSettings,
freeCompilerArgs = testCase.freeCompilerArgs, freeCompilerArgs = testCase.freeCompilerArgs,
sourceModules = testCase.modules, sourceModules = testCase.modules,
dependencies = createLibraryDependencies(dependencies, forExecutable = false), dependencies = createLibraryDependencies(dependencies),
expectedArtifact = klibArtifact expectedArtifact = klibArtifact
) )
@@ -112,7 +113,7 @@ abstract class AbstractNativePartialLinkageTest : AbstractNativeSimpleTest() {
producedKlibs += ProducedKlib(moduleName, klibArtifact, dependencies) // Remember the artifact with its dependencies. producedKlibs += ProducedKlib(moduleName, klibArtifact, dependencies) // Remember the artifact with its dependencies.
} }
private fun buildBinaryAndRun(allDependencies: Dependencies) { private fun buildBinaryAndRun(mainModule: Dependency, otherDependencies: Dependencies) {
val cacheDependencies = if (useStaticCacheForUserLibraries) { val cacheDependencies = if (useStaticCacheForUserLibraries) {
producedKlibs.map { producedKlib -> producedKlibs.map { producedKlib ->
buildCacheForKlib(producedKlib) buildCacheForKlib(producedKlib)
@@ -132,7 +133,11 @@ abstract class AbstractNativePartialLinkageTest : AbstractNativeSimpleTest() {
freeCompilerArgs = testCase.freeCompilerArgs, freeCompilerArgs = testCase.freeCompilerArgs,
sourceModules = testCase.modules, sourceModules = testCase.modules,
extras = testCase.extras, extras = testCase.extras,
dependencies = createLibraryDependencies(allDependencies, forExecutable = true) + cacheDependencies, dependencies = buildList {
this += createIncludedDependency(mainModule)
this += createLibraryDependencies(otherDependencies)
this += cacheDependencies
},
expectedArtifact = executableArtifact expectedArtifact = executableArtifact
) )
@@ -187,20 +192,17 @@ abstract class AbstractNativePartialLinkageTest : AbstractNativeSimpleTest() {
} }
} }
private fun createLibraryDependencies( private fun createIncludedDependency(dependency: Dependency): TestCompilationDependency<KLIB> =
dependencies: Dependencies, KLIB(dependency.libraryFile).toIncludedDependency()
forExecutable: Boolean
): Iterable<TestCompilationDependency<KLIB>> =
dependencies.regularDependencies.map { dependency ->
val klib = KLIB(dependency.libraryFile)
if (forExecutable && dependency.moduleName == MAIN_MODULE_NAME) klib.toIncludedDependency() else klib.toDependency()
} + dependencies.friendDependencies.map { KLIB(it.libraryFile).toFriendDependency() }
private fun createLibraryCacheDependencies( private fun createLibraryDependencies(dependencies: Dependencies): Iterable<TestCompilationDependency<KLIB>> =
dependencies: Dependencies dependencies.regularDependencies.map { dependency -> KLIB(dependency.libraryFile).toDependency() } +
): Iterable<TestCompilationDependency<KLIBStaticCache>> = dependencies.regularDependencies.mapNotNull { dependency -> dependencies.friendDependencies.map { KLIB(it.libraryFile).toFriendDependency() }
if (dependency.libraryFile != stdlibFile) KLIB(dependency.libraryFile).toStaticCacheArtifact().toDependency() else null
} private fun createLibraryCacheDependencies(dependencies: Dependencies): Iterable<TestCompilationDependency<KLIBStaticCache>> =
dependencies.regularDependencies.mapNotNull { dependency ->
if (dependency.libraryFile != stdlibFile) KLIB(dependency.libraryFile).toStaticCacheArtifact().toDependency() else null
}
private fun KLIB.toDependency() = ExistingDependency(this, Library) private fun KLIB.toDependency() = ExistingDependency(this, Library)
private fun KLIB.toIncludedDependency() = ExistingDependency(this, IncludedLibrary) private fun KLIB.toIncludedDependency() = ExistingDependency(this, IncludedLibrary)