[Native][tests] Fix: Pass friend modules to compiler CLI when building static cache

^KT-53723
This commit is contained in:
Dmitriy Dolovov
2022-08-26 23:09:04 +02:00
committed by Space
parent ea4a841056
commit 6b6bc7d6fe
3 changed files with 11 additions and 13 deletions
@@ -321,6 +321,9 @@ internal class StaticCacheCompilation(
} }
override fun applyDependencies(argsBuilder: ArgsBuilder): Unit = with(argsBuilder) { 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) } addFlattened(dependencies.cachedLibraries) { (_, library) -> listOf("-l", library.path) }
add(dependencies.uniqueCacheDirs) { libraryCacheDir -> "-Xcache-directory=${libraryCacheDir.path}" } add(dependencies.uniqueCacheDirs) { libraryCacheDir -> "-Xcache-directory=${libraryCacheDir.path}" }
} }
@@ -349,8 +352,12 @@ internal class CategorizedDependencies(uncategorizedDependencies: Iterable<TestC
val cachedLibraries: List<KLIBStaticCache> by lazy { uncategorizedDependencies.collectArtifacts<KLIBStaticCache, LibraryStaticCache>() } val cachedLibraries: List<KLIBStaticCache> by lazy { uncategorizedDependencies.collectArtifacts<KLIBStaticCache, LibraryStaticCache>() }
val libraryToCache: KLIB by lazy { val libraryToCache: KLIB by lazy {
val libraries = uncategorizedDependencies.collectArtifacts<KLIB, TestCompilationDependencyType<KLIB>>() val libraries: List<KLIB> = buildList {
libraries.singleOrNull<KLIB>() 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" } ?: fail { "Only one library is expected as input for ${StaticCacheCompilation::class.java}, found: $libraries" }
} }
@@ -359,14 +366,7 @@ internal class CategorizedDependencies(uncategorizedDependencies: Iterable<TestC
} }
private inline fun <reified A : TestCompilationArtifact, reified T : TestCompilationDependencyType<A>> Iterable<TestCompilationDependency<*>>.collectArtifacts(): List<A> { private inline fun <reified A : TestCompilationArtifact, reified T : TestCompilationDependencyType<A>> Iterable<TestCompilationDependency<*>>.collectArtifacts(): List<A> {
val concreteDependencyType = T::class.objectInstance return mapNotNull { dependency -> if (dependency.type is T) dependency.artifact as A else null }
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 }
} }
} }
@@ -17,8 +17,6 @@ import org.jetbrains.kotlin.konan.blackboxtest.support.compilation.TestCompilati
* [IncludedLibrary] - similarly but included modules (-Xinclude). * [IncludedLibrary] - similarly but included modules (-Xinclude).
*/ */
internal sealed class TestCompilationDependencyType<A : TestCompilationArtifact>(private val artifactClass: Class<A>) { internal sealed class TestCompilationDependencyType<A : TestCompilationArtifact>(private val artifactClass: Class<A>) {
fun canYield(artifactClass: Class<out TestCompilationArtifact>): Boolean = this.artifactClass.isAssignableFrom(artifactClass)
object Library : TestCompilationDependencyType<KLIB>(KLIB::class.java) object Library : TestCompilationDependencyType<KLIB>(KLIB::class.java)
object FriendLibrary : TestCompilationDependencyType<KLIB>(KLIB::class.java) object FriendLibrary : TestCompilationDependencyType<KLIB>(KLIB::class.java)
object IncludedLibrary : TestCompilationDependencyType<KLIB>(KLIB::class.java) object IncludedLibrary : TestCompilationDependencyType<KLIB>(KLIB::class.java)
@@ -39,7 +39,7 @@ internal class TestCompilationFactory {
/** Dependencies needed to compile KLIB static cache. */ /** Dependencies needed to compile KLIB static cache. */
fun forStaticCache(klib: CompiledDependency<KLIB>): Iterable<CompiledDependency<*>> = fun forStaticCache(klib: CompiledDependency<KLIB>): Iterable<CompiledDependency<*>> =
(staticCacheDependencies.asSequence() + klib).asIterable() (klibDependencies.asSequence().filter { it.type == FriendLibrary } + klib + staticCacheDependencies).asIterable()
/** Dependencies needed to compile one-stage executable. */ /** Dependencies needed to compile one-stage executable. */
fun forOneStageExecutable(): Iterable<CompiledDependency<*>> = fun forOneStageExecutable(): Iterable<CompiledDependency<*>> =