From 354ccce5faf2ea167f9b68259b18844949ca5f89 Mon Sep 17 00:00:00 2001 From: Pavel Marek Date: Fri, 10 Jan 2025 14:26:41 +0100 Subject: [PATCH] Remove unused native libs from opencv (#12021) * Remove native libs of opencv or different platforms * Fix Mac os name * Include Mac native libs in signing --- .../client/tasks/signArchivesMacOs.ts | 10 +++--- project/StdBits.scala | 32 ++++++++++++++++++- 2 files changed, 36 insertions(+), 6 deletions(-) diff --git a/app/ide-desktop/client/tasks/signArchivesMacOs.ts b/app/ide-desktop/client/tasks/signArchivesMacOs.ts index f009b12bfc9a..1d15f1460394 100644 --- a/app/ide-desktop/client/tasks/signArchivesMacOs.ts +++ b/app/ide-desktop/client/tasks/signArchivesMacOs.ts @@ -134,12 +134,12 @@ async function ensoPackageSignables(resourcesDir: string): Promise { ['META-INF/native/libconscrypt_openjdk_jni-osx-*.dylib'], ], ['lib/Standard/Tableau/*/polyglot/java/jna-*.jar', ['com/sun/jna/*/libjnidispatch.jnilib']], - [ - 'lib/Standard/Image/*/polyglot/java/opencv-*.jar', - ['nu/pattern/opencv/osx/*/libopencv_java*.dylib'], - ], ] - return ArchiveToSign.lookupMany(engineDir, archivePatterns) + const binariesPattern = 'lib/Standard/Image/*/polyglot/lib/*.dylib' + + const binaries = await BinaryToSign.lookupMany(engineDir, [binariesPattern]) + const archives = await ArchiveToSign.lookupMany(engineDir, archivePatterns) + return [...archives, ...binaries] } // ================ diff --git a/project/StdBits.scala b/project/StdBits.scala index e52de6c98e88..b6300ad3a905 100644 --- a/project/StdBits.scala +++ b/project/StdBits.scala @@ -5,6 +5,7 @@ import sbt.io.IO import sbt.librarymanagement.{ConfigurationFilter, DependencyFilter} import java.io.File +import java.util.Locale object StdBits { @@ -132,7 +133,10 @@ object StdBits { if ( strippedEntryName.contains("linux/ARM") || strippedEntryName.contains("linux/x86_32") || - strippedEntryName.contains("README.md") + strippedEntryName.contains("README.md") || + // Remove native libs for different platforms + (!strippedEntryName.contains(osName())) || + (!strippedEntryName.contains(arch())) ) { None } else { @@ -171,6 +175,32 @@ object StdBits { ) } + /** Inspired by `org.enso.pkg.NativeLibraryFinder` + */ + private def osName(): String = { + var osName = System.getProperty("os.name").toLowerCase(Locale.ENGLISH) + if (osName.contains(" ")) { + // Strip version + osName = osName.substring(0, osName.indexOf(' ')) + } + if (osName.contains("linux")) { + "linux" + } else if (osName.contains("mac")) { + "osx" + } else if (osName.contains("windows")) { + "windows" + } else { + throw new IllegalStateException(s"Unsupported OS: $osName") + } + } + + /** Inspired by `org.enso.pkg.NativeLibraryFinder` + */ + private def arch(): String = { + val arch = System.getProperty("os.arch").toLowerCase(Locale.ENGLISH) + arch.replace("amd64", "x86_64") + } + private def updateDependency( jar: File, destinationDir: File,