Fix def file substitutions

Properly handle the case when platform-specific property is specified
but the base one isn't.
This commit is contained in:
Svyatoslav Scherbina
2017-04-25 15:41:03 +03:00
committed by SvyatoslavScherbina
parent 9926b281dd
commit 94ff4d69be
@@ -84,19 +84,16 @@ private fun String.targetSuffix(): String =
// foo = ${foo} ${foo.${arch}} ${foo.${os}}
private fun substitute(properties: Properties, substitutions: Map<String, String>) {
for (key in properties.stringPropertyNames()) {
if (key.contains('.')) {
continue
}
var value = ""
for (substitution in substitutions.keys) {
val property = properties.getProperty(key + "." + substitutions[substitution])
if (property != null) {
value += " " + property
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)
}
}
if (value != "") {
properties.setProperty(key, properties.getProperty(key, "") + " " + value)
}
}
}