diff --git a/admin/osx/mac-crafter/Sources/Utils/Codesign.swift b/admin/osx/mac-crafter/Sources/Utils/Codesign.swift new file mode 100644 index 000000000..78ea5af2e --- /dev/null +++ b/admin/osx/mac-crafter/Sources/Utils/Codesign.swift @@ -0,0 +1,28 @@ +/* + * Copyright (C) 2024 by Claudio Cambra + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + */ + +import Foundation + +func codesign( + identity: String, + path: String, + options: String = "--timestamp --force --preserve-metadata=entitlements --verbose=4 --options runtime" +) { + print("Code-signing \(path)...") + let command = "codesign -s \"\(identity)\" \(options) \(path)" + guard shell(command) == 0 else { + print("Failed to code-sign \(path).") + exit(1) + } +} diff --git a/admin/osx/mac-crafter/Sources/Utils/Install.swift b/admin/osx/mac-crafter/Sources/Utils/Install.swift new file mode 100644 index 000000000..2406b1440 --- /dev/null +++ b/admin/osx/mac-crafter/Sources/Utils/Install.swift @@ -0,0 +1,32 @@ +/* + * Copyright (C) 2024 by Claudio Cambra + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + */ + +import Foundation + +func installIfMissing( + _ command: String, + _ installCommand: String, + installCommandEnv: [String: String]? = nil +) { + if commandExists(command) { + print("\(command) is installed.") + } else { + print("\(command) is missing. Installing...") + guard shell(installCommand, env: installCommandEnv) == 0 else { + print("Failed to install \(command).") + exit(1) + } + print("\(command) installed.") + } +} diff --git a/admin/osx/mac-crafter/Sources/Utils/Shell.swift b/admin/osx/mac-crafter/Sources/Utils/Shell.swift new file mode 100644 index 000000000..a240ccffa --- /dev/null +++ b/admin/osx/mac-crafter/Sources/Utils/Shell.swift @@ -0,0 +1,60 @@ +/* + * Copyright (C) 2024 by Claudio Cambra + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + */ + +import Foundation + +@discardableResult +func run( + _ launchPath: String, + _ args: [String], + env: [String: String]? = nil, + quiet: Bool = false +) -> Int32 { + let task = Process() + task.launchPath = launchPath + task.arguments = args + + if let env, + let combinedEnv = task.environment?.merging(env, uniquingKeysWith: { (_, new) in new }) + { + task.environment = combinedEnv + } + + if quiet { + task.standardOutput = nil + task.standardError = nil + } + + task.launch() + task.waitUntilExit() + return task.terminationStatus +} + +func run( + _ launchPath: String, + _ args: String..., + env: [String: String]? = nil, + quiet: Bool = false +) -> Int32 { + return run(launchPath, args, env: env, quiet: quiet) +} + +@discardableResult +func shell(_ commands: String..., env: [String: String]? = nil, quiet: Bool = false) -> Int32 { + return run("/bin/zsh", ["-c"] + commands, env: env, quiet: quiet) +} + +func commandExists(_ command: String) -> Bool { + return run("/usr/bin/type", command, quiet: true) == 0 +} diff --git a/admin/osx/mac-crafter/Sources/main.swift b/admin/osx/mac-crafter/Sources/main.swift index a18bc5cbb..1c3239d1c 100644 --- a/admin/osx/mac-crafter/Sources/main.swift +++ b/admin/osx/mac-crafter/Sources/main.swift @@ -14,81 +14,6 @@ import Foundation -@discardableResult -func run( - _ launchPath: String, - _ args: [String], - env: [String: String]? = nil, - quiet: Bool = false -) -> Int32 { - let task = Process() - task.launchPath = launchPath - task.arguments = args - - if let env, - let combinedEnv = task.environment?.merging(env, uniquingKeysWith: { (_, new) in new }) - { - task.environment = combinedEnv - } - - if quiet { - task.standardOutput = nil - task.standardError = nil - } - - task.launch() - task.waitUntilExit() - return task.terminationStatus -} - -func run( - _ launchPath: String, - _ args: String..., - env: [String: String]? = nil, - quiet: Bool = false -) -> Int32 { - return run(launchPath, args, env: env, quiet: quiet) -} - -@discardableResult -func shell(_ commands: String..., env: [String: String]? = nil, quiet: Bool = false) -> Int32 { - return run("/bin/zsh", ["-c"] + commands, env: env, quiet: quiet) -} - -func commandExists(_ command: String) -> Bool { - return run("/usr/bin/type", command, quiet: true) == 0 -} - -func installIfMissing( - _ command: String, - _ installCommand: String, - installCommandEnv: [String: String]? = nil -) { - if commandExists(command) { - print("\(command) is installed.") - } else { - print("\(command) is missing. Installing...") - guard shell(installCommand, env: installCommandEnv) == 0 else { - print("Failed to install \(command).") - exit(1) - } - print("\(command) installed.") - } -} - -func codesign( - identity: String, - path: String, - options: String = "--timestamp --force --preserve-metadata=entitlements --verbose=4 --options runtime" -) { - print("Code-signing \(path)...") - let command = "codesign -s \"\(identity)\" \(options) \(path)" - guard shell(command) == 0 else { - print("Failed to code-sign \(path).") - exit(1) - } -} - print("Configuring build tooling.") installIfMissing("git", "xcode-select --install") @@ -105,20 +30,20 @@ print("Configuring KDE Craft.") let fm = FileManager.default let currentDir = fm.currentDirectoryPath -let craftDir = "\(currentDir)/craftmaster" +let craftMasterDir = "\(currentDir)/craftmaster" -if fm.fileExists(atPath: craftDir) { +if fm.fileExists(atPath: craftMasterDir) { print("KDE Craft is already cloned.") } else { print("Cloning KDE Craft...") - shell("git clone -q --depth=1 https://invent.kde.org/packaging/craftmaster.git \(craftDir)") + shell("git clone --depth=1 https://invent.kde.org/packaging/craftmaster.git \(craftMasterDir)") } print("Configuring Nextcloud Desktop Client blueprints for KDE Craft...") let repoRootDir = "\(currentDir)/../.." let craftMasterIni = "\(repoRootDir)/craftmaster.ini" -let craftMasterPy = "\(craftDir)/CraftMaster.py" +let craftMasterPy = "\(craftMasterDir)/CraftMaster.py" let craftTarget = "macos-clang-arm64" let craftCommand = "python3 \(craftMasterPy) --config \(craftMasterIni) --target \(craftTarget) -c" let clientBlueprintsGitUrl = "https://github.com/nextcloud/desktop-client-blueprints.git"