Skip to content

Commit

Permalink
Merge pull request #18 from vkormushkin/ruby_m1_failure
Browse files Browse the repository at this point in the history
Fix for #16: Failure if system ruby is used on a M1 mac
  • Loading branch information
terrakok authored Apr 19, 2022
2 parents 51cf1e1 + 7d99e86 commit 53d8a8d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> =
System.execute("/usr/bin/mdfind", "kMDItemCFBundleIdentifier=\"$appId\"").output
Expand All @@ -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
Expand Down

0 comments on commit 53d8a8d

Please sign in to comment.