From 7d99e8693629d750a498f3d2cba359159348a1b2 Mon Sep 17 00:00:00 2001 From: Viacheslav Kormushkin Date: Wed, 13 Apr 2022 18:51:55 +0300 Subject: [PATCH] Failure if system ruby is used on a M1 mac --- .../doctor/diagnostics/CocoapodsDiagnostic.kt | 17 +++++++++++++---- .../doctor/diagnostics/SystemDiagnostic.kt | 2 +- .../jetbrains/kotlin/doctor/entity/System.kt | 15 ++++++--------- 3 files changed, 20 insertions(+), 14 deletions(-) diff --git a/kdoctor/src/commonMain/kotlin/org/jetbrains/kotlin/doctor/diagnostics/CocoapodsDiagnostic.kt b/kdoctor/src/commonMain/kotlin/org/jetbrains/kotlin/doctor/diagnostics/CocoapodsDiagnostic.kt index 2251fe2..bfd9575 100644 --- a/kdoctor/src/commonMain/kotlin/org/jetbrains/kotlin/doctor/diagnostics/CocoapodsDiagnostic.kt +++ b/kdoctor/src/commonMain/kotlin/org/jetbrains/kotlin/doctor/diagnostics/CocoapodsDiagnostic.kt @@ -34,10 +34,19 @@ class CocoapodsDiagnostic : Diagnostic("Cocoapods") { messages.addSuccess("${ruby.name} (${ruby.version})") if (ruby.location == "/usr/bin/ruby") { - messages.addInfo( - "System ruby is currently used", - "Consider installing ruby via Homebrew, rvm or other package manager in case of issues with cocoapods installation" - ) + var title = "System ruby is currently used" + if (System.isUsingM1) { + messages.addFailure( + title, + "CocoaPods is not compatible with system ruby installation on Apple M1 computers.", + "Please install ruby 2.7 via Homebrew, rvm, rbenv or other tool and make it default" + ) + } else { + messages.addInfo( + title, + "Consider installing ruby 2.7 via Homebrew, rvm or other package manager in case of issues with CocoaPods installation" + ) + } } val rubyGemsVersion = System.execute("gem", "-v").output diff --git a/kdoctor/src/commonMain/kotlin/org/jetbrains/kotlin/doctor/diagnostics/SystemDiagnostic.kt b/kdoctor/src/commonMain/kotlin/org/jetbrains/kotlin/doctor/diagnostics/SystemDiagnostic.kt index cdd0bed..5957634 100644 --- a/kdoctor/src/commonMain/kotlin/org/jetbrains/kotlin/doctor/diagnostics/SystemDiagnostic.kt +++ b/kdoctor/src/commonMain/kotlin/org/jetbrains/kotlin/doctor/diagnostics/SystemDiagnostic.kt @@ -11,7 +11,7 @@ class SystemDiagnostic : Diagnostic("System") { resultType = if (System.type == SystemType.MacOS) ResultType.Success else ResultType.Failure, text = """ OS: ${System.type} (${System.getVersion() ?: "N/A"}) - ${System.getHardwareInfo() ?: ""} + ${System.getCPUInfo() ?: ""} """.trimIndent() ) ) diff --git a/kdoctor/src/commonMain/kotlin/org/jetbrains/kotlin/doctor/entity/System.kt b/kdoctor/src/commonMain/kotlin/org/jetbrains/kotlin/doctor/entity/System.kt index 288a12b..bb5e0a1 100644 --- a/kdoctor/src/commonMain/kotlin/org/jetbrains/kotlin/doctor/entity/System.kt +++ b/kdoctor/src/commonMain/kotlin/org/jetbrains/kotlin/doctor/entity/System.kt @@ -21,18 +21,13 @@ object System { val isUsingRosetta by lazy { isUsingRosetta() } + val isUsingM1 by lazy { isUsingM1() } + fun getVersion() = System.execute("sw_vers", "-productVersion").output?.let { Version(it) } - fun getHardwareInfo(): String? = if (isUsingRosetta) { - System.execute("sysctl", "-n", "machdep.cpu.brand_string", "").output - ?.let { "CPU: $it" } - } else { - System.execute("system_profiler", "SPHardwareDataType").output?.lines() - ?.firstOrNull { it.contains("Processor Name") || it.contains("Chip") } - ?.split(":")?.lastOrNull() - ?.let { "CPU: $it" } - } + fun getCPUInfo(): String? = System.execute("sysctl", "-n", "machdep.cpu.brand_string", "").output + ?.let { "CPU: $it" } fun findAppPaths(appId: String): List = System.execute("/usr/bin/mdfind", "kMDItemCFBundleIdentifier=\"$appId\"").output @@ -51,6 +46,8 @@ object System { private fun isUsingRosetta(): Boolean = System.execute("sysctl", "sysctl.proc_translated").output ?.substringAfter("sysctl.proc_translated: ") ?.toIntOrNull() == 1 + + private fun isUsingM1(): Boolean = getCPUInfo()?.contains("Apple") == true } expect fun System.getCurrentSystemType(): SystemType