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 {...@@ -222,6 +222,7 @@ pub const NativeTargetInfo = struct {
222 ProcessFdQuotaExceeded,222 ProcessFdQuotaExceeded,
223 SystemFdQuotaExceeded,223 SystemFdQuotaExceeded,
224 DeviceBusy,224 DeviceBusy,
225 OSVersionDetectionFail,
225 };226 };
226227
227 /// Given a `CrossTarget`, which specifies in detail which parts of the target should be detected228 /// Given a `CrossTarget`, which specifies in detail which parts of the target should be detected
...@@ -254,7 +255,7 @@ pub const NativeTargetInfo = struct {...@@ -254,7 +255,7 @@ pub const NativeTargetInfo = struct {
254 os.version_range.windows.min = detected_version;255 os.version_range.windows.min = detected_version;
255 os.version_range.windows.max = detected_version;256 os.version_range.windows.max = detected_version;
256 },257 },
257 .macos => macos.detect(&os) catch {}, // valid to ignore any error and keep os defaults258 .macos => try macos.detect(&os),
258 .freebsd => {259 .freebsd => {
259 var osreldate: u32 = undefined;260 var osreldate: u32 = undefined;
260 var len: usize = undefined;261 var len: usize = undefined;
lib/std/zig/system/macos.zig+4-9
...@@ -9,7 +9,7 @@ const mem = std.mem;...@@ -9,7 +9,7 @@ const mem = std.mem;
9const testing = std.testing;9const testing = std.testing;
1010
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.
13pub fn detect(os: *std.Target.Os) !void {13pub 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 later15 // 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 '200322 // 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 herring25 // 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 the26 // 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 to28 // 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 result29 // 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 {
6158
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 herring61 // 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 }