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