Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rosetta detection and support added #12

Merged
merged 3 commits into from
Feb 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,24 @@ import org.jetbrains.kotlin.doctor.entity.System
import org.jetbrains.kotlin.doctor.entity.SystemType

class SystemDiagnostic : Diagnostic("System") {
override fun runChecks() = listOf(
Message(
if (System.type == SystemType.MacOS) ResultType.Success else ResultType.Failure,
"""
${System.type} (${System.getVersion() ?: "N/A"})
${System.getHardwareInfo() ?: ""}

""".trimIndent()

override fun runChecks() = buildList {
add(
Message(
resultType = if (System.type == SystemType.MacOS) ResultType.Success else ResultType.Failure,
text = """
OS: ${System.type} (${System.getVersion() ?: "N/A"})
${System.getHardwareInfo() ?: ""}
""".trimIndent()
)
)
)
}

if (System.isUsingRosetta) {
this.addInfo(
title = "You are currently using Rosetta 2.",
"It may cause some issues while trying to install packages using Homebrew.",
"Consider switching off Rosetta 2 or ignore this message in case you actually need it."
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,20 @@ object System {
val type: SystemType = getCurrentSystemType()
val homeDir: String = getHomeDir()

val isUsingRosetta by lazy { isUsingRosetta() }

fun getVersion() =
System.execute("sw_vers", "-productVersion").output?.let { Version(it) }

fun getHardwareInfo(): String? =
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" }
?.split(":")?.lastOrNull()
?.let { "CPU: $it" }
}

fun findAppPaths(appId: String): List<String> =
System.execute("/usr/bin/mdfind", "kMDItemCFBundleIdentifier=\"$appId\"").output
Expand All @@ -40,6 +47,10 @@ object System {
val shellPath = getEnvVar("SHELL")
return Shell.values().singleOrNull { it.path == shellPath }
}

private fun isUsingRosetta(): Boolean = System.execute("sysctl", "sysctl.proc_translated").output
?.substringAfter("sysctl.proc_translated: ")
?.toIntOrNull() == 1
}

expect fun System.getCurrentSystemType(): SystemType
Expand Down