diff --git a/backend.native/cli.bc/src/org/jetbrains/kotlin/cli/bc/K2Native.kt b/backend.native/cli.bc/src/org/jetbrains/kotlin/cli/bc/K2Native.kt index 6cebce4e186..7edd318dd1c 100644 --- a/backend.native/cli.bc/src/org/jetbrains/kotlin/cli/bc/K2Native.kt +++ b/backend.native/cli.bc/src/org/jetbrains/kotlin/cli/bc/K2Native.kt @@ -42,7 +42,7 @@ private fun maybeExecuteHelper(targetName: String) { val distribution = Distribution(TargetManager(targetName)) val result = ctor.call( distribution.dependenciesDir, - distribution.properties.properties, + distribution.properties, distribution.dependencies ) result.run() diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/Distribution.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/Distribution.kt index f3634f2f315..a1ddb3e1f85 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/Distribution.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/Distribution.kt @@ -16,21 +16,20 @@ package org.jetbrains.kotlin.backend.konan -import java.io.File import org.jetbrains.kotlin.konan.target.* +import org.jetbrains.kotlin.backend.konan.util.* class Distribution(val targetManager: TargetManager, val propertyFileOverride: String? = null, val runtimeFileOverride: String? = null) { + val target = targetManager.target val targetName = targetManager.targetName val hostSuffix = targetManager.hostSuffix val hostTargetSuffix = targetManager.hostTargetSuffix val targetSuffix = targetManager.targetSuffix - private fun findUserHome() = File(System.getProperty("user.home")).absolutePath - val userHome = findUserHome() - val localKonanDir = "$userHome/.konan" + val localKonanDir = "${File.userHome}/.konan" private fun findKonanHome(): String { val value = System.getProperty("konan.home", "dist") @@ -39,8 +38,8 @@ class Distribution(val targetManager: TargetManager, } val konanHome = findKonanHome() - val propertyFile = propertyFileOverride ?: "$konanHome/konan/konan.properties" - val properties = KonanProperties(propertyFile) + val propertyFileName = propertyFileOverride ?: "$konanHome/konan/konan.properties" + val properties = File(propertyFileName).loadProperties() val klib = "$konanHome/klib" diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/KonanProperties.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/KonanProperties.kt deleted file mode 100644 index de89043ede4..00000000000 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/KonanProperties.kt +++ /dev/null @@ -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 { - 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 -} - diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/LinkStage.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/LinkStage.kt index 7c5975a4678..cf3ccc15c0e 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/LinkStage.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/LinkStage.kt @@ -17,10 +17,10 @@ package org.jetbrains.kotlin.backend.konan import org.jetbrains.kotlin.backend.konan.util.bufferedReader -import java.io.File import java.lang.ProcessBuilder import java.lang.ProcessBuilder.Redirect import org.jetbrains.kotlin.konan.target.* +import org.jetbrains.kotlin.backend.konan.util.* typealias BitcodeFile = String typealias ObjectFile = String @@ -32,7 +32,7 @@ internal abstract class PlatformFlags(val distribution: Distribution) { val properties = distribution.properties val hostSuffix = distribution.hostTargetSuffix - val targetSuffix = distribution.targetSuffix + val target = distribution.target open val llvmLtoNooptFlags = propertyTargetList("llvmLtoNooptFlags") @@ -56,14 +56,10 @@ internal abstract class PlatformFlags(val distribution: Distribution) { open fun linkCommandSuffix(): List = emptyList() - protected fun propertyHostString(name: String) - = properties.propertyString(name, hostSuffix)!! - protected fun propertyHostList(name: String) - = properties.propertyList(name, hostSuffix) protected fun propertyTargetString(name: String) - = properties.propertyString(name, targetSuffix)!! + = properties.targetString(name, target)!! protected fun propertyTargetList(name: String) - = properties.propertyList(name, targetSuffix) + = properties.targetList(name, target) } diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/library/impl/KonanLibraryReaderImpl.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/library/impl/KonanLibraryReaderImpl.kt index 959fab42500..ab4399b8283 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/library/impl/KonanLibraryReaderImpl.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/library/impl/KonanLibraryReaderImpl.kt @@ -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.MetadataReader import org.jetbrains.kotlin.backend.konan.serialization.deserializeModule -import org.jetbrains.kotlin.backend.konan.util.File -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.backend.konan.util.* import org.jetbrains.kotlin.config.LanguageVersionSettings abstract class FileBasedLibraryReader( diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/util/NoJavaUtil.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/util/NoJavaUtil.kt index 32dfe5910a3..b89cd79cb21 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/util/NoJavaUtil.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/util/NoJavaUtil.kt @@ -55,6 +55,7 @@ class File(val path: String) { fun mkdirs() = javaFile.mkdirs() fun delete() = javaFile.delete() fun deleteRecursively() = javaFile.deleteRecursively() + fun deleteOnExit() = javaFile.deleteOnExit() fun readText() = javaFile.readText() fun readBytes() = javaFile.readBytes() fun writeText(text: String) = javaFile.writeText(text) @@ -73,6 +74,11 @@ class File(val path: String) { val userHome 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() + } } } diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/util/Properties.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/util/Properties.kt index 92e9b2d4c73..22b9c2405c6 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/util/Properties.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/util/Properties.kt @@ -33,3 +33,20 @@ fun File.saveProperties(properties: Properties) { } 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 { + 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}" + + diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/util/TargetProperties.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/util/TargetProperties.kt new file mode 100644 index 00000000000..7409dbce2c2 --- /dev/null +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/util/TargetProperties.kt @@ -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 + = 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 + = this.propertyList(name, target.targetSuffix)