pub fn isSdkInstalled(gpa: Allocator, io: Io) bool 19
20
21
22
23
24
25
26
27
28
29
30
31pub fn isSdkInstalled(gpa: Allocator, io: Io) bool {
const result = std.process.run(gpa, io, .{
.argv = &.{ "xcode-select", "--print-path" },
}) catch return false;
defer {
gpa.free(result.stderr);
gpa.free(result.stdout);
}
return switch (result.term) {
.exited => |code| if (code == 0) result.stdout.len > 0 else false,
else => false,
};
}
Check if SDK is installed on Darwin without triggering CLT installation popup window.
Simply invoking
xcrunwill inevitably trigger the CLT installation popup. Therefore, we resort to invokingxcode-select --print-pathand checking if the status is nonzero.stderr from xcode-select is ignored.
If error.OutOfMemory occurs in Allocator, this function returns null.