KLIB: Merge manifest for stdlib produced for different targets
(cherry picked from commit b7f12c9ae64f8a4a0785105a53f118083e660386)
This commit is contained in:
committed by
Vasily Levchenko
parent
35e54cd8c8
commit
bf9c66e275
@@ -7,7 +7,11 @@ package org.jetbrains.kotlin
|
||||
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.api.Task
|
||||
import org.jetbrains.kotlin.konan.properties.loadProperties
|
||||
import org.jetbrains.kotlin.konan.properties.propertyList
|
||||
import org.jetbrains.kotlin.konan.properties.saveProperties
|
||||
import org.jetbrains.kotlin.konan.target.*
|
||||
import org.jetbrains.kotlin.library.KLIB_PROPERTY_NATIVE_TARGETS
|
||||
import java.io.FileInputStream
|
||||
import java.io.IOException
|
||||
import java.io.File
|
||||
@@ -17,6 +21,7 @@ import java.net.URL
|
||||
import java.util.Base64
|
||||
import org.jetbrains.report.json.*
|
||||
import java.nio.file.Path
|
||||
import org.jetbrains.kotlin.konan.file.File as KFile
|
||||
|
||||
//region Project properties.
|
||||
|
||||
@@ -254,4 +259,60 @@ fun compileSwift(project: Project, target: KonanTarget, sources: List<String>, o
|
||||
}
|
||||
|
||||
fun targetSupportsMimallocAllocator(targetName: String) =
|
||||
HostManager().targetByName(targetName).supportsMimallocAllocator()
|
||||
HostManager().targetByName(targetName).supportsMimallocAllocator()
|
||||
|
||||
fun Project.mergeManifestsByTargets(source: File, destination: File) {
|
||||
logger.info("Merging manifests: $source -> $destination")
|
||||
|
||||
val sourceFile = KFile(source.absolutePath)
|
||||
val sourceProperties = sourceFile.loadProperties()
|
||||
|
||||
val destinationFile = KFile(destination.absolutePath)
|
||||
val destinationProperties = destinationFile.loadProperties()
|
||||
|
||||
// check that all properties except for KLIB_PROPERTY_NATIVE_TARGETS are equivalent
|
||||
val mismatchedProperties = (sourceProperties.keys + destinationProperties.keys)
|
||||
.asSequence()
|
||||
.map { it.toString() }
|
||||
.filter { it != KLIB_PROPERTY_NATIVE_TARGETS }
|
||||
.sorted()
|
||||
.mapNotNull { propertyKey: String ->
|
||||
val sourceProperty: String? = sourceProperties.getProperty(propertyKey)
|
||||
val destinationProperty: String? = destinationProperties.getProperty(propertyKey)
|
||||
when {
|
||||
sourceProperty == null -> "\"$propertyKey\" is absent in $sourceFile"
|
||||
destinationProperty == null -> "\"$propertyKey\" is absent in $destinationFile"
|
||||
sourceProperty == destinationProperty -> {
|
||||
// properties match, OK
|
||||
null
|
||||
}
|
||||
sourceProperties.propertyList(propertyKey, escapeInQuotes = true).toSet() ==
|
||||
destinationProperties.propertyList(propertyKey, escapeInQuotes = true).toSet() -> {
|
||||
// properties match, OK
|
||||
null
|
||||
}
|
||||
else -> "\"$propertyKey\" differ: [$sourceProperty] vs [$destinationProperty]"
|
||||
}
|
||||
}
|
||||
.toList()
|
||||
|
||||
check(mismatchedProperties.isEmpty()) {
|
||||
buildString {
|
||||
appendln("Found mismatched properties while merging manifest files: $source -> $destination")
|
||||
mismatchedProperties.joinTo(this, "\n")
|
||||
}
|
||||
}
|
||||
|
||||
// merge KLIB_PROPERTY_NATIVE_TARGETS property
|
||||
val sourceNativeTargets = sourceProperties.propertyList(KLIB_PROPERTY_NATIVE_TARGETS)
|
||||
val destinationNativeTargets = destinationProperties.propertyList(KLIB_PROPERTY_NATIVE_TARGETS)
|
||||
|
||||
val mergedNativeTargets = HashSet<String>().apply {
|
||||
addAll(sourceNativeTargets)
|
||||
addAll(destinationNativeTargets)
|
||||
}
|
||||
|
||||
destinationProperties[KLIB_PROPERTY_NATIVE_TARGETS] = mergedNativeTargets.joinToString(" ")
|
||||
|
||||
destinationFile.saveProperties(destinationProperties)
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@ import org.jetbrains.kotlin.CollisionDetector
|
||||
import org.jetbrains.kotlin.CollisionTransformer
|
||||
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
|
||||
import org.apache.tools.ant.filters.ReplaceTokens
|
||||
import org.jetbrains.kotlin.UtilsKt
|
||||
|
||||
buildscript {
|
||||
apply from: "gradle/kotlinGradlePlugin.gradle"
|
||||
@@ -465,6 +466,15 @@ targetList.each { target ->
|
||||
from(project(':runtime').file("build/${target}Stdlib")) {
|
||||
include('**')
|
||||
into(stdlib)
|
||||
eachFile {
|
||||
if (name == 'manifest') {
|
||||
def existingManifest = file("$destinationDir/$path")
|
||||
if (existingManifest.exists()) {
|
||||
UtilsKt.mergeManifestsByTargets(project, file, existingManifest)
|
||||
exclude()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
from(project(':runtime').file("build/$target")) {
|
||||
include("runtime.bc")
|
||||
|
||||
Reference in New Issue
Block a user