From d18ade088d64ae362ee1bf76d3487d65743984dd Mon Sep 17 00:00:00 2001 From: Pavel Kunyavskiy Date: Wed, 28 Jul 2021 15:37:42 +0300 Subject: [PATCH] [K/N] Help message for disabling quarantine flag on dylibs in distribution --- .../src/jvm/kotlin/kotlinx/cinterop/JvmUtils.kt | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/kotlin-native/Interop/Runtime/src/jvm/kotlin/kotlinx/cinterop/JvmUtils.kt b/kotlin-native/Interop/Runtime/src/jvm/kotlin/kotlinx/cinterop/JvmUtils.kt index e9bc4b35316..b1078852683 100644 --- a/kotlin-native/Interop/Runtime/src/jvm/kotlin/kotlinx/cinterop/JvmUtils.kt +++ b/kotlin-native/Interop/Runtime/src/jvm/kotlin/kotlinx/cinterop/JvmUtils.kt @@ -111,6 +111,17 @@ fun loadKonanLibrary(name: String) { try { System.load("$dir/$fullLibraryName") } catch (e: UnsatisfiedLinkError) { + if (fullLibraryName.endsWith(".dylib") && e.message?.contains("library load disallowed by system policy") == true) { + throw UnsatisfiedLinkError(""" + |Library $dir/$fullLibraryName can't be loaded. + |${'\t'}This can happen because library file is marked as untrusted (e.g because it was downloaded from browser). + |${'\t'}You can trust libraries in distribution by running + |${'\t'}${'\t'}xattr -d com.apple.quarantine '$dir'/* + |${'\t'}command in terminal + |${'\t'}Original exception message: + |${'\t'}${e.message} + """.trimMargin()) + } val tempDir = Files.createTempDirectory(Paths.get(dir), null).toAbsolutePath().toString() Files.createLink(Paths.get(tempDir, fullLibraryName), Paths.get(dir, fullLibraryName)) // TODO: Does not work on Windows. May be use FILE_FLAG_DELETE_ON_CLOSE?