[KLIB] Add ZIP file system accessor
The accessor interface is used for reading klib archives in place.
This commit is contained in:
committed by
Space Team
parent
af1f3a102b
commit
e4406638bd
@@ -0,0 +1,18 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jetbrains.kotlin.konan.file
|
||||||
|
|
||||||
|
import java.nio.file.FileSystem
|
||||||
|
|
||||||
|
interface ZipFileSystemAccessor {
|
||||||
|
fun <T> withZipFileSystem(zipFile: File, action: (FileSystem) -> T): T
|
||||||
|
}
|
||||||
|
|
||||||
|
object ZipFileSystemInPlaceAccessor : ZipFileSystemAccessor {
|
||||||
|
override fun <T> withZipFileSystem(zipFile: File, action: (FileSystem) -> T): T {
|
||||||
|
return zipFile.withZipFileSystem(action)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -17,6 +17,7 @@
|
|||||||
package org.jetbrains.kotlin.library.impl
|
package org.jetbrains.kotlin.library.impl
|
||||||
|
|
||||||
import org.jetbrains.kotlin.konan.file.File
|
import org.jetbrains.kotlin.konan.file.File
|
||||||
|
import org.jetbrains.kotlin.konan.file.ZipFileSystemAccessor
|
||||||
import org.jetbrains.kotlin.konan.properties.Properties
|
import org.jetbrains.kotlin.konan.properties.Properties
|
||||||
import org.jetbrains.kotlin.konan.properties.loadProperties
|
import org.jetbrains.kotlin.konan.properties.loadProperties
|
||||||
import org.jetbrains.kotlin.library.*
|
import org.jetbrains.kotlin.library.*
|
||||||
@@ -322,11 +323,12 @@ fun createKotlinLibrary(
|
|||||||
libraryFile: File,
|
libraryFile: File,
|
||||||
component: String,
|
component: String,
|
||||||
isDefault: Boolean = false,
|
isDefault: Boolean = false,
|
||||||
perFile: Boolean = false
|
perFile: Boolean = false,
|
||||||
|
zipAccessor: ZipFileSystemAccessor? = null,
|
||||||
): KotlinLibrary {
|
): KotlinLibrary {
|
||||||
val baseAccess = BaseLibraryAccess<KotlinLibraryLayout>(libraryFile, component)
|
val baseAccess = BaseLibraryAccess<KotlinLibraryLayout>(libraryFile, component, zipAccessor)
|
||||||
val metadataAccess = MetadataLibraryAccess<MetadataKotlinLibraryLayout>(libraryFile, component)
|
val metadataAccess = MetadataLibraryAccess<MetadataKotlinLibraryLayout>(libraryFile, component, zipAccessor)
|
||||||
val irAccess = IrLibraryAccess<IrKotlinLibraryLayout>(libraryFile, component)
|
val irAccess = IrLibraryAccess<IrKotlinLibraryLayout>(libraryFile, component, zipAccessor)
|
||||||
|
|
||||||
val base = BaseKotlinLibraryImpl(baseAccess, isDefault)
|
val base = BaseKotlinLibraryImpl(baseAccess, isDefault)
|
||||||
val metadata = MetadataLibraryImpl(metadataAccess)
|
val metadata = MetadataLibraryImpl(metadataAccess)
|
||||||
@@ -337,12 +339,13 @@ fun createKotlinLibrary(
|
|||||||
|
|
||||||
fun createKotlinLibraryComponents(
|
fun createKotlinLibraryComponents(
|
||||||
libraryFile: File,
|
libraryFile: File,
|
||||||
isDefault: Boolean = true
|
isDefault: Boolean = true,
|
||||||
) : List<KotlinLibrary> {
|
zipAccessor: ZipFileSystemAccessor? = null,
|
||||||
val baseAccess = BaseLibraryAccess<KotlinLibraryLayout>(libraryFile, null)
|
): List<KotlinLibrary> {
|
||||||
|
val baseAccess = BaseLibraryAccess<KotlinLibraryLayout>(libraryFile, null, zipAccessor)
|
||||||
val base = BaseKotlinLibraryImpl(baseAccess, isDefault)
|
val base = BaseKotlinLibraryImpl(baseAccess, isDefault)
|
||||||
return base.componentList.map {
|
return base.componentList.map {
|
||||||
createKotlinLibrary(libraryFile, it, isDefault)
|
createKotlinLibrary(libraryFile, it, isDefault, zipAccessor = zipAccessor)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,6 @@
|
|||||||
package org.jetbrains.kotlin.library.impl
|
package org.jetbrains.kotlin.library.impl
|
||||||
|
|
||||||
import org.jetbrains.kotlin.konan.file.File
|
import org.jetbrains.kotlin.konan.file.*
|
||||||
import org.jetbrains.kotlin.konan.file.file
|
|
||||||
import org.jetbrains.kotlin.konan.file.unzipTo
|
|
||||||
import org.jetbrains.kotlin.konan.file.withZipFileSystem
|
|
||||||
import org.jetbrains.kotlin.library.*
|
import org.jetbrains.kotlin.library.*
|
||||||
import org.jetbrains.kotlin.util.removeSuffixIfPresent
|
import org.jetbrains.kotlin.util.removeSuffixIfPresent
|
||||||
import java.nio.file.FileSystem
|
import java.nio.file.FileSystem
|
||||||
@@ -54,9 +51,11 @@ class IrLibraryLayoutImpl(klib: File, component: String) : KotlinLibraryLayoutIm
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Suppress("UNCHECKED_CAST")
|
@Suppress("UNCHECKED_CAST")
|
||||||
open class BaseLibraryAccess<L : KotlinLibraryLayout>(val klib: File, component: String?) {
|
open class BaseLibraryAccess<L : KotlinLibraryLayout>(val klib: File, component: String?, zipAccessor: ZipFileSystemAccessor? = null) {
|
||||||
open val layout = KotlinLibraryLayoutImpl(klib, component)
|
open val layout = KotlinLibraryLayoutImpl(klib, component)
|
||||||
|
|
||||||
|
private val klibZipAccessor = zipAccessor ?: ZipFileSystemInPlaceAccessor
|
||||||
|
|
||||||
fun <T> realFiles(action: (L) -> T): T =
|
fun <T> realFiles(action: (L) -> T): T =
|
||||||
if (layout.isZipped)
|
if (layout.isZipped)
|
||||||
action(layout.extractingToTemp as L)
|
action(layout.extractingToTemp as L)
|
||||||
@@ -65,7 +64,7 @@ open class BaseLibraryAccess<L : KotlinLibraryLayout>(val klib: File, component:
|
|||||||
|
|
||||||
fun <T> inPlace(action: (L) -> T): T =
|
fun <T> inPlace(action: (L) -> T): T =
|
||||||
if (layout.isZipped)
|
if (layout.isZipped)
|
||||||
layout.klib.withZipFileSystem { zipFileSystem ->
|
klibZipAccessor.withZipFileSystem(layout.klib) { zipFileSystem ->
|
||||||
action(layout.directlyFromZip(zipFileSystem) as L)
|
action(layout.directlyFromZip(zipFileSystem) as L)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -73,11 +72,13 @@ open class BaseLibraryAccess<L : KotlinLibraryLayout>(val klib: File, component:
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class MetadataLibraryAccess<L : KotlinLibraryLayout>(klib: File, component: String) : BaseLibraryAccess<L>(klib, component) {
|
class MetadataLibraryAccess<L : KotlinLibraryLayout>(klib: File, component: String, zipAccessor: ZipFileSystemAccessor? = null) :
|
||||||
|
BaseLibraryAccess<L>(klib, component, zipAccessor) {
|
||||||
override val layout = MetadataLibraryLayoutImpl(klib, component)
|
override val layout = MetadataLibraryLayoutImpl(klib, component)
|
||||||
}
|
}
|
||||||
|
|
||||||
class IrLibraryAccess<L : KotlinLibraryLayout>(klib: File, component: String) : BaseLibraryAccess<L>(klib, component) {
|
class IrLibraryAccess<L : KotlinLibraryLayout>(klib: File, component: String, zipAccessor: ZipFileSystemAccessor? = null) :
|
||||||
|
BaseLibraryAccess<L>(klib, component, zipAccessor) {
|
||||||
override val layout = IrLibraryLayoutImpl(klib, component)
|
override val layout = IrLibraryLayoutImpl(klib, component)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user