[Interop][Metadata] Fix dependency graph
We didn't filter dependency list before and blindly added all resolved dependencies into the manifest. It may result in broken compilation.
This commit is contained in:
committed by
Sergey Bogolepov
parent
e4fc21d7af
commit
5b9beec860
+15
-3
@@ -16,17 +16,29 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.native.interop.gen
|
package org.jetbrains.kotlin.native.interop.gen
|
||||||
|
|
||||||
|
import org.jetbrains.kotlin.konan.library.KonanLibrary
|
||||||
import org.jetbrains.kotlin.native.interop.indexer.*
|
import org.jetbrains.kotlin.native.interop.indexer.*
|
||||||
|
|
||||||
interface Imports {
|
interface Imports {
|
||||||
fun getPackage(location: Location): String?
|
fun getPackage(location: Location): String?
|
||||||
}
|
}
|
||||||
|
|
||||||
class ImportsImpl(internal val headerIdToPackage: Map<HeaderId, String>) : Imports {
|
|
||||||
|
|
||||||
override fun getPackage(location: Location): String? =
|
class PackageInfo(val name: String, val library: KonanLibrary)
|
||||||
headerIdToPackage[location.headerId]
|
|
||||||
|
|
||||||
|
class ImportsImpl(internal val headerIdToPackage: Map<HeaderId, PackageInfo>) : Imports {
|
||||||
|
|
||||||
|
override fun getPackage(location: Location): String? {
|
||||||
|
val packageInfo = headerIdToPackage[location.headerId]
|
||||||
|
?: return null
|
||||||
|
accessedLibraries += packageInfo.library
|
||||||
|
return packageInfo.name
|
||||||
|
}
|
||||||
|
|
||||||
|
private val accessedLibraries = mutableSetOf<KonanLibrary>()
|
||||||
|
|
||||||
|
val requiredLibraries: Set<KonanLibrary>
|
||||||
|
get() = accessedLibraries.toSet()
|
||||||
}
|
}
|
||||||
|
|
||||||
class HeaderInclusionPolicyImpl(private val nameGlobs: List<String>) : HeaderInclusionPolicy {
|
class HeaderInclusionPolicyImpl(private val nameGlobs: List<String>) : HeaderInclusionPolicy {
|
||||||
|
|||||||
+22
-8
@@ -29,6 +29,7 @@ import org.jetbrains.kotlin.konan.target.CompilerOutputKind
|
|||||||
import org.jetbrains.kotlin.konan.target.Distribution
|
import org.jetbrains.kotlin.konan.target.Distribution
|
||||||
import org.jetbrains.kotlin.konan.target.KonanTarget
|
import org.jetbrains.kotlin.konan.target.KonanTarget
|
||||||
import org.jetbrains.kotlin.library.KotlinLibrary
|
import org.jetbrains.kotlin.library.KotlinLibrary
|
||||||
|
import org.jetbrains.kotlin.library.resolver.impl.KotlinLibraryResolverImpl
|
||||||
import org.jetbrains.kotlin.library.resolver.impl.libraryResolver
|
import org.jetbrains.kotlin.library.resolver.impl.libraryResolver
|
||||||
import org.jetbrains.kotlin.library.toUnresolvedLibraries
|
import org.jetbrains.kotlin.library.toUnresolvedLibraries
|
||||||
import org.jetbrains.kotlin.util.removeSuffixIfPresent
|
import org.jetbrains.kotlin.util.removeSuffixIfPresent
|
||||||
@@ -109,7 +110,7 @@ private fun parseImports(dependencies: List<KotlinLibrary>): ImportsImpl =
|
|||||||
// TODO: handle missing properties?
|
// TODO: handle missing properties?
|
||||||
library.packageFqName?.let { packageFqName ->
|
library.packageFqName?.let { packageFqName ->
|
||||||
val headerIds = library.includedHeaders
|
val headerIds = library.includedHeaders
|
||||||
headerIds.map { HeaderId(it) to packageFqName }
|
headerIds.map { HeaderId(it) to PackageInfo(packageFqName, library) }
|
||||||
}
|
}
|
||||||
}.reversed().flatten().toMap().let(::ImportsImpl)
|
}.reversed().flatten().toMap().let(::ImportsImpl)
|
||||||
|
|
||||||
@@ -225,8 +226,10 @@ private fun processCLib(args: Array<String>, additionalArgs: Map<String, Any> =
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val resolver = getLibraryResolver(cinteropArguments, tool.target)
|
||||||
|
|
||||||
val allLibraryDependencies = when (flavor) {
|
val allLibraryDependencies = when (flavor) {
|
||||||
KotlinPlatform.NATIVE -> resolveDependencies(cinteropArguments, tool.target)
|
KotlinPlatform.NATIVE -> resolveDependencies(resolver, cinteropArguments)
|
||||||
else -> listOf()
|
else -> listOf()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -337,6 +340,11 @@ private fun processCLib(args: Array<String>, additionalArgs: Map<String, Any> =
|
|||||||
argsToCompiler(staticLibraries, libraryPaths) + bitcodePaths
|
argsToCompiler(staticLibraries, libraryPaths) + bitcodePaths
|
||||||
}
|
}
|
||||||
is StubIrDriver.Result.Metadata -> {
|
is StubIrDriver.Result.Metadata -> {
|
||||||
|
val stdlibDependency = resolver.resolveWithDependencies(
|
||||||
|
emptyList(),
|
||||||
|
noDefaultLibs = true,
|
||||||
|
noEndorsedLibs = true
|
||||||
|
).getFullList()
|
||||||
createInteropLibrary(
|
createInteropLibrary(
|
||||||
metadata = stubIrOutput.metadata,
|
metadata = stubIrOutput.metadata,
|
||||||
nativeBitcodeFiles = compiledFiles + nativeOutputPath,
|
nativeBitcodeFiles = compiledFiles + nativeOutputPath,
|
||||||
@@ -344,7 +352,7 @@ private fun processCLib(args: Array<String>, additionalArgs: Map<String, Any> =
|
|||||||
moduleName = moduleName,
|
moduleName = moduleName,
|
||||||
outputPath = cinteropArguments.output,
|
outputPath = cinteropArguments.output,
|
||||||
manifest = def.manifestAddendProperties,
|
manifest = def.manifestAddendProperties,
|
||||||
dependencies = allLibraryDependencies,
|
dependencies = stdlibDependency + imports.requiredLibraries.toList(),
|
||||||
nopack = cinteropArguments.nopack
|
nopack = cinteropArguments.nopack
|
||||||
)
|
)
|
||||||
return null
|
return null
|
||||||
@@ -366,19 +374,25 @@ private fun compileSources(
|
|||||||
outputFileName
|
outputFileName
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun resolveDependencies(
|
private fun getLibraryResolver(
|
||||||
cinteropArguments: CInteropArguments, target: KonanTarget
|
cinteropArguments: CInteropArguments, target: KonanTarget
|
||||||
): List<KotlinLibrary> {
|
): KotlinLibraryResolverImpl<KonanLibrary> {
|
||||||
val libraries = cinteropArguments.library
|
val libraries = cinteropArguments.library
|
||||||
val repos = cinteropArguments.repo
|
val repos = cinteropArguments.repo
|
||||||
val noDefaultLibs = cinteropArguments.nodefaultlibs || cinteropArguments.nodefaultlibsDeprecated
|
return defaultResolver(
|
||||||
val noEndorsedLibs = cinteropArguments.noendorsedlibs
|
|
||||||
val resolver = defaultResolver(
|
|
||||||
repos,
|
repos,
|
||||||
libraries.filter { it.contains(org.jetbrains.kotlin.konan.file.File.separator) },
|
libraries.filter { it.contains(org.jetbrains.kotlin.konan.file.File.separator) },
|
||||||
target,
|
target,
|
||||||
Distribution()
|
Distribution()
|
||||||
).libraryResolver()
|
).libraryResolver()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun resolveDependencies(
|
||||||
|
resolver: KotlinLibraryResolverImpl<KonanLibrary>, cinteropArguments: CInteropArguments
|
||||||
|
): List<KotlinLibrary> {
|
||||||
|
val libraries = cinteropArguments.library
|
||||||
|
val noDefaultLibs = cinteropArguments.nodefaultlibs || cinteropArguments.nodefaultlibsDeprecated
|
||||||
|
val noEndorsedLibs = cinteropArguments.noendorsedlibs
|
||||||
return resolver.resolveWithDependencies(
|
return resolver.resolveWithDependencies(
|
||||||
libraries.toUnresolvedLibraries,
|
libraries.toUnresolvedLibraries,
|
||||||
noStdLib = false,
|
noStdLib = false,
|
||||||
|
|||||||
Reference in New Issue
Block a user