ctr: Add helpers to database to check Linux and ARM arch

On ARM platforms, we have to prepare the variant for spec.platform.
Currently, this action would only work on Linux/ARM system. We
introduce these two helpers to check running system's OS and Arch.

Change-Id: Iff14087699219413779dd6caf1bf9524db1cc19e
Signed-off-by: Wei Chen <Wei.Chen@arm.com>
This commit is contained in:
Wei Chen 2017-09-30 14:21:23 +08:00
parent 1a560540b9
commit 4355ba2f83

View File

@ -5,6 +5,13 @@ import (
"strings" "strings"
) )
// isLinuxOS returns true if the operating system is Linux.
//
// The OS value should be normalized before calling this function.
func isLinuxOS(os string) bool {
return os == "linux"
}
// These function are generated from from https://golang.org/src/go/build/syslist.go. // These function are generated from from https://golang.org/src/go/build/syslist.go.
// //
// We use switch statements because they are slightly faster than map lookups // We use switch statements because they are slightly faster than map lookups
@ -21,6 +28,17 @@ func isKnownOS(os string) bool {
return false return false
} }
// isArmArch returns true if the architecture is ARM.
//
// The arch value should be normalized before being passed to this function.
func isArmArch(arch string) bool {
switch arch {
case "arm", "arm64":
return true
}
return false
}
// isKnownArch returns true if we know about the architecture. // isKnownArch returns true if we know about the architecture.
// //
// The arch value should be normalized before being passed to this function. // The arch value should be normalized before being passed to this function.