[Native][tests] Fix: Pass friend modules to compiler CLI when building static cache
^KT-53723
This commit is contained in:
+10
-10
@@ -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<TestC
|
||||
val cachedLibraries: List<KLIBStaticCache> by lazy { uncategorizedDependencies.collectArtifacts<KLIBStaticCache, LibraryStaticCache>() }
|
||||
|
||||
val libraryToCache: KLIB by lazy {
|
||||
val libraries = uncategorizedDependencies.collectArtifacts<KLIB, TestCompilationDependencyType<KLIB>>()
|
||||
libraries.singleOrNull<KLIB>()
|
||||
val libraries: List<KLIB> = 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<TestC
|
||||
}
|
||||
|
||||
private inline fun <reified A : TestCompilationArtifact, reified T : TestCompilationDependencyType<A>> Iterable<TestCompilationDependency<*>>.collectArtifacts(): List<A> {
|
||||
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 }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
-2
@@ -17,8 +17,6 @@ import org.jetbrains.kotlin.konan.blackboxtest.support.compilation.TestCompilati
|
||||
* [IncludedLibrary] - similarly but included modules (-Xinclude).
|
||||
*/
|
||||
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 FriendLibrary : TestCompilationDependencyType<KLIB>(KLIB::class.java)
|
||||
object IncludedLibrary : TestCompilationDependencyType<KLIB>(KLIB::class.java)
|
||||
|
||||
+1
-1
@@ -39,7 +39,7 @@ internal class TestCompilationFactory {
|
||||
|
||||
/** Dependencies needed to compile KLIB static cache. */
|
||||
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. */
|
||||
fun forOneStageExecutable(): Iterable<CompiledDependency<*>> =
|
||||
|
||||
Reference in New Issue
Block a user