authorgravatar for michael.dusan@gmail.comMichael Dusan <michael.dusan@gmail.com> 2021-01-11 20:54:31-05:00
committergravatar for michael.dusan@gmail.comMichael Dusan <michael.dusan@gmail.com> 2021-01-11 20:58:31-05:00
log4c3de99253487620d3897df29eac7f14553a2632
treebbe7d338f87f4017611266fa85f214fce7f6b489
parentf2be1fb23edc272c0a310a9ceb9cdff45e011d98
signaturelock-open Commit is signed but in an unrecognized format.

more fixups

- clarify comments - `NativeTargetInfo.detect()` propagate macOS errors - `macos.detect()` drop `std.log` usage

2 files changed, 6 insertions(+), 10 deletions(-)

lib/std/zig/system.zig+2-1
......@@ -222,6 +222,7 @@ pub const NativeTargetInfo = struct {
222222 ProcessFdQuotaExceeded,
223223 SystemFdQuotaExceeded,
224224 DeviceBusy,
225 OSVersionDetectionFail,
225226 };
226227
227228 /// Given a `CrossTarget`, which specifies in detail which parts of the target should be detected
......@@ -254,7 +255,7 @@ pub const NativeTargetInfo = struct {
254255 os.version_range.windows.min = detected_version;
255256 os.version_range.windows.max = detected_version;
256257 },
257 .macos => macos.detect(&os) catch {}, // valid to ignore any error and keep os defaults
258 .macos => try macos.detect(&os),
258259 .freebsd => {
259260 var osreldate: u32 = undefined;
260261 var len: usize = undefined;
lib/std/zig/system/macos.zig+4-9
......@@ -9,7 +9,7 @@ const mem = std.mem;
99const testing = std.testing;
1010
1111/// Detect macOS version.
12/// On error `os` will not be modified.
12/// `os` is not modified in case of error.
1313pub fn detect(os: *std.Target.Os) !void {
1414 // Drop use of osproductversion sysctl because:
1515 // 1. only available 10.13.4 High Sierra and later
......@@ -22,9 +22,8 @@ pub fn detect(os: *std.Target.Os) !void {
2222 // NOTE: Historically `SystemVersion.plist` first appeared circa '2003
2323 // with the release of Mac OS X 10.3.0 Panther.
2424 //
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.
2827 //
2928 // BACKGROUND: `10.(16+)` is not a proper version and does not have enough fidelity to
3029 // 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 {
4948 // such that I am comfortable with implementing a minimalistic parser.
5049 // Things like string and general escapes are not supported.
5150 const prefixSlash = "/System/Library/CoreServices/";
52 const format_failure = "macOS detect: failed to {s} '{s}': {}";
53
5451 const paths = [_][]const u8{
5552 prefixSlash ++ "SystemVersion.plist",
5653 prefixSlash ++ ".SystemVersionPlatform.plist",
......@@ -61,7 +58,7 @@ pub fn detect(os: *std.Target.Os) !void {
6158
6259 if (std.fs.cwd().readFile(path, &buf)) |bytes| {
6360 if (parseSystemVersion(bytes)) |ver| {
64 // never return red herring
61 // never return non-canonical `10.(16+)`
6562 if (!(ver.major == 10 and ver.minor >= 16)) {
6663 os.version_range.semver.min = ver;
6764 os.version_range.semver.max = ver;
......@@ -69,11 +66,9 @@ pub fn detect(os: *std.Target.Os) !void {
6966 }
7067 continue;
7168 } else |err| {
72 std.log.err(format_failure, .{ "parse", path, err });
7369 return error.OSVersionDetectionFail;
7470 }
7571 } else |err| {
76 std.log.err(format_failure, .{ "read", path, err });
7772 return error.OSVersionDetectionFail;
7873 }
7974 }