Moved KonanLibrary to org.jetbrains.kotlin.backend.konan.util.File
instead of java.io.File.
This commit is contained in:
committed by
alexander-gorshenev
parent
3b5ce031f8
commit
dc80ba3492
-70
@@ -1,70 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2010-2017 JetBrains s.r.o.
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.jetbrains.kotlin.backend.konan
|
|
||||||
|
|
||||||
import java.io.File
|
|
||||||
import java.net.URI
|
|
||||||
import java.nio.file.FileSystems
|
|
||||||
import java.nio.file.Files
|
|
||||||
import java.nio.file.Path
|
|
||||||
import java.nio.file.StandardCopyOption
|
|
||||||
|
|
||||||
val File.zipUri: URI
|
|
||||||
get() = URI.create("jar:file:${this.absolutePath}")
|
|
||||||
|
|
||||||
val File.zipRootPath: Path
|
|
||||||
get() {
|
|
||||||
val zipUri = this.zipUri
|
|
||||||
val allowCreation = hashMapOf("create" to "true")
|
|
||||||
val zipfs = FileSystems.newFileSystem(zipUri, allowCreation, null)
|
|
||||||
return zipfs.getPath("/")
|
|
||||||
}
|
|
||||||
|
|
||||||
fun File.zipDirAs(zipFile: File) {
|
|
||||||
val zipPath = zipFile.zipRootPath
|
|
||||||
this.toPath().recursiveCopyTo(zipPath)
|
|
||||||
zipPath.fileSystem.close()
|
|
||||||
}
|
|
||||||
|
|
||||||
fun File.unzipAs(directory: File) {
|
|
||||||
val zipPath = this.zipRootPath
|
|
||||||
zipPath.recursiveCopyTo(directory.toPath())
|
|
||||||
zipPath.fileSystem.close()
|
|
||||||
}
|
|
||||||
|
|
||||||
fun Path.recursiveCopyTo(destPath: Path) {
|
|
||||||
val sourcePath = this
|
|
||||||
Files.walk(sourcePath).forEach next@ { oldPath ->
|
|
||||||
|
|
||||||
val relative = sourcePath.relativize(oldPath)
|
|
||||||
val destFs = destPath.getFileSystem()
|
|
||||||
// We are copying files between file systems,
|
|
||||||
// so pass the relative path through the Sting.
|
|
||||||
val newPath = destFs.getPath(destPath.toString(), relative.toString())
|
|
||||||
|
|
||||||
// File systems don't allow replacing an existing root.
|
|
||||||
if (newPath == newPath.getRoot()) return@next
|
|
||||||
Files.copy(oldPath, newPath,
|
|
||||||
StandardCopyOption.REPLACE_EXISTING)
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun File.copyTo(destination: File) {
|
|
||||||
Files.copy(this.toPath(), destination.toPath())
|
|
||||||
}
|
|
||||||
|
|
||||||
+11
-8
@@ -22,9 +22,12 @@ import llvm.LLVMWriteBitcodeToFile
|
|||||||
import org.jetbrains.kotlin.backend.konan.llvm.*
|
import org.jetbrains.kotlin.backend.konan.llvm.*
|
||||||
import org.jetbrains.kotlin.backend.konan.serialization.Base64
|
import org.jetbrains.kotlin.backend.konan.serialization.Base64
|
||||||
import org.jetbrains.kotlin.backend.konan.serialization.deserializeModule
|
import org.jetbrains.kotlin.backend.konan.serialization.deserializeModule
|
||||||
|
import org.jetbrains.kotlin.backend.konan.util.File
|
||||||
|
import org.jetbrains.kotlin.backend.konan.util.copyTo
|
||||||
|
import org.jetbrains.kotlin.backend.konan.util.unzipAs
|
||||||
|
import org.jetbrains.kotlin.backend.konan.util.zipDirAs
|
||||||
import org.jetbrains.kotlin.config.CompilerConfiguration
|
import org.jetbrains.kotlin.config.CompilerConfiguration
|
||||||
import org.jetbrains.kotlin.descriptors.impl.ModuleDescriptorImpl
|
import org.jetbrains.kotlin.descriptors.impl.ModuleDescriptorImpl
|
||||||
import java.io.File
|
|
||||||
|
|
||||||
interface KonanLibraryReader {
|
interface KonanLibraryReader {
|
||||||
val libraryName: String
|
val libraryName: String
|
||||||
@@ -87,23 +90,23 @@ class SplitLibraryReader(val libDir: File, configuration: CompilerConfiguration)
|
|||||||
// TODO: Search path processing is also goes somewhere around here.
|
// TODO: Search path processing is also goes somewhere around here.
|
||||||
fun unpackIfNeeded() {
|
fun unpackIfNeeded() {
|
||||||
// TODO: Clarify the policy here.
|
// TODO: Clarify the policy here.
|
||||||
if (libDir.exists()) {
|
if (libDir.exists) {
|
||||||
if (libDir.isDirectory()) return
|
if (libDir.isDirectory) return
|
||||||
}
|
}
|
||||||
if (!klibFile.exists()) {
|
if (!klibFile.exists) {
|
||||||
error("Could not find neither $libDir nor $klibFile.")
|
error("Could not find neither $libDir nor $klibFile.")
|
||||||
}
|
}
|
||||||
if (klibFile.isFile()) {
|
if (klibFile.isFile) {
|
||||||
klibFile.unzipAs(libDir)
|
klibFile.unzipAs(libDir)
|
||||||
|
|
||||||
if (!libDir.exists()) error("Could not unpack $klibFile as $libDir.")
|
if (!libDir.exists) error("Could not unpack $klibFile as $libDir.")
|
||||||
} else {
|
} else {
|
||||||
error("Expected $klibFile to be a regular libDir.")
|
error("Expected $klibFile to be a regular libDir.")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private val File.dirAbsolutePaths: List<String>
|
private val File.dirAbsolutePaths: List<String>
|
||||||
get() = this.listFiles()!!.toList()!!.map{it->it.absolutePath}
|
get() = this.listFiles!!.toList()!!.map{it->it.absolutePath}
|
||||||
|
|
||||||
private val targetDir: File
|
private val targetDir: File
|
||||||
get() {
|
get() {
|
||||||
@@ -209,7 +212,7 @@ class SplitLibraryWriter(val libDir: File, target: String, val nopack: Boolean =
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun addNativeBitcode(library: String) {
|
override fun addNativeBitcode(library: String) {
|
||||||
val basename = File(library).getName()
|
val basename = File(library).name
|
||||||
File(library).copyTo(File(nativeDir, basename))
|
File(library).copyTo(File(nativeDir, basename))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-5
@@ -18,13 +18,9 @@ package org.jetbrains.kotlin.backend.konan.llvm
|
|||||||
|
|
||||||
import kotlinx.cinterop.*
|
import kotlinx.cinterop.*
|
||||||
import llvm.*
|
import llvm.*
|
||||||
import org.jetbrains.kotlin.backend.konan.Context
|
|
||||||
import org.jetbrains.kotlin.backend.konan.KonanConfigKeys
|
|
||||||
import org.jetbrains.kotlin.backend.konan.LinkData
|
import org.jetbrains.kotlin.backend.konan.LinkData
|
||||||
import org.jetbrains.kotlin.ir.declarations.IrModuleFragment
|
import org.jetbrains.kotlin.backend.konan.util.File
|
||||||
import java.io.Closeable
|
import java.io.Closeable
|
||||||
import java.io.File
|
|
||||||
import kotlin.io.readText
|
|
||||||
import java.util.Properties
|
import java.util.Properties
|
||||||
|
|
||||||
class NamedModuleData(val name:String, val base64: String)
|
class NamedModuleData(val name:String, val base64: String)
|
||||||
|
|||||||
+85
-3
@@ -16,12 +16,94 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.backend.konan.util
|
package org.jetbrains.kotlin.backend.konan.util
|
||||||
|
|
||||||
class File(val path:String) {
|
import java.net.URI
|
||||||
|
import java.nio.file.FileSystems
|
||||||
|
import java.nio.file.Files
|
||||||
|
import java.nio.file.Path
|
||||||
|
import java.nio.file.Paths
|
||||||
|
import java.nio.file.StandardCopyOption
|
||||||
|
|
||||||
|
class File(val path: String) {
|
||||||
|
private constructor(file: java.io.File): this(file.path)
|
||||||
|
constructor(parent: String, child: String): this(java.io.File(parent, child))
|
||||||
|
constructor(parent: File, child: String): this(java.io.File(parent.path, child))
|
||||||
|
|
||||||
private val javaFile = java.io.File(path)
|
private val javaFile = java.io.File(path)
|
||||||
val absoluteFile: File
|
val absolutePath: String
|
||||||
get() = File(javaFile.absolutePath)
|
get() = javaFile.absolutePath
|
||||||
|
val absoluteFile: File
|
||||||
|
get() = File(absolutePath)
|
||||||
val name: String
|
val name: String
|
||||||
get() = javaFile.name
|
get() = javaFile.name
|
||||||
val parent: String
|
val parent: String
|
||||||
get() = javaFile.parent
|
get() = javaFile.parent
|
||||||
|
|
||||||
|
val exists
|
||||||
|
get() = javaFile.exists()
|
||||||
|
val isDirectory
|
||||||
|
get() = javaFile.isDirectory()
|
||||||
|
val isFile
|
||||||
|
get() = javaFile.isFile()
|
||||||
|
val listFiles
|
||||||
|
get() = javaFile.listFiles()
|
||||||
|
|
||||||
|
fun mkdirs() = javaFile.mkdirs()
|
||||||
|
fun delete() = javaFile.delete()
|
||||||
|
fun deleteRecursively() = javaFile.deleteRecursively()
|
||||||
|
fun readText() = javaFile.readText()
|
||||||
|
fun writeText(text: String) = javaFile.writeText(text)
|
||||||
|
|
||||||
|
override fun toString() = path
|
||||||
|
|
||||||
|
// TODO: Consider removeing these after konanazing java.util.Properties.
|
||||||
|
fun bufferedReader() = javaFile.bufferedReader()
|
||||||
|
fun outputStream() = javaFile.outputStream()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private val File.zipUri: URI
|
||||||
|
get() = URI.create("jar:file:${this.absolutePath}")
|
||||||
|
|
||||||
|
private val File.zipRootPath: Path
|
||||||
|
get() {
|
||||||
|
val zipUri = this.zipUri
|
||||||
|
val allowCreation = hashMapOf("create" to "true")
|
||||||
|
val zipfs = FileSystems.newFileSystem(zipUri, allowCreation, null)
|
||||||
|
return zipfs.getPath("/")
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun File.toPath() = Paths.get(this.path)
|
||||||
|
|
||||||
|
fun File.zipDirAs(zipFile: File) {
|
||||||
|
val zipPath = zipFile.zipRootPath
|
||||||
|
this.toPath().recursiveCopyTo(zipPath)
|
||||||
|
zipPath.fileSystem.close()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun File.unzipAs(directory: File) {
|
||||||
|
val zipPath = this.zipRootPath
|
||||||
|
zipPath.recursiveCopyTo(directory.toPath())
|
||||||
|
zipPath.fileSystem.close()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun Path.recursiveCopyTo(destPath: Path) {
|
||||||
|
val sourcePath = this
|
||||||
|
Files.walk(sourcePath).forEach next@ { oldPath ->
|
||||||
|
|
||||||
|
val relative = sourcePath.relativize(oldPath)
|
||||||
|
val destFs = destPath.getFileSystem()
|
||||||
|
// We are copying files between file systems,
|
||||||
|
// so pass the relative path through the Sting.
|
||||||
|
val newPath = destFs.getPath(destPath.toString(), relative.toString())
|
||||||
|
|
||||||
|
// File systems don't allow replacing an existing root.
|
||||||
|
if (newPath == newPath.getRoot()) return@next
|
||||||
|
Files.copy(oldPath, newPath,
|
||||||
|
StandardCopyOption.REPLACE_EXISTING)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun File.copyTo(destination: File) {
|
||||||
|
Files.copy(this.toPath(), destination.toPath())
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user