Moved clang flags out of the root build.gardle.
Collected clang args in ClangArgs.kt Switched dependencies/build.gradle to KonanTarget. Introduced KonanProperties to take care of target specific properties.
This commit is contained in:
committed by
alexander-gorshenev
parent
1d532729a8
commit
55c4966203
@@ -106,7 +106,7 @@ kotlinNativeInterop {
|
||||
compilerOpts '-fPIC'
|
||||
linkerOpts '-fPIC'
|
||||
linker 'clang++'
|
||||
linkOutputs ":common:${host}Hash"
|
||||
linkOutputs ":common:${hostName}Hash"
|
||||
|
||||
headers fileTree('../common/src/hash/headers') {
|
||||
include '**/*.h'
|
||||
@@ -148,8 +148,8 @@ build.dependsOn 'compilerClasses','cli_bcClasses','bc_frontendClasses'
|
||||
|
||||
|
||||
// These are just a couple of aliases
|
||||
task stdlib(dependsOn: "${host}Stdlib")
|
||||
task start(dependsOn: "${host}Start")
|
||||
task stdlib(dependsOn: "${hostName}Stdlib")
|
||||
task start(dependsOn: "${hostName}Start")
|
||||
|
||||
// These files are built before the 'dist' is complete,
|
||||
// so we provide custom values for
|
||||
|
||||
+15
-13
@@ -17,7 +17,8 @@
|
||||
package org.jetbrains.kotlin.backend.konan
|
||||
|
||||
import org.jetbrains.kotlin.konan.target.*
|
||||
import org.jetbrains.kotlin.backend.konan.util.*
|
||||
import org.jetbrains.kotlin.konan.file.*
|
||||
import org.jetbrains.kotlin.konan.properties.*
|
||||
|
||||
class Distribution(val targetManager: TargetManager,
|
||||
val propertyFileOverride: String? = null,
|
||||
@@ -25,7 +26,8 @@ class Distribution(val targetManager: TargetManager,
|
||||
|
||||
val target = targetManager.target
|
||||
val targetName = targetManager.targetName
|
||||
val hostSuffix = targetManager.hostSuffix
|
||||
val host = TargetManager.host
|
||||
val hostSuffix = TargetManager.hostSuffix
|
||||
val hostTargetSuffix = targetManager.hostTargetSuffix
|
||||
val targetSuffix = targetManager.targetSuffix
|
||||
|
||||
@@ -42,23 +44,23 @@ class Distribution(val targetManager: TargetManager,
|
||||
val properties = File(propertyFileName).loadProperties()
|
||||
|
||||
val klib = "$konanHome/klib"
|
||||
|
||||
val dependenciesDir = "$konanHome/dependencies"
|
||||
val dependencies = properties.propertyList("dependencies.$hostTargetSuffix")
|
||||
|
||||
val stdlib = "$klib/stdlib"
|
||||
val runtime = runtimeFileOverride ?: "$stdlib/targets/${targetName}/native/runtime.bc"
|
||||
|
||||
val llvmHome = "$dependenciesDir/${properties.propertyString("llvmHome.$hostSuffix")}"
|
||||
val hostSysRoot = "$dependenciesDir/${properties.propertyString("targetSysRoot.$hostSuffix")}"
|
||||
val targetSysRoot = "$dependenciesDir/${properties.propertyString("targetSysRoot.$targetSuffix")}"
|
||||
val targetToolchain = "$dependenciesDir/${properties.propertyString("targetToolchain.$hostTargetSuffix")}"
|
||||
val libffi =
|
||||
"$dependenciesDir/${properties.propertyString("libffiDir.$targetSuffix")}/lib/libffi.a"
|
||||
val dependenciesDir = "$konanHome/dependencies"
|
||||
|
||||
val targetProperties = KonanProperties(target, properties, dependenciesDir)
|
||||
val hostProperties = if (target == host) {
|
||||
targetProperties
|
||||
} else {
|
||||
KonanProperties(host, properties, dependenciesDir)
|
||||
}
|
||||
val dependencies = targetProperties.hostTargetList("dependencies")
|
||||
|
||||
val llvmHome = hostProperties.absoluteLlvmHome
|
||||
val hostSysRoot = hostProperties.absoluteTargetSysRoot
|
||||
val llvmBin = "$llvmHome/bin"
|
||||
val llvmLib = "$llvmHome/lib"
|
||||
|
||||
val llvmLto = "$llvmBin/llvm-lto"
|
||||
|
||||
private val libLTODir = when (TargetManager.host) {
|
||||
|
||||
+1
-1
@@ -20,7 +20,6 @@ import com.intellij.openapi.project.Project
|
||||
import org.jetbrains.kotlin.backend.konan.library.KonanLibraryReader
|
||||
import org.jetbrains.kotlin.backend.konan.library.KonanLibrarySearchPathResolver
|
||||
import org.jetbrains.kotlin.backend.konan.library.impl.LibraryReaderImpl
|
||||
import org.jetbrains.kotlin.backend.konan.util.File
|
||||
import org.jetbrains.kotlin.backend.konan.util.profile
|
||||
import org.jetbrains.kotlin.backend.konan.util.removeSuffixIfPresent
|
||||
import org.jetbrains.kotlin.backend.konan.util.suffixIfNot
|
||||
@@ -30,6 +29,7 @@ import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity.*
|
||||
import org.jetbrains.kotlin.config.CommonConfigurationKeys
|
||||
import org.jetbrains.kotlin.config.CompilerConfiguration
|
||||
import org.jetbrains.kotlin.descriptors.impl.ModuleDescriptorImpl
|
||||
import org.jetbrains.kotlin.konan.file.File
|
||||
import org.jetbrains.kotlin.konan.target.*
|
||||
import org.jetbrains.kotlin.konan.target.TargetManager.*
|
||||
import org.jetbrains.kotlin.konan.target.CompilerOutputKind.*
|
||||
|
||||
+30
-37
@@ -16,11 +16,11 @@
|
||||
|
||||
package org.jetbrains.kotlin.backend.konan
|
||||
|
||||
import org.jetbrains.kotlin.backend.konan.util.bufferedReader
|
||||
import java.lang.ProcessBuilder
|
||||
import java.lang.ProcessBuilder.Redirect
|
||||
import org.jetbrains.kotlin.konan.file.*
|
||||
import org.jetbrains.kotlin.konan.properties.*
|
||||
import org.jetbrains.kotlin.konan.target.*
|
||||
import org.jetbrains.kotlin.backend.konan.util.*
|
||||
|
||||
typealias BitcodeFile = String
|
||||
typealias ObjectFile = String
|
||||
@@ -28,46 +28,39 @@ typealias ExecutableFile = String
|
||||
|
||||
// Use "clang -v -save-temps" to write linkCommand() method
|
||||
// for another implementation of this class.
|
||||
internal abstract class PlatformFlags(val distribution: Distribution) {
|
||||
val properties = distribution.properties
|
||||
|
||||
val target = distribution.target
|
||||
|
||||
open val llvmLtoNooptFlags
|
||||
= propertyTargetList("llvmLtoNooptFlags")
|
||||
open val llvmLtoOptFlags
|
||||
= propertyTargetList("llvmLtoOptFlags")
|
||||
open val llvmLtoFlags
|
||||
= propertyTargetList("llvmLtoFlags")
|
||||
open val entrySelector
|
||||
= propertyTargetList("entrySelector")
|
||||
open val linkerOptimizationFlags
|
||||
= propertyTargetList("linkerOptimizationFlags")
|
||||
open val linkerKonanFlags
|
||||
= propertyTargetList("linkerKonanFlags")
|
||||
open val linkerDebugFlags
|
||||
= propertyTargetList("linkerDebugFlags")
|
||||
open val llvmDebugOptFlags
|
||||
= propertyTargetList("llvmDebugOptFlags")
|
||||
internal abstract class PlatformFlags(val properties: KonanProperties) {
|
||||
val llvmLtoNooptFlags = properties.llvmLtoNooptFlags
|
||||
val llvmLtoOptFlags = properties.llvmLtoOptFlags
|
||||
val llvmLtoFlags = properties.llvmLtoFlags
|
||||
val entrySelector = properties.entrySelector
|
||||
val linkerOptimizationFlags = properties.linkerOptimizationFlags
|
||||
val linkerKonanFlags = properties.linkerKonanFlags
|
||||
val linkerDebugFlags = properties.linkerDebugFlags
|
||||
val llvmDebugOptFlags = properties.llvmDebugOptFlags
|
||||
|
||||
open val useCompilerDriverAsLinker: Boolean get() = false // TODO: refactor.
|
||||
|
||||
abstract fun linkCommand(objectFiles: List<ObjectFile>,
|
||||
executable: ExecutableFile, optimize: Boolean, debug: Boolean): List<String>
|
||||
|
||||
val targetLibffiDir = properties.absoluteLibffiDir
|
||||
val targetLibffi = "$targetLibffiDir/lib/libffi.a"
|
||||
val targetToolchain = properties.absoluteTargetToolchain
|
||||
val targetSysRoot = properties.absoluteTargetSysRoot
|
||||
|
||||
open fun linkCommandSuffix(): List<String> = emptyList()
|
||||
|
||||
protected fun propertyTargetString(name: String)
|
||||
= properties.targetString(name, target)!!
|
||||
protected fun propertyTargetList(name: String)
|
||||
= properties.targetList(name, target)
|
||||
= properties.targetString(name)!!
|
||||
protected fun propertyTargetList(name: String)
|
||||
= properties.targetList(name)
|
||||
}
|
||||
|
||||
|
||||
internal open class AndroidPlatform(distribution: Distribution)
|
||||
: PlatformFlags(distribution) {
|
||||
: PlatformFlags(distribution.targetProperties) {
|
||||
|
||||
private val prefix = "${distribution.targetToolchain}/bin/"
|
||||
private val prefix = "$targetToolchain/bin/"
|
||||
private val clang = "$prefix/clang"
|
||||
|
||||
override val useCompilerDriverAsLinker: Boolean get() = true
|
||||
@@ -87,11 +80,12 @@ internal open class AndroidPlatform(distribution: Distribution)
|
||||
}
|
||||
|
||||
internal open class MacOSBasedPlatform(distribution: Distribution)
|
||||
: PlatformFlags(distribution) {
|
||||
: PlatformFlags(distribution.targetProperties) {
|
||||
|
||||
// TODO: move 'ld' out of the host sysroot, as it doesn't belong here.
|
||||
private val linker = "${distribution.hostSysRoot}/usr/bin/ld"
|
||||
internal val dsymutil = "${distribution.llvmBin}/llvm-dsymutil"
|
||||
internal val libLTO = distribution.libLTO
|
||||
|
||||
open val osVersionMin by lazy {
|
||||
listOf(
|
||||
@@ -102,10 +96,10 @@ internal open class MacOSBasedPlatform(distribution: Distribution)
|
||||
override fun linkCommand(objectFiles: List<ObjectFile>, executable: ExecutableFile, optimize: Boolean, debug: Boolean): List<String> {
|
||||
return mutableListOf(linker).apply {
|
||||
add("-demangle")
|
||||
addAll(listOf("-object_path_lto", "temporary.o", "-lto_library", distribution.libLTO))
|
||||
addAll(listOf("-object_path_lto", "temporary.o", "-lto_library", libLTO))
|
||||
addAll(listOf("-dynamic", "-arch", propertyTargetString("arch")))
|
||||
addAll(osVersionMin)
|
||||
addAll(listOf("-syslibroot", distribution.targetSysRoot, "-o", executable))
|
||||
addAll(listOf("-syslibroot", targetSysRoot, "-o", executable))
|
||||
addAll(objectFiles)
|
||||
if (optimize) addAll(linkerOptimizationFlags)
|
||||
if (!debug) addAll(linkerDebugFlags)
|
||||
@@ -121,12 +115,11 @@ internal open class MacOSBasedPlatform(distribution: Distribution)
|
||||
}
|
||||
|
||||
internal open class LinuxBasedPlatform(distribution: Distribution)
|
||||
: PlatformFlags(distribution) {
|
||||
: PlatformFlags(distribution.targetProperties) {
|
||||
|
||||
private val targetSysRoot = distribution.targetSysRoot
|
||||
private val llvmLib = distribution.llvmLib
|
||||
private val libGcc = "$targetSysRoot/${propertyTargetString("libGcc")!!}"
|
||||
private val linker = "${distribution.targetToolchain}/bin/ld.gold"
|
||||
private val linker = "$targetToolchain/bin/ld.gold"
|
||||
private val pluginOptimizationFlags = propertyTargetList("pluginOptimizationFlags")
|
||||
private val specificLibs
|
||||
= propertyTargetList("abiSpecificLibraries").map{it -> "-L${targetSysRoot}/$it"}
|
||||
@@ -158,9 +151,9 @@ internal open class LinuxBasedPlatform(distribution: Distribution)
|
||||
}
|
||||
|
||||
internal open class MingwPlatform(distribution: Distribution)
|
||||
: PlatformFlags(distribution) {
|
||||
: PlatformFlags(distribution.targetProperties) {
|
||||
|
||||
private val linker = "${distribution.targetToolchain}/bin/clang++"
|
||||
private val linker = "$targetToolchain/bin/clang++"
|
||||
|
||||
override val useCompilerDriverAsLinker: Boolean get() = true
|
||||
|
||||
@@ -250,7 +243,7 @@ internal class LinkStage(val context: Context) {
|
||||
private fun link(objectFiles: List<ObjectFile>, libraryProvidedLinkerFlags: List<String>): ExecutableFile {
|
||||
val executable = context.config.outputFile
|
||||
val linkCommand = platform.linkCommand(objectFiles, executable, optimize, debug) +
|
||||
distribution.libffi +
|
||||
platform.targetLibffi +
|
||||
asLinkerArgs(config.getNotNull(KonanConfigKeys.LINKER_ARGS)) +
|
||||
entryPointSelector +
|
||||
platform.linkCommandSuffix() +
|
||||
|
||||
+2
-2
@@ -16,7 +16,6 @@
|
||||
|
||||
package org.jetbrains.kotlin.backend.konan.ir
|
||||
|
||||
import org.jetbrains.kotlin.backend.konan.util.File
|
||||
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.PackageFragmentDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor
|
||||
@@ -38,6 +37,7 @@ import org.jetbrains.kotlin.ir.symbols.IrFunctionSymbol
|
||||
import org.jetbrains.kotlin.ir.symbols.impl.IrBindableSymbolBase
|
||||
import org.jetbrains.kotlin.ir.visitors.IrElementTransformer
|
||||
import org.jetbrains.kotlin.ir.visitors.IrElementVisitor
|
||||
import org.jetbrains.kotlin.konan.file.*
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
|
||||
//-----------------------------------------------------------------------------//
|
||||
@@ -235,4 +235,4 @@ class IrSuspendableExpressionImpl(startOffset: Int, endOffset: Int, type: Kotlin
|
||||
suspensionPointId = suspensionPointId.transform(transformer, data)
|
||||
result = result.transform(transformer, data)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -17,7 +17,7 @@
|
||||
package org.jetbrains.kotlin.backend.konan.library
|
||||
|
||||
import org.jetbrains.kotlin.konan.target.KonanTarget
|
||||
import org.jetbrains.kotlin.backend.konan.util.File
|
||||
import org.jetbrains.kotlin.konan.file.File
|
||||
|
||||
// This scheme describes the Konan Library (klib) layout.
|
||||
interface KonanLibraryLayout {
|
||||
|
||||
+1
-1
@@ -16,9 +16,9 @@
|
||||
|
||||
package org.jetbrains.kotlin.backend.konan.library
|
||||
|
||||
import org.jetbrains.kotlin.backend.konan.util.File
|
||||
import org.jetbrains.kotlin.backend.konan.util.removeSuffixIfPresent
|
||||
import org.jetbrains.kotlin.backend.konan.util.suffixIfNot
|
||||
import org.jetbrains.kotlin.konan.file.File
|
||||
|
||||
interface SearchPathResolver {
|
||||
val searchRoots: List<File>
|
||||
|
||||
+2
-1
@@ -17,7 +17,8 @@
|
||||
package org.jetbrains.kotlin.backend.konan.library.impl
|
||||
|
||||
import org.jetbrains.kotlin.backend.konan.library.KonanLibrary
|
||||
import org.jetbrains.kotlin.backend.konan.util.*
|
||||
import org.jetbrains.kotlin.backend.konan.util.removeSuffixIfPresent
|
||||
import org.jetbrains.kotlin.konan.file.*
|
||||
import org.jetbrains.kotlin.konan.target.KonanTarget
|
||||
|
||||
open class ZippedKonanLibrary(val klibFile: File, override val target: KonanTarget? = null): KonanLibrary {
|
||||
|
||||
+2
-4
@@ -18,10 +18,8 @@ package org.jetbrains.kotlin.backend.konan.library.impl
|
||||
|
||||
import org.jetbrains.kotlin.backend.konan.library.KonanLibraryReader
|
||||
import org.jetbrains.kotlin.backend.konan.serialization.deserializeModule
|
||||
import org.jetbrains.kotlin.backend.konan.util.File
|
||||
import org.jetbrains.kotlin.backend.konan.util.Properties
|
||||
import org.jetbrains.kotlin.backend.konan.util.loadProperties
|
||||
import org.jetbrains.kotlin.backend.konan.util.propertyList
|
||||
import org.jetbrains.kotlin.konan.file.File
|
||||
import org.jetbrains.kotlin.konan.properties.*
|
||||
import org.jetbrains.kotlin.config.LanguageVersionSettings
|
||||
import org.jetbrains.kotlin.konan.target.KonanTarget
|
||||
|
||||
|
||||
+2
-1
@@ -21,7 +21,8 @@ import llvm.LLVMWriteBitcodeToFile
|
||||
import org.jetbrains.kotlin.backend.konan.library.KonanLibrary
|
||||
import org.jetbrains.kotlin.backend.konan.library.KonanLibraryWriter
|
||||
import org.jetbrains.kotlin.backend.konan.library.LinkData
|
||||
import org.jetbrains.kotlin.backend.konan.util.*
|
||||
import org.jetbrains.kotlin.konan.file.*
|
||||
import org.jetbrains.kotlin.konan.properties.*
|
||||
import org.jetbrains.kotlin.konan.target.KonanTarget
|
||||
|
||||
abstract class FileBasedLibraryWriter (
|
||||
|
||||
+1
-1
@@ -18,7 +18,7 @@ package org.jetbrains.kotlin.backend.konan.library.impl
|
||||
|
||||
import org.jetbrains.kotlin.backend.konan.library.KonanLibrary
|
||||
import org.jetbrains.kotlin.backend.konan.library.LinkData
|
||||
import org.jetbrains.kotlin.backend.konan.util.File
|
||||
import org.jetbrains.kotlin.konan.file.File
|
||||
|
||||
internal class MetadataWriterImpl(library: KonanLibrary): KonanLibrary by library {
|
||||
|
||||
|
||||
+1
-1
@@ -22,13 +22,13 @@ import llvm.*
|
||||
import org.jetbrains.kotlin.backend.konan.Context
|
||||
import org.jetbrains.kotlin.backend.konan.KonanConfigKeys
|
||||
import org.jetbrains.kotlin.backend.konan.KonanVersion
|
||||
import org.jetbrains.kotlin.backend.konan.util.File
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
|
||||
import org.jetbrains.kotlin.ir.SourceManager.FileEntry
|
||||
import org.jetbrains.kotlin.ir.declarations.IrFile
|
||||
import org.jetbrains.kotlin.js.descriptorUtils.getJetTypeFqName
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe
|
||||
import org.jetbrains.kotlin.konan.file.File
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
import org.jetbrains.kotlin.types.TypeUtils
|
||||
|
||||
|
||||
-189
@@ -1,189 +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.util
|
||||
|
||||
import java.io.BufferedReader
|
||||
import java.io.InputStream
|
||||
import java.io.InputStreamReader
|
||||
import java.net.URI
|
||||
import java.nio.file.*
|
||||
import java.nio.file.attribute.BasicFileAttributes
|
||||
|
||||
class File constructor(internal val javaPath: Path) {
|
||||
constructor(parent: Path, child: String): this(parent.resolve(child))
|
||||
constructor(parent: File, child: String): this(parent.javaPath.resolve(child))
|
||||
constructor(path: String): this(Paths.get(path))
|
||||
constructor(parent: String, child: String): this(Paths.get(parent, child))
|
||||
|
||||
val path: String
|
||||
get() = javaPath.toString()
|
||||
val absolutePath: String
|
||||
get() = javaPath.toAbsolutePath().toString()
|
||||
val absoluteFile: File
|
||||
get() = File(absolutePath)
|
||||
val name: String
|
||||
get() = javaPath.fileName.toString()
|
||||
val parent: String
|
||||
get() = javaPath.parent.toString()
|
||||
|
||||
val exists
|
||||
get() = Files.exists(javaPath)
|
||||
val isDirectory
|
||||
get() = Files.isDirectory(javaPath)
|
||||
val isFile
|
||||
get() = Files.isRegularFile(javaPath)
|
||||
val isAbsolute
|
||||
get() = javaPath.isAbsolute()
|
||||
val listFiles: List<File>
|
||||
get() {
|
||||
val stream = Files.newDirectoryStream(javaPath)
|
||||
val result = mutableListOf<File>()
|
||||
for (entry in stream) {
|
||||
result.add(File(entry))
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
fun copyTo(destination: File, vararg options: StandardCopyOption) {
|
||||
Files.copy(javaPath, destination.javaPath, StandardCopyOption.REPLACE_EXISTING)
|
||||
}
|
||||
|
||||
fun recursiveCopyTo(destination: File) {
|
||||
val sourcePath = javaPath
|
||||
val destPath = destination.javaPath
|
||||
sourcePath.recursiveCopyTo(destPath)
|
||||
}
|
||||
|
||||
fun mkdirs() = Files.createDirectories(javaPath)
|
||||
fun delete() = Files.deleteIfExists(javaPath)
|
||||
fun deleteRecursively() = postorder{Files.delete(it)}
|
||||
fun deleteOnExitRecursively() = preorder{File(it).deleteOnExit()}
|
||||
|
||||
fun preorder(task: (Path) -> Unit) {
|
||||
if (!this.exists) return
|
||||
|
||||
Files.walkFileTree(javaPath, object: SimpleFileVisitor<Path>() {
|
||||
override fun visitFile(file: Path?, attrs: BasicFileAttributes?): FileVisitResult {
|
||||
task(file!!)
|
||||
return FileVisitResult.CONTINUE
|
||||
}
|
||||
|
||||
override fun preVisitDirectory(dir: Path?, attrs: BasicFileAttributes?): FileVisitResult {
|
||||
task(dir!!)
|
||||
return FileVisitResult.CONTINUE
|
||||
}
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
fun postorder(task: (Path) -> Unit) {
|
||||
if (!this.exists) return
|
||||
|
||||
Files.walkFileTree(javaPath, object: SimpleFileVisitor<Path>() {
|
||||
override fun visitFile(file: Path?, attrs: BasicFileAttributes?): FileVisitResult {
|
||||
task(file!!)
|
||||
return FileVisitResult.CONTINUE
|
||||
}
|
||||
|
||||
override fun postVisitDirectory(dir: Path?, exc: java.io.IOException?): FileVisitResult {
|
||||
task(dir!!)
|
||||
return FileVisitResult.CONTINUE
|
||||
}
|
||||
})
|
||||
|
||||
}
|
||||
fun deleteOnExit() {
|
||||
// Works only on the default file system,
|
||||
// but that's okay for now.
|
||||
javaPath.toFile().deleteOnExit()
|
||||
}
|
||||
fun readBytes() = Files.readAllBytes(javaPath)
|
||||
fun writeBytes(bytes: ByteArray) = Files.write(javaPath, bytes)
|
||||
fun forEachLine(action: (String) -> Unit) { Files.lines(javaPath).forEach { action(it) } }
|
||||
|
||||
override fun toString() = path
|
||||
|
||||
// TODO: Consider removeing these after konanazing java.util.Properties.
|
||||
fun bufferedReader() = Files.newBufferedReader(javaPath)
|
||||
fun outputStream() = Files.newOutputStream(javaPath)
|
||||
|
||||
companion object {
|
||||
val userDir
|
||||
get() = File(System.getProperty("user.dir"))
|
||||
|
||||
val userHome
|
||||
get() = File(System.getProperty("user.home"))
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
fun String.File(): File = File(this)
|
||||
fun Path.File(): File = File(this)
|
||||
|
||||
fun createTempFile(name: String, suffix: String? = null)
|
||||
= Files.createTempFile(name, suffix).File()
|
||||
fun createTempDir(name: String): File
|
||||
= Files.createTempDirectory(name).File()
|
||||
|
||||
private val File.zipUri: URI
|
||||
get() = URI.create("jar:${this.toPath().toUri()}")
|
||||
|
||||
fun File.zipFileSystem(mutable: Boolean = false): FileSystem {
|
||||
val zipUri = this.zipUri
|
||||
val allowCreation = if (mutable) "true" else "false"
|
||||
val attributes = hashMapOf("create" to if (mutable) "true" else "false")
|
||||
return FileSystems.newFileSystem(zipUri, attributes, null)
|
||||
}
|
||||
|
||||
fun File.mutableZipFileSystem() = this.zipFileSystem(mutable = true)
|
||||
|
||||
fun File.zipPath(path: String): Path
|
||||
= this.zipFileSystem().getPath(path)
|
||||
|
||||
val File.asZipRoot: File
|
||||
get() = File(this.zipPath("/"))
|
||||
|
||||
val File.asWritableZipRoot: File
|
||||
get() = File(this.mutableZipFileSystem().getPath("/"))
|
||||
|
||||
private fun File.toPath() = Paths.get(this.path)
|
||||
|
||||
fun File.zipDirAs(unixFile: File) {
|
||||
val zipRoot = unixFile.asWritableZipRoot
|
||||
this.recursiveCopyTo(zipRoot)
|
||||
zipRoot.javaPath.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 bufferedReader(errorStream: InputStream?) = BufferedReader(InputStreamReader(errorStream))
|
||||
|
||||
-57
@@ -1,57 +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.util
|
||||
|
||||
typealias Properties = java.util.Properties
|
||||
|
||||
fun File.loadProperties(): Properties {
|
||||
val properties = java.util.Properties()
|
||||
this.bufferedReader().use { reader ->
|
||||
properties.load(reader)
|
||||
}
|
||||
return properties
|
||||
}
|
||||
|
||||
fun File.saveProperties(properties: Properties) {
|
||||
this.outputStream().use {
|
||||
properties.store(it, null)
|
||||
}
|
||||
}
|
||||
|
||||
fun Properties.saveToFile(file: File) = file.saveProperties(this)
|
||||
|
||||
fun Properties.propertyString(key: String, suffix: String? = null): String?
|
||||
= this.getProperty(key.suffix(suffix))
|
||||
|
||||
/**
|
||||
* TODO: this method working with suffixes should be replaced with
|
||||
* functionality borrowed from def file parser and unified for interop tool
|
||||
* and kotlin compiler.
|
||||
*/
|
||||
fun Properties.propertyList(key: String, suffix: String? = null): List<String> {
|
||||
val value = this.getProperty(key.suffix(suffix)) ?: this.getProperty(key)
|
||||
return value?.split(' ') ?: emptyList()
|
||||
}
|
||||
|
||||
fun Properties.hasProperty(key: String, suffix: String? = null): Boolean
|
||||
= this.getProperty(key.suffix(suffix)) != null
|
||||
|
||||
fun String.suffix(suf: String?): String =
|
||||
if (suf == null) this
|
||||
else "${this}.$suf"
|
||||
|
||||
|
||||
-31
@@ -1,31 +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.util
|
||||
|
||||
import org.jetbrains.kotlin.konan.target.*
|
||||
|
||||
fun Properties.hostString(name: String): String?
|
||||
= this.propertyString(name, TargetManager.host.targetSuffix)
|
||||
|
||||
fun Properties.hostList(name: String): List<String>
|
||||
= this.propertyList(name, TargetManager.host.targetSuffix)
|
||||
|
||||
fun Properties.targetString(name: String, target: KonanTarget): String?
|
||||
= this.propertyString(name, target.targetSuffix)
|
||||
|
||||
fun Properties.targetList(name: String, target: KonanTarget): List<String>
|
||||
= this.propertyList(name, target.targetSuffix)
|
||||
@@ -89,6 +89,7 @@ osVersionMin.ios_sim = 8.0
|
||||
# Linux x86-64.
|
||||
llvmVersion.linux = 3.9.0
|
||||
llvmHome.linux = clang-llvm-3.9.0-linux-x86-64
|
||||
gccToolchain.linux = target-gcc-toolchain-3-linux-x86-64
|
||||
targetToolchain.linux = target-gcc-toolchain-3-linux-x86-64/x86_64-unknown-linux-gnu
|
||||
|
||||
quadruple.linux = x86_64-unknown-linux-gnu
|
||||
|
||||
Reference in New Issue
Block a user