at master 2.3 kB view raw
1diff --git a/src/cmd/linuxkit/vendor/github.com/Code-Hex/vz/v3/osversion.go b/src/cmd/linuxkit/vendor/github.com/Code-Hex/vz/v3/osversion.go 2index d72a7856d..b186d3aff 100644 3--- a/src/cmd/linuxkit/vendor/github.com/Code-Hex/vz/v3/osversion.go 4+++ b/src/cmd/linuxkit/vendor/github.com/Code-Hex/vz/v3/osversion.go 5@@ -9,6 +9,7 @@ import "C" 6 import ( 7 "errors" 8 "fmt" 9+ "os/exec" 10 "strconv" 11 "strings" 12 "sync" 13@@ -48,6 +49,40 @@ func fetchMajorMinorVersion() (float64, error) { 14 if err != nil { 15 return 0, err 16 } 17+ 18+ // For backward compatibility reasons, if code compiled against an SDK 19+ // earlier than macOS 11 is run on macOS 11 or later, and then tries to read 20+ // value of kern.osproductversion, the OS will return the value "10.16" 21+ // instead of the real OS version string. By contrast, the command `sw_vers 22+ // -productVersion` will return the real OS version string unless the 23+ // environment variable SYSTEM_VERSION_COMPAT is set to 1 or 2, in which 24+ // case it will respectively return "10.16" and "15.7" (the latter is for 25+ // some iOS compatibility reason). 26+ // 27+ // The only (currently) sure way to get the real OS version string 28+ // regardless of SYSTEM_VERSION_COMPAT or the SDK compiled against is 29+ // apparently to parse 30+ // /System/Library/CoreServices/.SystemVersionPlatform.plist if it exists, 31+ // and /System/Library/CoreServices/SystemVersion.plist otherwise. Doing 32+ // so, however, requires parsing XML plist files. 33+ // 34+ // Given what this library does, it doesn't seem likely that there would be 35+ // a good reason to run its code with SYSTEM_VERSION_COMPAT set, so using 36+ // `sw_vers` should be adequate until a proper parsing of plist files is 37+ // added. 38+ // 39+ // See https://github.com/ziglang/zig/issues/7569, 40+ // https://github.com/ziglang/zig/pull/7714 and 41+ // https://eclecticlight.co/2020/08/13/macos-version-numbering-isnt-so-simple/ 42+ // for more information. 43+ if osver == "10.16" { 44+ out, err := exec.Command("sw_vers", "-productVersion").Output() 45+ if err != nil { 46+ return 0, err 47+ } 48+ osver = strings.TrimRight(string(out), "\r\n") 49+ } 50+ 51 prefix := "v" 52 majorMinor := strings.TrimPrefix(semver.MajorMinor(prefix+osver), prefix) 53 version, err := strconv.ParseFloat(majorMinor, 64)