-
Notifications
You must be signed in to change notification settings - Fork 307
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #217 from amir1376/change/add-arch-name-to-releases
add arch name in output release binaries
- Loading branch information
Showing
2 changed files
with
56 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
compositeBuilds/shared/platform/src/main/kotlin/ir/amirab/util/platform/Arch.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package ir.amirab.util.platform | ||
|
||
sealed class Arch(val name: String) { | ||
data object X64 : Arch("x64") | ||
data object Arm64 : Arch("arm64") | ||
data object X32 : Arch("x32") | ||
|
||
override fun toString(): String { | ||
return name | ||
} | ||
|
||
companion object : ArchFinder by JvmArchFinder() { | ||
private val DefinedArchStrings = mapOf( | ||
X64 to listOf( | ||
"amd64", "x64" | ||
), | ||
Arm64 to listOf( | ||
"arm64", "aarch64" | ||
), | ||
X32 to listOf( | ||
"x86", | ||
), | ||
) | ||
|
||
fun fromString(archName: String): Arch? { | ||
val a = archName.lowercase() | ||
return DefinedArchStrings.entries.firstOrNull { | ||
a in it.value | ||
}?.key | ||
} | ||
} | ||
} | ||
|
||
interface ArchFinder { | ||
fun getCurrentArch(): Arch | ||
} | ||
|
||
private class JvmArchFinder : ArchFinder { | ||
private val _arch by lazy { | ||
getCurrentArchFromJVMProperty() | ||
} | ||
|
||
private fun getCurrentArchFromJVMProperty(): Arch { | ||
val osString = System.getProperty("os.arch").lowercase() | ||
return requireNotNull(Arch.fromString(osString)) { | ||
"this arch is not recognized: $osString" | ||
} | ||
} | ||
|
||
override fun getCurrentArch(): Arch { | ||
return _arch | ||
} | ||
} |