Skip to content

Commit

Permalink
Fix cwebp for macosx support
Browse files Browse the repository at this point in the history
  • Loading branch information
johnsonlee committed May 19, 2023
1 parent d2c83f0 commit d101396
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ object OS {

val name: String = System.getProperty("os.name", "").lowercase()

val arch: String = try {
"arch".execute().stdout.trim().lowercase()
val arch: String = System.getProperty("os.arch", "").lowercase()

val uname = try {
"uname -a".execute().stdout.trim().lowercase()
} catch (e: Throwable) {
System.getProperty("os.arch", "").lowercase()
arch
}

val version = object : Comparable<String> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class Cwebp internal constructor(val supportAlpha: Boolean) : CompressionTool(Co
true -> CwebpCompressOpaqueFlatImages::class
else -> CwebpCompressFlatImages::class
}

else -> when (supportAlpha) {
true -> CwebpCompressOpaqueImages::class
else -> CwebpCompressImages::class
Expand Down Expand Up @@ -50,27 +51,29 @@ class Cwebp internal constructor(val supportAlpha: Boolean) : CompressionTool(Co

}

private val X64 = setOf("x64", "x86_64", "amd64")

internal val CWEBP = "$PROGRAM${OS.executableSuffix}"

internal val PREBUILT_CWEBP_EXECUTABLE = "bin/" + when {
OS.isLinux() -> "linux/" + when (OS.arch) {
"x64", "x86_64", "amd64" -> "x64"
else -> TODO("Unsupported architecture ${OS.arch}")
OS.isLinux() -> {
"linux/" + if (OS.arch in X64) "x64" else TODO("Unsupported architecture ${OS.arch}")
}
OS.isMac() -> "macosx/" + when (OS.arch) {
"arm64" -> "arm64"
"x86_64" -> "x86_64/" + when {
OS.version >= "10.15" -> "10.15"
OS.version >= "10.14" -> "10.14"
OS.version >= "10.13" -> "10.13"
OS.version >= "10.12" -> "10.12"
else -> TODO("Unsupported system version ${OS.version}")
OS.isMac() -> {
"macosx/" + when {
"arm64" == OS.arch || "arm64" in OS.uname -> "arm64"
OS.arch in X64 -> "x64/" + when {
OS.version >= "10.15" -> "10.15"
OS.version >= "10.14" -> "10.14"
OS.version >= "10.13" -> "10.13"
OS.version >= "10.12" -> "10.12"
else -> TODO("Unsupported system version ${OS.version}")
}
else -> TODO("Unsupported architecture ${OS.arch}")
}
else -> TODO("Unsupported architecture ${OS.arch}")
}
OS.isWindows() -> "windows/" + when (OS.arch) {
"x64", "x86_64", "amd64" -> "x64"
else -> TODO("Unsupported architecture ${OS.arch}")
OS.isWindows() -> {
"windows/" + if (OS.arch in X64) "x64" else TODO("Unsupported architecture ${OS.arch}")
}
else -> TODO("Unsupported OS ${OS.name}")
} + "/$CWEBP"
Expand Down

0 comments on commit d101396

Please sign in to comment.