Directly sign plugins and frameworks within app bundle in mac crafter
authorClaudio Cambra <claudio.cambra@nextcloud.com>
Thu, 20 Jun 2024 11:33:50 +0000 (19:33 +0800)
committerClaudio Cambra <developer@claudiocambra.com>
Mon, 8 Jul 2024 07:41:45 +0000 (15:41 +0800)
Signed-off-by: Claudio Cambra <claudio.cambra@nextcloud.com>
admin/osx/mac-crafter/Sources/main.swift

index 7a40f0731576bff83fb2afdec7dbf2a96cbb9d10..7e1bcf96f4442a68de80306de582bd219fa97aa3 100644 (file)
@@ -46,9 +46,6 @@ struct MacCrafter: ParsableCommand {
     @Option(name: [.long], help: "Build type (e.g. Release, RelWithDebInfo, MinSizeRel, Debug).")
     var buildType = "RelWithDebInfo"
 
-    @Option(name: [.long], help: "Skip code-signing dependency libraries and plugins.")
-    var skipDependencyCodeSigning = false
-
     @Option(name: [.long], help: "Skip craft configuration.")
     var skipCraftConfiguration = false
 
@@ -103,39 +100,42 @@ struct MacCrafter: ParsableCommand {
             shell("\(craftCommand) --install-deps nextcloud-client")
         }
 
-        if !skipCraftConfiguration, !skipDependencyCodeSigning, let codeSignIdentity {
-            print("Code-signing Nextcloud Desktop Client libraries and frameworks...")
+        print("Crafting Nextcloud Desktop Client...")
+        shell("\(craftCommand) --src-dir \(repoRootDir) -i --buildtype \(buildType) nextcloud-client")
 
-            let craftLibDir = "\(buildPath)/\(craftTarget)/lib"
-            let craftLibs = try fm.contentsOfDirectory(atPath: craftLibDir)
-            for lib in craftLibs {
-                guard isLibrary(lib) else { continue }
-                try codesign(identity: codeSignIdentity, path: "\(craftLibDir)/\(lib)")
-            }
+        guard let codeSignIdentity else {
+            print("Crafted Nextcloud Desktop Client. Not codesigned.")
+            return
+        }
 
-            let craftPluginsDir = "\(buildPath)/\(craftTarget)/plugins"
-            guard let craftPluginsEnumerator = fm.enumerator(atPath: craftPluginsDir) else {
-                throw MacCrafterError.failedEnumeration(
-                    "Failed to list craft plugins directory at \(craftPluginsDir)."
-                )
-            }
+        print("Code-signing Nextcloud Desktop Client libraries and frameworks...")
 
-            for case let plugin as String in craftPluginsEnumerator {
-                guard isLibrary(plugin) else { continue }
-                try codesign(identity: codeSignIdentity, path: "\(craftPluginsDir)/\(plugin)")
-            }
+        let craftBuildDir = "\(buildPath)/\(craftTarget)/build"
+        let clientAppDir =
+            "\(craftBuildDir)/nextcloud-client/image-\(buildType)-master/\(appName).app"
+        let clientFrameworksDir = "\(clientAppDir)/Contents/Frameworks"
+        let clientLibs = try fm.contentsOfDirectory(atPath: clientFrameworksDir)
+        for lib in clientLibs {
+            guard isLibrary(lib) else { continue }
+            try codesign(identity: codeSignIdentity, path: "\(clientFrameworksDir)/\(lib)")
         }
 
-        print("Crafting Nextcloud Desktop Client...")
-        shell("\(craftCommand) --src-dir \(repoRootDir) -i --buildtype \(buildType) nextcloud-client")
+        let clientPluginsDir = "\(clientAppDir)/Contents/PlugIns"
+        guard let clientPluginsEnumerator = fm.enumerator(atPath: clientPluginsDir) else {
+            throw MacCrafterError.failedEnumeration(
+                "Failed to list craft plugins directory at \(clientPluginsDir)."
+            )
+        }
 
-        if let codeSignIdentity {
-            print("Code-signing Nextcloud Desktop Client app bundle...")
-            let craftBuildDir = "\(buildPath)/\(craftTarget)/build"
-            let clientAppDir =
-                "\(craftBuildDir)/nextcloud-client/image-\(buildType)-master/\(appName).app"
-            try codesign(identity: codeSignIdentity, path: clientAppDir)
+        for case let plugin as String in clientPluginsEnumerator {
+            guard isLibrary(plugin) else { continue }
+            try codesign(identity: codeSignIdentity, path: "\(clientPluginsDir)/\(plugin)")
         }
+
+        print("Code-signing Nextcloud Desktop Client app bundle...")
+        try codesign(identity: codeSignIdentity, path: clientAppDir)
+
+        print("Done!")
     }
 }