Skip to content

Commit

Permalink
fix macos architecture check
Browse files Browse the repository at this point in the history
use /usr/bin/arch to detect what architecture we are actually running on
instead of what arch the jre was built for. This fixes the case of using
an intel version of the jvm on arm.

Fixes cashapp#1031
  • Loading branch information
evant committed Nov 21, 2023
1 parent 7601c21 commit 4144d06
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions paparazzi/src/main/java/app/cash/paparazzi/internal/Renderer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import java.io.File
import java.nio.file.Paths
import java.util.Locale
import kotlin.io.path.name
import kotlin.jvm.optionals.getOrNull

/** View rendering. */
internal class Renderer(
Expand Down Expand Up @@ -188,12 +189,28 @@ internal class Renderer(
}

private fun getNativeLibDir(): String {
val osName = System.getProperty("os.name").toLowerCase(Locale.US)
val osName = System.getProperty("os.name").lowercase(Locale.US)
val osLabel = when {
osName.startsWith("windows") -> "win"
osName.startsWith("mac") -> {
val osArch = System.getProperty("os.arch").lowercase(Locale.US)
if (osArch.startsWith("x86")) "mac" else "mac-arm"
// System.getProperty("os.arch") returns the os of the jre, not necessarily of the platform we are running on,
// try /usr/bin/arch to get the actual architecture
val osArch = ProcessBuilder("/usr/bin/arch")
.start()
.inputStream
.bufferedReader()
.lines()
.findFirst()
.getOrNull()
?.lowercase(Locale.US)

if (osArch != null) {
if (osArch.startsWith("i386")) "mac" else "mac-arm"
} else {
// fallback to jre arch and cross fingers it's correct
val jreArch = System.getProperty("os.arch").lowercase(Locale.US)
if (jreArch.startsWith("x86")) "mac" else "mac-arm"
}
}
else -> "linux"
}
Expand Down

0 comments on commit 4144d06

Please sign in to comment.