From 4ea11c5f590b73c6dad576ca9894251d3c7ae78c Mon Sep 17 00:00:00 2001 From: Nico Verbruggen Date: Fri, 1 Jan 2021 22:58:16 +0100 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20Refactoring,=20version=20b?= =?UTF-8?q?ump=20for=20M1=20support=20(#20)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- PHP Monitor.xcodeproj/project.pbxproj | 8 ++++---- phpmon/Singletons/Paths.swift | 28 ++++++++++++++------------- phpmon/Singletons/Shell.swift | 9 ++++++--- 3 files changed, 25 insertions(+), 20 deletions(-) diff --git a/PHP Monitor.xcodeproj/project.pbxproj b/PHP Monitor.xcodeproj/project.pbxproj index 21af174..2d51191 100644 --- a/PHP Monitor.xcodeproj/project.pbxproj +++ b/PHP Monitor.xcodeproj/project.pbxproj @@ -423,7 +423,7 @@ CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; - CURRENT_PROJECT_VERSION = 26; + CURRENT_PROJECT_VERSION = 28; DEVELOPMENT_TEAM = 8M54J5J787; ENABLE_HARDENED_RUNTIME = YES; INFOPLIST_FILE = phpmon/Info.plist; @@ -431,7 +431,7 @@ "$(inherited)", "@executable_path/../Frameworks", ); - MARKETING_VERSION = 2.5; + MARKETING_VERSION = 2.6; PRODUCT_BUNDLE_IDENTIFIER = com.nicoverbruggen.phpmon; PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE_SPECIFIER = ""; @@ -447,7 +447,7 @@ CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; - CURRENT_PROJECT_VERSION = 26; + CURRENT_PROJECT_VERSION = 28; DEVELOPMENT_TEAM = 8M54J5J787; ENABLE_HARDENED_RUNTIME = YES; INFOPLIST_FILE = phpmon/Info.plist; @@ -455,7 +455,7 @@ "$(inherited)", "@executable_path/../Frameworks", ); - MARKETING_VERSION = 2.5; + MARKETING_VERSION = 2.6; PRODUCT_BUNDLE_IDENTIFIER = com.nicoverbruggen.phpmon; PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE_SPECIFIER = ""; diff --git a/phpmon/Singletons/Paths.swift b/phpmon/Singletons/Paths.swift index 4356c6b..d1d5765 100644 --- a/phpmon/Singletons/Paths.swift +++ b/phpmon/Singletons/Paths.swift @@ -8,7 +8,7 @@ import Foundation -enum HomebrewDirectory: String { +enum HomebrewDir: String { case opt = "/opt/homebrew/bin" case usr = "/usr/local/bin" } @@ -16,24 +16,26 @@ enum HomebrewDirectory: String { class Paths { static let shared = Paths() - var baseDirectory : HomebrewDirectory + var baseDir : HomebrewDir init() { - let optBrewFound = Shell.fileExists("\(HomebrewDirectory.opt.rawValue)/brew") - let usrBrewFound = Shell.fileExists("\(HomebrewDirectory.usr.rawValue)/brew") + let optBrewFound = Shell.fileExists("\(HomebrewDir.opt.rawValue)/brew") + let usrBrewFound = Shell.fileExists("\(HomebrewDir.usr.rawValue)/brew") if (optBrewFound) { - self.baseDirectory = .opt + // This is usually the case with Homebrew installed on Apple Silicon + self.baseDir = .opt } else if (usrBrewFound) { - self.baseDirectory = .usr + // This is usually the case with Homebrew installed on Intel (or Rosetta 2) + self.baseDir = .usr } else { - // Falling back to Intel - print("Seems like we couldn't determine the architecture.") + // Falling back to default "legacy" Homebrew location (for Intel) + print("Seems like we couldn't determine the Homebrew directory.") print("This usually means we're in trouble... (no Homebrew?)") - self.baseDirectory = .usr + self.baseDir = .usr } - print("Homebrew directory: \(self.baseDirectory)") + print("Homebrew directory: \(self.baseDir)") } public static func brew() -> String { @@ -45,11 +47,11 @@ class Paths { } public static func binPath() -> String { - return self.shared.baseDirectory.rawValue + return self.shared.baseDir.rawValue } public static func optPath() -> String { - switch self.shared.baseDirectory { + switch self.shared.baseDir { case .opt: return "/opt/homebrew/opt" case .usr: @@ -58,7 +60,7 @@ class Paths { } public static func etcPath() -> String { - switch self.shared.baseDirectory { + switch self.shared.baseDir { case .opt: return "/opt/homebrew/etc" case .usr: diff --git a/phpmon/Singletons/Shell.swift b/phpmon/Singletons/Shell.swift index 733a1b8..81506ca 100644 --- a/phpmon/Singletons/Shell.swift +++ b/phpmon/Singletons/Shell.swift @@ -47,9 +47,12 @@ class Shell { )! } - public static func fileExists(_ filePath: String) -> Bool { + /** + Checks if a file exists at the provided path. + */ + public static func fileExists(_ path: String) -> Bool { return Shell.user.pipe( - "if [ -f \(filePath) ]; then echo \"Y\"; fi" - ).contains("Y") + "if [ -f \(path) ]; then echo \"PHP_Y_FE\"; fi" + ).contains("PHP_Y_FE") } }