Allow arch and family susbtitutions in manifest files.

This commit is contained in:
Alexander Gorshenev
2018-04-22 15:32:26 +03:00
committed by alexander-gorshenev
parent f005a5664e
commit 6dc6ba5137
4 changed files with 33 additions and 25 deletions
@@ -24,6 +24,8 @@ 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
import org.jetbrains.kotlin.konan.util.defaultTargetSubstitutions
import org.jetbrains.kotlin.konan.util.substitute
class LibraryReaderImpl(var libraryFile: File, val currentAbiVersion: Int,
val target: KonanTarget? = null, override val isDefaultLibrary: Boolean = false)
@@ -39,7 +41,9 @@ class LibraryReaderImpl(var libraryFile: File, val currentAbiVersion: Int,
private val reader = MetadataReaderImpl(inPlace)
override val manifestProperties: Properties by lazy {
inPlace.manifestFile.loadProperties()
val properties = inPlace.manifestFile.loadProperties()
if (target != null) substitute(properties, defaultTargetSubstitutions(target))
properties
}
val abiVersion: String
@@ -141,21 +141,4 @@ private fun parseDefFile(file: File?, substitutions: Map<String, String>): Tripl
return Triple(properties, manifestAddendProperties, headerLines)
}
// Performs substitution similar to:
// foo = ${foo} ${foo.${arch}} ${foo.${os}}
fun substitute(properties: Properties, substitutions: Map<String, String>) {
for (key in properties.stringPropertyNames()) {
for (substitution in substitutions.values) {
val suffix = ".$substitution"
if (key.endsWith(suffix)) {
val baseKey = key.removeSuffix(suffix)
val oldValue = properties.getProperty(baseKey, "")
val appendedValue = properties.getProperty(key, "")
val newValue = if (oldValue != "") "$oldValue $appendedValue" else appendedValue
properties.setProperty(baseKey, newValue)
}
}
}
}
private fun Properties.duplicate() = Properties().apply { putAll(this@duplicate) }
@@ -0,0 +1,27 @@
package org.jetbrains.kotlin.konan.util
import org.jetbrains.kotlin.konan.target.KonanTarget
import java.util.*
fun defaultTargetSubstitutions(target: KonanTarget) =
mapOf<String, String>(
"target" to target.visibleName,
"arch" to target.architecture.visibleName,
"family" to target.family.visibleName)
// Performs substitution similar to:
// foo = ${foo} ${foo.${arch}} ${foo.${os}}
fun substitute(properties: Properties, substitutions: Map<String, String>) {
for (key in properties.stringPropertyNames()) {
for (substitution in substitutions.values) {
val suffix = ".$substitution"
if (key.endsWith(suffix)) {
val baseKey = key.removeSuffix(suffix)
val oldValue = properties.getProperty(baseKey, "")
val appendedValue = properties.getProperty(key, "")
val newValue = if (oldValue != "") "$oldValue $appendedValue" else appendedValue
properties.setProperty(baseKey, newValue)
}
}
}
}
@@ -3,10 +3,4 @@ package org.jetbrains.kotlin.konan.util
import org.jetbrains.kotlin.konan.target.KonanTarget
import java.io.File
fun defaultTargetSubstitutions(target: KonanTarget) =
mapOf<String, String>(
"target" to target.visibleName,
"arch" to target.architecture.visibleName,
"family" to target.family.visibleName)
fun DefFile(file: File?, target: KonanTarget) = DefFile(file, defaultTargetSubstitutions(target))
fun DefFile(file: File?, target: KonanTarget) = DefFile(file, defaultTargetSubstitutions(target))