From 6b6bc7d6fe5896aceb3895e62013799f4308e1d9 Mon Sep 17 00:00:00 2001 From: Dmitriy Dolovov Date: Fri, 26 Aug 2022 23:09:04 +0200 Subject: [PATCH] [Native][tests] Fix: Pass friend modules to compiler CLI when building static cache ^KT-53723 --- .../support/compilation/TestCompilation.kt | 20 +++++++++---------- .../compilation/TestCompilationDependency.kt | 2 -- .../compilation/TestCompilationFactory.kt | 2 +- 3 files changed, 11 insertions(+), 13 deletions(-) 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 6fd911c5f3f..691ace3e187 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 @@ -321,6 +321,9 @@ internal class StaticCacheCompilation( } override fun applyDependencies(argsBuilder: ArgsBuilder): Unit = with(argsBuilder) { + dependencies.friends.takeIf(Collection<*>::isNotEmpty)?.let { friends -> + add("-friend-modules", friends.joinToString(File.pathSeparator) { friend -> friend.path }) + } addFlattened(dependencies.cachedLibraries) { (_, library) -> listOf("-l", library.path) } add(dependencies.uniqueCacheDirs) { libraryCacheDir -> "-Xcache-directory=${libraryCacheDir.path}" } } @@ -349,8 +352,12 @@ internal class CategorizedDependencies(uncategorizedDependencies: Iterable by lazy { uncategorizedDependencies.collectArtifacts() } val libraryToCache: KLIB by lazy { - val libraries = uncategorizedDependencies.collectArtifacts>() - libraries.singleOrNull() + val libraries: List = buildList { + this += libraries + this += includedLibraries + if (isEmpty()) this += friends // Friends should be ignored if they come with the main library. + } + libraries.singleOrNull() ?: fail { "Only one library is expected as input for ${StaticCacheCompilation::class.java}, found: $libraries" } } @@ -359,14 +366,7 @@ internal class CategorizedDependencies(uncategorizedDependencies: Iterable> Iterable>.collectArtifacts(): List { - val concreteDependencyType = T::class.objectInstance - val dependencyTypeMatcher: (TestCompilationDependencyType<*>) -> Boolean = if (concreteDependencyType != null) { - { it == concreteDependencyType } - } else { - { it.canYield(A::class.java) } - } - - return mapNotNull { dependency -> if (dependencyTypeMatcher(dependency.type)) dependency.artifact as A else null } + return mapNotNull { dependency -> if (dependency.type is T) dependency.artifact as A else null } } } diff --git a/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/compilation/TestCompilationDependency.kt b/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/compilation/TestCompilationDependency.kt index 68edf1744ac..d736befc47f 100644 --- a/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/compilation/TestCompilationDependency.kt +++ b/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/compilation/TestCompilationDependency.kt @@ -17,8 +17,6 @@ import org.jetbrains.kotlin.konan.blackboxtest.support.compilation.TestCompilati * [IncludedLibrary] - similarly but included modules (-Xinclude). */ internal sealed class TestCompilationDependencyType(private val artifactClass: Class) { - fun canYield(artifactClass: Class): Boolean = this.artifactClass.isAssignableFrom(artifactClass) - object Library : TestCompilationDependencyType(KLIB::class.java) object FriendLibrary : TestCompilationDependencyType(KLIB::class.java) object IncludedLibrary : TestCompilationDependencyType(KLIB::class.java) 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 e6443cbb79a..6902d43734c 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 @@ -39,7 +39,7 @@ internal class TestCompilationFactory { /** Dependencies needed to compile KLIB static cache. */ fun forStaticCache(klib: CompiledDependency): Iterable> = - (staticCacheDependencies.asSequence() + klib).asIterable() + (klibDependencies.asSequence().filter { it.type == FriendLibrary } + klib + staticCacheDependencies).asIterable() /** Dependencies needed to compile one-stage executable. */ fun forOneStageExecutable(): Iterable> =