[libraries] Move SearchPathResolver into shared
This commit is contained in:
@@ -20,7 +20,7 @@ import com.intellij.openapi.Disposable
|
||||
import org.jetbrains.annotations.NotNull
|
||||
import org.jetbrains.annotations.Nullable
|
||||
import org.jetbrains.kotlin.backend.konan.*
|
||||
import org.jetbrains.kotlin.backend.konan.util.profile
|
||||
import org.jetbrains.kotlin.konan.util.profile
|
||||
import org.jetbrains.kotlin.cli.common.CLICompiler
|
||||
import org.jetbrains.kotlin.cli.common.CLITool
|
||||
import org.jetbrains.kotlin.cli.common.CommonCompilerPerformanceManager
|
||||
|
||||
+2
-1
@@ -20,7 +20,6 @@ import com.intellij.openapi.project.Project
|
||||
import org.jetbrains.kotlin.backend.konan.descriptors.createForwardDeclarationsModule
|
||||
import org.jetbrains.kotlin.backend.konan.library.*
|
||||
import org.jetbrains.kotlin.backend.konan.library.impl.*
|
||||
import org.jetbrains.kotlin.backend.konan.util.*
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
import org.jetbrains.kotlin.cli.common.CLIConfigurationKeys
|
||||
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity
|
||||
@@ -32,7 +31,9 @@ import org.jetbrains.kotlin.descriptors.impl.ModuleDescriptorImpl
|
||||
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
|
||||
import org.jetbrains.kotlin.konan.TempFiles
|
||||
import org.jetbrains.kotlin.konan.file.File
|
||||
import org.jetbrains.kotlin.konan.library.defaultResolver
|
||||
import org.jetbrains.kotlin.konan.target.*
|
||||
import org.jetbrains.kotlin.konan.util.profile
|
||||
import org.jetbrains.kotlin.storage.LockBasedStorageManager
|
||||
import org.jetbrains.kotlin.storage.StorageManager
|
||||
|
||||
|
||||
+1
-2
@@ -16,7 +16,6 @@
|
||||
|
||||
package org.jetbrains.kotlin.backend.konan
|
||||
|
||||
import org.jetbrains.kotlin.backend.konan.util.*
|
||||
import org.jetbrains.kotlin.konan.util.*
|
||||
import org.jetbrains.kotlin.konan.target.CompilerOutputKind
|
||||
|
||||
@@ -137,7 +136,7 @@ internal class PhaseManager(val context: Context) {
|
||||
|
||||
with (context) {
|
||||
profileIf(shouldProfilePhases(), "Phase ${nTabs(depth)} ${phase.name}") {
|
||||
body()
|
||||
body()
|
||||
}
|
||||
|
||||
if (shouldVerifyDescriptors()) {
|
||||
|
||||
+3
-3
@@ -15,9 +15,9 @@
|
||||
*/
|
||||
package org.jetbrains.kotlin.backend.konan
|
||||
|
||||
import org.jetbrains.kotlin.backend.konan.util.prefixBaseNameIfNot
|
||||
import org.jetbrains.kotlin.backend.konan.util.removeSuffixIfPresent
|
||||
import org.jetbrains.kotlin.backend.konan.util.suffixIfNot
|
||||
import org.jetbrains.kotlin.konan.util.prefixBaseNameIfNot
|
||||
import org.jetbrains.kotlin.konan.util.removeSuffixIfPresent
|
||||
import org.jetbrains.kotlin.konan.util.suffixIfNot
|
||||
import org.jetbrains.kotlin.konan.file.File
|
||||
import org.jetbrains.kotlin.konan.target.CompilerOutputKind
|
||||
import org.jetbrains.kotlin.konan.target.KonanTarget
|
||||
|
||||
+1
-1
@@ -16,7 +16,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.backend.konan.descriptors
|
||||
|
||||
import org.jetbrains.kotlin.backend.konan.util.nTabs
|
||||
import org.jetbrains.kotlin.konan.util.nTabs
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
|
||||
class DeepPrintVisitor(worker: DeclarationDescriptorVisitor<Boolean, Int>): DeepVisitor<Int>(worker) {
|
||||
|
||||
+1
-95
@@ -17,29 +17,10 @@
|
||||
package org.jetbrains.kotlin.backend.konan.library
|
||||
|
||||
import org.jetbrains.kotlin.backend.konan.library.impl.LibraryReaderImpl
|
||||
import org.jetbrains.kotlin.backend.konan.util.removeSuffixIfPresent
|
||||
import org.jetbrains.kotlin.backend.konan.util.suffixIfNot
|
||||
import org.jetbrains.kotlin.konan.file.File
|
||||
import org.jetbrains.kotlin.konan.target.Distribution
|
||||
import org.jetbrains.kotlin.konan.library.SearchPathResolver
|
||||
import org.jetbrains.kotlin.konan.target.KonanTarget
|
||||
|
||||
interface SearchPathResolver {
|
||||
val searchRoots: List<File>
|
||||
fun resolve(givenPath: String): File
|
||||
fun defaultLinks(nostdlib: Boolean, noDefaultLibs: Boolean): List<File>
|
||||
}
|
||||
|
||||
fun defaultResolver(repositories: List<String>, target: KonanTarget): SearchPathResolver =
|
||||
defaultResolver(repositories, target, Distribution())
|
||||
|
||||
fun defaultResolver(repositories: List<String>, target: KonanTarget, distribution: Distribution): SearchPathResolver =
|
||||
KonanLibrarySearchPathResolver(
|
||||
repositories,
|
||||
target,
|
||||
distribution.klib,
|
||||
distribution.localKonanDir.absolutePath
|
||||
)
|
||||
|
||||
fun SearchPathResolver.resolveImmediateLibraries(libraryNames: List<String>,
|
||||
target: KonanTarget,
|
||||
abiVersion: Int = 1,
|
||||
@@ -129,78 +110,3 @@ fun SearchPathResolver.resolveLibrariesRecursive(libraryNames: List<String>,
|
||||
resolveLibrariesRecursive(immediateLibraries, target, abiVersion)
|
||||
return immediateLibraries.withResolvedDependencies()
|
||||
}
|
||||
|
||||
class KonanLibrarySearchPathResolver(
|
||||
repositories: List<String>,
|
||||
val target: KonanTarget?,
|
||||
val distributionKlib: String?,
|
||||
val localKonanDir: String?,
|
||||
val skipCurrentDir: Boolean = false
|
||||
): SearchPathResolver {
|
||||
|
||||
val localHead: File?
|
||||
get() = localKonanDir?.File()?.klib
|
||||
|
||||
val distHead: File?
|
||||
get() = distributionKlib?.File()?.child("common")
|
||||
|
||||
val distPlatformHead: File?
|
||||
get() = target?.let { distributionKlib?.File()?.child("platform")?.child(target.visibleName) }
|
||||
|
||||
val currentDirHead: File?
|
||||
get() = if (!skipCurrentDir) File.userDir else null
|
||||
|
||||
private val repoRoots: List<File> by lazy {
|
||||
repositories.map{File(it)}
|
||||
}
|
||||
|
||||
// This is the place where we specify the order of library search.
|
||||
override val searchRoots: List<File> by lazy {
|
||||
(listOf(currentDirHead) + repoRoots + listOf(localHead, distHead, distPlatformHead)).filterNotNull()
|
||||
}
|
||||
|
||||
private fun found(candidate: File): File? {
|
||||
fun check(file: File): Boolean =
|
||||
file.exists && (file.isFile || File(file, "manifest").exists)
|
||||
|
||||
val noSuffix = File(candidate.path.removeSuffixIfPresent(".klib"))
|
||||
val withSuffix = File(candidate.path.suffixIfNot(".klib"))
|
||||
return when {
|
||||
check(withSuffix) -> withSuffix
|
||||
check(noSuffix) -> noSuffix
|
||||
else -> null
|
||||
}
|
||||
}
|
||||
|
||||
override fun resolve(givenPath: String): File {
|
||||
val given = File(givenPath)
|
||||
if (given.isAbsolute) {
|
||||
found(given)?.apply{ return this }
|
||||
} else {
|
||||
searchRoots.forEach{
|
||||
found(File(it, givenPath))?.apply{return this}
|
||||
}
|
||||
}
|
||||
error("Could not find \"$givenPath\" in ${searchRoots.map{it.absolutePath}}.")
|
||||
}
|
||||
|
||||
private val File.klib
|
||||
get() = File(this, "klib")
|
||||
|
||||
// The libraries from the default root are linked automatically.
|
||||
val defaultRoots: List<File>
|
||||
get() = listOf(distHead, distPlatformHead)
|
||||
.filterNotNull()
|
||||
.filter{ it.exists }
|
||||
|
||||
override fun defaultLinks(nostdlib: Boolean, noDefaultLibs: Boolean): List<File> {
|
||||
val defaultLibs = defaultRoots.flatMap{ it.listFiles }
|
||||
.filterNot { it.name.removeSuffixIfPresent(".klib") == "stdlib" }
|
||||
.map { File(it.absolutePath) }
|
||||
val result = mutableListOf<File>()
|
||||
if (!nostdlib) result.add(resolve("stdlib"))
|
||||
if (!noDefaultLibs) result.addAll(defaultLibs)
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -17,7 +17,7 @@
|
||||
package org.jetbrains.kotlin.backend.konan.library.impl
|
||||
|
||||
import org.jetbrains.kotlin.backend.konan.library.KonanLibrary
|
||||
import org.jetbrains.kotlin.backend.konan.util.removeSuffixIfPresent
|
||||
import org.jetbrains.kotlin.konan.util.removeSuffixIfPresent
|
||||
import org.jetbrains.kotlin.konan.file.*
|
||||
import org.jetbrains.kotlin.konan.target.KonanTarget
|
||||
|
||||
|
||||
@@ -18,7 +18,6 @@ package org.jetbrains.kotlin.cli.klib
|
||||
|
||||
// TODO: Extract `library` package as a shared jar?
|
||||
import org.jetbrains.kotlin.backend.konan.isStdlib
|
||||
import org.jetbrains.kotlin.backend.konan.library.KonanLibrarySearchPathResolver
|
||||
import org.jetbrains.kotlin.backend.konan.library.impl.LibraryReaderImpl
|
||||
import org.jetbrains.kotlin.backend.konan.library.impl.UnzippedKonanLibrary
|
||||
import org.jetbrains.kotlin.backend.konan.library.impl.ZippedKonanLibrary
|
||||
@@ -28,6 +27,7 @@ import org.jetbrains.kotlin.config.LanguageVersion
|
||||
import org.jetbrains.kotlin.config.LanguageVersionSettingsImpl
|
||||
import org.jetbrains.kotlin.descriptors.impl.ModuleDescriptorImpl
|
||||
import org.jetbrains.kotlin.konan.file.File
|
||||
import org.jetbrains.kotlin.konan.library.KonanLibrarySearchPathResolver
|
||||
import org.jetbrains.kotlin.konan.target.Distribution
|
||||
import org.jetbrains.kotlin.konan.target.PlatformManager
|
||||
import org.jetbrains.kotlin.konan.util.DependencyProcessor
|
||||
|
||||
@@ -0,0 +1,99 @@
|
||||
package org.jetbrains.kotlin.konan.library
|
||||
|
||||
import org.jetbrains.kotlin.konan.file.File
|
||||
import org.jetbrains.kotlin.konan.target.Distribution
|
||||
import org.jetbrains.kotlin.konan.target.KonanTarget
|
||||
import org.jetbrains.kotlin.konan.util.removeSuffixIfPresent
|
||||
import org.jetbrains.kotlin.konan.util.suffixIfNot
|
||||
|
||||
|
||||
interface SearchPathResolver {
|
||||
val searchRoots: List<File>
|
||||
fun resolve(givenPath: String): File
|
||||
fun defaultLinks(nostdlib: Boolean, noDefaultLibs: Boolean): List<File>
|
||||
}
|
||||
|
||||
fun defaultResolver(repositories: List<String>, target: KonanTarget): SearchPathResolver =
|
||||
defaultResolver(repositories, target, Distribution())
|
||||
|
||||
fun defaultResolver(repositories: List<String>, target: KonanTarget, distribution: Distribution): SearchPathResolver =
|
||||
KonanLibrarySearchPathResolver(
|
||||
repositories,
|
||||
target,
|
||||
distribution.klib,
|
||||
distribution.localKonanDir.absolutePath
|
||||
)
|
||||
|
||||
class KonanLibrarySearchPathResolver(
|
||||
repositories: List<String>,
|
||||
val target: KonanTarget?,
|
||||
val distributionKlib: String?,
|
||||
val localKonanDir: String?,
|
||||
val skipCurrentDir: Boolean = false
|
||||
): SearchPathResolver {
|
||||
|
||||
val localHead: File?
|
||||
get() = localKonanDir?.File()?.klib
|
||||
|
||||
val distHead: File?
|
||||
get() = distributionKlib?.File()?.child("common")
|
||||
|
||||
val distPlatformHead: File?
|
||||
get() = target?.let { distributionKlib?.File()?.child("platform")?.child(target.visibleName) }
|
||||
|
||||
val currentDirHead: File?
|
||||
get() = if (!skipCurrentDir) File.userDir else null
|
||||
|
||||
private val repoRoots: List<File> by lazy {
|
||||
repositories.map{File(it)}
|
||||
}
|
||||
|
||||
// This is the place where we specify the order of library search.
|
||||
override val searchRoots: List<File> by lazy {
|
||||
(listOf(currentDirHead) + repoRoots + listOf(localHead, distHead, distPlatformHead)).filterNotNull()
|
||||
}
|
||||
|
||||
private fun found(candidate: File): File? {
|
||||
fun check(file: File): Boolean =
|
||||
file.exists && (file.isFile || File(file, "manifest").exists)
|
||||
|
||||
val noSuffix = File(candidate.path.removeSuffixIfPresent(".klib"))
|
||||
val withSuffix = File(candidate.path.suffixIfNot(".klib"))
|
||||
return when {
|
||||
check(withSuffix) -> withSuffix
|
||||
check(noSuffix) -> noSuffix
|
||||
else -> null
|
||||
}
|
||||
}
|
||||
|
||||
override fun resolve(givenPath: String): File {
|
||||
val given = File(givenPath)
|
||||
if (given.isAbsolute) {
|
||||
found(given)?.apply{ return this }
|
||||
} else {
|
||||
searchRoots.forEach{
|
||||
found(File(it, givenPath))?.apply{return this}
|
||||
}
|
||||
}
|
||||
error("Could not find \"$givenPath\" in ${searchRoots.map{it.absolutePath}}.")
|
||||
}
|
||||
|
||||
private val File.klib
|
||||
get() = File(this, "klib")
|
||||
|
||||
// The libraries from the default root are linked automatically.
|
||||
val defaultRoots: List<File>
|
||||
get() = listOf(distHead, distPlatformHead)
|
||||
.filterNotNull()
|
||||
.filter{ it.exists }
|
||||
|
||||
override fun defaultLinks(nostdlib: Boolean, noDefaultLibs: Boolean): List<File> {
|
||||
val defaultLibs = defaultRoots.flatMap{ it.listFiles }
|
||||
.filterNot { it.name.removeSuffixIfPresent(".klib") == "stdlib" }
|
||||
.map { File(it.absolutePath) }
|
||||
val result = mutableListOf<File>()
|
||||
if (!nostdlib) result.add(resolve("stdlib"))
|
||||
if (!noDefaultLibs) result.addAll(defaultLibs)
|
||||
return result
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.backend.konan.util
|
||||
package org.jetbrains.kotlin.konan.util
|
||||
|
||||
import kotlin.system.measureTimeMillis
|
||||
import org.jetbrains.kotlin.konan.file.*
|
||||
@@ -16,11 +16,11 @@
|
||||
|
||||
package org.jetbrains.kotlin.cli.utilities
|
||||
|
||||
import org.jetbrains.kotlin.backend.konan.library.defaultResolver
|
||||
import org.jetbrains.kotlin.backend.konan.library.impl.KonanLibrary
|
||||
import org.jetbrains.kotlin.backend.konan.library.resolveLibrariesRecursive
|
||||
import org.jetbrains.kotlin.konan.TempFiles
|
||||
import org.jetbrains.kotlin.konan.file.File
|
||||
import org.jetbrains.kotlin.konan.library.defaultResolver
|
||||
import org.jetbrains.kotlin.konan.properties.loadProperties
|
||||
import org.jetbrains.kotlin.konan.target.PlatformManager
|
||||
import org.jetbrains.kotlin.native.interop.gen.jvm.interop
|
||||
|
||||
Reference in New Issue
Block a user