| ... | ... | @@ -9,7 +9,7 @@ const mem = std.mem; |
| 9 | 9 | const testing = std.testing; |
| 10 | 10 | |
| 11 | 11 | /// Detect macOS version. |
| 12 | | /// On error `os` will not be modified. |
| 12 | /// `os` is not modified in case of error. |
| 13 | 13 | pub fn detect(os: *std.Target.Os) !void { |
| 14 | 14 | // Drop use of osproductversion sysctl because: |
| 15 | 15 | // 1. only available 10.13.4 High Sierra and later |
| ... | ... | @@ -22,9 +22,8 @@ pub fn detect(os: *std.Target.Os) !void { |
| 22 | 22 | // NOTE: Historically `SystemVersion.plist` first appeared circa '2003 |
| 23 | 23 | // with the release of Mac OS X 10.3.0 Panther. |
| 24 | 24 | // |
| 25 | | // and if it contains a `10.16` value where the `16` is `>= 16` then it is a red herring |
| 26 | | // and is discarded, and move on to next step. Otherwise we accept this is the |
| 27 | | // canonical file for versioning. |
| 25 | // and if it contains a `10.16` value where the `16` is `>= 16` then it is non-canonical, |
| 26 | // discarded, and we move on to next step. Otherwise we accept the version. |
| 28 | 27 | // |
| 29 | 28 | // BACKGROUND: `10.(16+)` is not a proper version and does not have enough fidelity to |
| 30 | 29 | // indicate minor/point version of Big Sur and later. It is a context-sensitive result |
| ... | ... | @@ -49,8 +48,6 @@ pub fn detect(os: *std.Target.Os) !void { |
| 49 | 48 | // such that I am comfortable with implementing a minimalistic parser. |
| 50 | 49 | // Things like string and general escapes are not supported. |
| 51 | 50 | const prefixSlash = "/System/Library/CoreServices/"; |
| 52 | | const format_failure = "macOS detect: failed to {s} '{s}': {}"; |
| 53 | | |
| 54 | 51 | const paths = [_][]const u8{ |
| 55 | 52 | prefixSlash ++ "SystemVersion.plist", |
| 56 | 53 | prefixSlash ++ ".SystemVersionPlatform.plist", |
| ... | ... | @@ -61,7 +58,7 @@ pub fn detect(os: *std.Target.Os) !void { |
| 61 | 58 | |
| 62 | 59 | if (std.fs.cwd().readFile(path, &buf)) |bytes| { |
| 63 | 60 | if (parseSystemVersion(bytes)) |ver| { |
| 64 | | // never return red herring |
| 61 | // never return non-canonical `10.(16+)` |
| 65 | 62 | if (!(ver.major == 10 and ver.minor >= 16)) { |
| 66 | 63 | os.version_range.semver.min = ver; |
| 67 | 64 | os.version_range.semver.max = ver; |
| ... | ... | @@ -69,11 +66,9 @@ pub fn detect(os: *std.Target.Os) !void { |
| 69 | 66 | } |
| 70 | 67 | continue; |
| 71 | 68 | } else |err| { |
| 72 | | std.log.err(format_failure, .{ "parse", path, err }); |
| 73 | 69 | return error.OSVersionDetectionFail; |
| 74 | 70 | } |
| 75 | 71 | } else |err| { |
| 76 | | std.log.err(format_failure, .{ "read", path, err }); |
| 77 | 72 | return error.OSVersionDetectionFail; |
| 78 | 73 | } |
| 79 | 74 | } |