A little bit more of utils abstracting us from java api.
This commit is contained in:
committed by
alexander-gorshenev
parent
0582d8f1bd
commit
edde21827c
@@ -42,7 +42,7 @@ private fun maybeExecuteHelper(targetName: String) {
|
|||||||
val distribution = Distribution(TargetManager(targetName))
|
val distribution = Distribution(TargetManager(targetName))
|
||||||
val result = ctor.call(
|
val result = ctor.call(
|
||||||
distribution.dependenciesDir,
|
distribution.dependenciesDir,
|
||||||
distribution.properties.properties,
|
distribution.properties,
|
||||||
distribution.dependencies
|
distribution.dependencies
|
||||||
)
|
)
|
||||||
result.run()
|
result.run()
|
||||||
|
|||||||
+5
-6
@@ -16,21 +16,20 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.backend.konan
|
package org.jetbrains.kotlin.backend.konan
|
||||||
|
|
||||||
import java.io.File
|
|
||||||
import org.jetbrains.kotlin.konan.target.*
|
import org.jetbrains.kotlin.konan.target.*
|
||||||
|
import org.jetbrains.kotlin.backend.konan.util.*
|
||||||
|
|
||||||
class Distribution(val targetManager: TargetManager,
|
class Distribution(val targetManager: TargetManager,
|
||||||
val propertyFileOverride: String? = null,
|
val propertyFileOverride: String? = null,
|
||||||
val runtimeFileOverride: String? = null) {
|
val runtimeFileOverride: String? = null) {
|
||||||
|
|
||||||
|
val target = targetManager.target
|
||||||
val targetName = targetManager.targetName
|
val targetName = targetManager.targetName
|
||||||
val hostSuffix = targetManager.hostSuffix
|
val hostSuffix = targetManager.hostSuffix
|
||||||
val hostTargetSuffix = targetManager.hostTargetSuffix
|
val hostTargetSuffix = targetManager.hostTargetSuffix
|
||||||
val targetSuffix = targetManager.targetSuffix
|
val targetSuffix = targetManager.targetSuffix
|
||||||
|
|
||||||
private fun findUserHome() = File(System.getProperty("user.home")).absolutePath
|
val localKonanDir = "${File.userHome}/.konan"
|
||||||
val userHome = findUserHome()
|
|
||||||
val localKonanDir = "$userHome/.konan"
|
|
||||||
|
|
||||||
private fun findKonanHome(): String {
|
private fun findKonanHome(): String {
|
||||||
val value = System.getProperty("konan.home", "dist")
|
val value = System.getProperty("konan.home", "dist")
|
||||||
@@ -39,8 +38,8 @@ class Distribution(val targetManager: TargetManager,
|
|||||||
}
|
}
|
||||||
|
|
||||||
val konanHome = findKonanHome()
|
val konanHome = findKonanHome()
|
||||||
val propertyFile = propertyFileOverride ?: "$konanHome/konan/konan.properties"
|
val propertyFileName = propertyFileOverride ?: "$konanHome/konan/konan.properties"
|
||||||
val properties = KonanProperties(propertyFile)
|
val properties = File(propertyFileName).loadProperties()
|
||||||
|
|
||||||
val klib = "$konanHome/klib"
|
val klib = "$konanHome/klib"
|
||||||
|
|
||||||
|
|||||||
-47
@@ -1,47 +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 org.jetbrains.kotlin.backend.konan.util.*
|
|
||||||
|
|
||||||
public class KonanProperties(val propertyFile: String) {
|
|
||||||
|
|
||||||
val properties = Properties()
|
|
||||||
|
|
||||||
fun String.suffix(suf: String?): String =
|
|
||||||
if (suf == null) this
|
|
||||||
else "${this}.${suf}"
|
|
||||||
|
|
||||||
init {
|
|
||||||
val file = File(propertyFile)
|
|
||||||
file.bufferedReader().use { reader ->
|
|
||||||
properties.load(reader)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun propertyString(key: String, suffix: String? = null): String?
|
|
||||||
= properties.getProperty(key.suffix(suffix))
|
|
||||||
|
|
||||||
fun propertyList(key: String, suffix: String? = null): List<String> {
|
|
||||||
val value = properties.getProperty(key.suffix(suffix))
|
|
||||||
return value?.split(' ') ?: emptyList()
|
|
||||||
}
|
|
||||||
|
|
||||||
fun hasProperty(key: String, suffix: String? = null): Boolean
|
|
||||||
= properties.getProperty(key.suffix(suffix)) != null
|
|
||||||
}
|
|
||||||
|
|
||||||
+4
-8
@@ -17,10 +17,10 @@
|
|||||||
package org.jetbrains.kotlin.backend.konan
|
package org.jetbrains.kotlin.backend.konan
|
||||||
|
|
||||||
import org.jetbrains.kotlin.backend.konan.util.bufferedReader
|
import org.jetbrains.kotlin.backend.konan.util.bufferedReader
|
||||||
import java.io.File
|
|
||||||
import java.lang.ProcessBuilder
|
import java.lang.ProcessBuilder
|
||||||
import java.lang.ProcessBuilder.Redirect
|
import java.lang.ProcessBuilder.Redirect
|
||||||
import org.jetbrains.kotlin.konan.target.*
|
import org.jetbrains.kotlin.konan.target.*
|
||||||
|
import org.jetbrains.kotlin.backend.konan.util.*
|
||||||
|
|
||||||
typealias BitcodeFile = String
|
typealias BitcodeFile = String
|
||||||
typealias ObjectFile = String
|
typealias ObjectFile = String
|
||||||
@@ -32,7 +32,7 @@ internal abstract class PlatformFlags(val distribution: Distribution) {
|
|||||||
val properties = distribution.properties
|
val properties = distribution.properties
|
||||||
|
|
||||||
val hostSuffix = distribution.hostTargetSuffix
|
val hostSuffix = distribution.hostTargetSuffix
|
||||||
val targetSuffix = distribution.targetSuffix
|
val target = distribution.target
|
||||||
|
|
||||||
open val llvmLtoNooptFlags
|
open val llvmLtoNooptFlags
|
||||||
= propertyTargetList("llvmLtoNooptFlags")
|
= propertyTargetList("llvmLtoNooptFlags")
|
||||||
@@ -56,14 +56,10 @@ internal abstract class PlatformFlags(val distribution: Distribution) {
|
|||||||
|
|
||||||
open fun linkCommandSuffix(): List<String> = emptyList()
|
open fun linkCommandSuffix(): List<String> = emptyList()
|
||||||
|
|
||||||
protected fun propertyHostString(name: String)
|
|
||||||
= properties.propertyString(name, hostSuffix)!!
|
|
||||||
protected fun propertyHostList(name: String)
|
|
||||||
= properties.propertyList(name, hostSuffix)
|
|
||||||
protected fun propertyTargetString(name: String)
|
protected fun propertyTargetString(name: String)
|
||||||
= properties.propertyString(name, targetSuffix)!!
|
= properties.targetString(name, target)!!
|
||||||
protected fun propertyTargetList(name: String)
|
protected fun propertyTargetList(name: String)
|
||||||
= properties.propertyList(name, targetSuffix)
|
= properties.targetList(name, target)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+1
-4
@@ -20,10 +20,7 @@ import org.jetbrains.kotlin.backend.konan.library.KonanLibrary
|
|||||||
import org.jetbrains.kotlin.backend.konan.library.KonanLibraryReader
|
import org.jetbrains.kotlin.backend.konan.library.KonanLibraryReader
|
||||||
import org.jetbrains.kotlin.backend.konan.library.MetadataReader
|
import org.jetbrains.kotlin.backend.konan.library.MetadataReader
|
||||||
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.*
|
||||||
import org.jetbrains.kotlin.backend.konan.util.loadProperties
|
|
||||||
import org.jetbrains.kotlin.backend.konan.util.Properties
|
|
||||||
import org.jetbrains.kotlin.backend.konan.util.unzipAs
|
|
||||||
import org.jetbrains.kotlin.config.LanguageVersionSettings
|
import org.jetbrains.kotlin.config.LanguageVersionSettings
|
||||||
|
|
||||||
abstract class FileBasedLibraryReader(
|
abstract class FileBasedLibraryReader(
|
||||||
|
|||||||
+6
@@ -55,6 +55,7 @@ class File(val path: String) {
|
|||||||
fun mkdirs() = javaFile.mkdirs()
|
fun mkdirs() = javaFile.mkdirs()
|
||||||
fun delete() = javaFile.delete()
|
fun delete() = javaFile.delete()
|
||||||
fun deleteRecursively() = javaFile.deleteRecursively()
|
fun deleteRecursively() = javaFile.deleteRecursively()
|
||||||
|
fun deleteOnExit() = javaFile.deleteOnExit()
|
||||||
fun readText() = javaFile.readText()
|
fun readText() = javaFile.readText()
|
||||||
fun readBytes() = javaFile.readBytes()
|
fun readBytes() = javaFile.readBytes()
|
||||||
fun writeText(text: String) = javaFile.writeText(text)
|
fun writeText(text: String) = javaFile.writeText(text)
|
||||||
@@ -73,6 +74,11 @@ class File(val path: String) {
|
|||||||
|
|
||||||
val userHome
|
val userHome
|
||||||
get() = File(System.getProperty("user.home"))
|
get() = File(System.getProperty("user.home"))
|
||||||
|
|
||||||
|
fun createTempFile(name: String, suffix: String? = null, directory: File? = null): File {
|
||||||
|
val javaDirectory = directory ?.let { java.io.File(directory.path) }
|
||||||
|
return java.io.File.createTempFile(name, suffix, javaDirectory).path.File()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+17
@@ -33,3 +33,20 @@ fun File.saveProperties(properties: Properties) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun Properties.saveToFile(file: File) = file.saveProperties(this)
|
fun Properties.saveToFile(file: File) = file.saveProperties(this)
|
||||||
|
|
||||||
|
fun Properties.propertyString(key: String, suffix: String? = null): String?
|
||||||
|
= this.getProperty(key.suffix(suffix))
|
||||||
|
|
||||||
|
fun Properties.propertyList(key: String, suffix: String? = null): List<String> {
|
||||||
|
val value = this.getProperty(key.suffix(suffix))
|
||||||
|
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
@@ -0,0 +1,31 @@
|
|||||||
|
/*
|
||||||
|
* 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)
|
||||||
Reference in New Issue
Block a user