diff --git a/Interop/StubGenerator/src/main/kotlin/org/jetbrains/kotlin/native/interop/gen/jvm/main.kt b/Interop/StubGenerator/src/main/kotlin/org/jetbrains/kotlin/native/interop/gen/jvm/main.kt index 7744656d67b..631c1960ba5 100644 --- a/Interop/StubGenerator/src/main/kotlin/org/jetbrains/kotlin/native/interop/gen/jvm/main.kt +++ b/Interop/StubGenerator/src/main/kotlin/org/jetbrains/kotlin/native/interop/gen/jvm/main.kt @@ -142,6 +142,18 @@ private fun Properties.storeProperties(file: File) { } } +private fun Properties.putAndRunOnReplace(key: Any, newValue: Any, beforeReplace: (Any, Any, Any) -> Unit) { + val oldValue = this[key] + if (oldValue != null && oldValue!! != newValue) { + beforeReplace(key, oldValue!!, newValue) + } + this[key] = newValue +} + +private fun warn(msg: String) { + println("warning: $msg") +} + private fun usage() { println(""" Run interop tool with -def .def @@ -318,7 +330,13 @@ private fun processLib(args: Map>, // TODO: if a library has partially included headers, then it shouldn't be used as a dependency. def.manifestAddendProperties["includedHeaders"] = nativeIndex.includedHeaders.joinToString(" ") { it.value } - def.manifestAddendProperties["pkg"] = outKtPkg + + def.manifestAddendProperties.putAndRunOnReplace("package", outKtPkg) { + key, oldValue, newValue -> + warn("The package value `$oldValue` specified in .def file is overriden with explicit $newValue") + } + + def.manifestAddendProperties["interop"] = "true" gen.addManifestProperties(def.manifestAddendProperties) diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/InteropUtils.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/InteropUtils.kt index 81df0a9f521..6fd0a2fdb08 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/InteropUtils.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/InteropUtils.kt @@ -39,7 +39,9 @@ interface InteropLibrary { } fun createInteropLibrary(reader: KonanLibraryReader): InteropLibrary? { - val pkg = reader.manifestProperties.getProperty("pkg") ?: return null + if (reader.manifestProperties.getProperty("interop") != "true") return null + val pkg = reader.manifestProperties.getProperty("package") + ?: error("Inconsistent manifest: interop library ${reader.libraryName} should have `package` specified") val exportForwardDeclarations = reader.manifestProperties .getProperty("exportForwardDeclarations").split(' ') .map { it.trim() }.filter { it.isNotEmpty() } diff --git a/utilities/src/main/kotlin/org/jetbrains/kotlin/cli/utilities/main.kt b/utilities/src/main/kotlin/org/jetbrains/kotlin/cli/utilities/main.kt index 18475d8e49e..92f86178db8 100644 --- a/utilities/src/main/kotlin/org/jetbrains/kotlin/cli/utilities/main.kt +++ b/utilities/src/main/kotlin/org/jetbrains/kotlin/cli/utilities/main.kt @@ -69,7 +69,7 @@ fun invokeCinterop(args: Array) { val library = KonanLibrary(it.libraryFile) val manifestProperties = library.manifestFile.loadProperties() // TODO: handle missing properties? - manifestProperties["pkg"]?.let { + manifestProperties["package"]?.let { val pkg = it as String val headerIds = (manifestProperties["includedHeaders"] as String).split(' ') val arg = "$pkg:${headerIds.joinToString(",")}"