feature. See also
. The project being documented here (as the example) is the Zig library itself.
Build.tryFindProgram
fn tryFindProgram(b: *Build, full_path: []const u8) ?[]const u8
File
Code
fn tryFindProgram(b: *Build, full_path: []const u8) ?[]const u8 {
const graph = b.graph;
const io = graph.io;
const arena = graph.arena;
if (Io.Dir.cwd().access(io, full_path, .{ .execute = true })) |_| {
return full_path;
} else |err| switch (err) {
error.FileNotFound, error.AccessDenied, error.PermissionDenied => |e| {
if (graph.verbose) log.info("searched: {t} {s}", .{ e, full_path });
},
else => |e| return panic("failed accessing {s}: {t}", .{ full_path, e }),
}
if (builtin.os.tag == .windows) {
if (b.graph.environ_map.get("PATHEXT")) |PATHEXT| {
var it = mem.tokenizeScalar(u8, PATHEXT, fs.path.delimiter);
const extended_path_buf = arena.alloc(u8, full_path.len + 1 + std.process.WindowsExtension.max_len) catch @panic("OOM");
@memcpy(extended_path_buf[0..full_path.len], full_path);
while (it.next()) |ext| {
if (!supportedWindowsProgramExtension(ext)) continue;
@memcpy(extended_path_buf[full_path.len..][0..ext.len], ext);
const extended_path = extended_path_buf[0 .. full_path.len + ext.len];
if (Io.Dir.cwd().access(io, extended_path, .{ .execute = true })) |_| {
return extended_path;
} else |err| switch (err) {
error.FileNotFound, error.AccessDenied, error.PermissionDenied => |e| {
if (graph.verbose) log.info("searched: {t} {s}", .{ e, extended_path });
},
else => |e| return panic("failed accessing {s}: {t}", .{ extended_path, e }),
}
}
}
}
return null;
}