Check for the existence of zig in PATH in main()
This commit is contained in:
parent
f008a776e2
commit
4542abf145
31
src/main.zig
31
src/main.zig
@ -888,6 +888,37 @@ pub fn main() anyerror!void {
|
||||
}
|
||||
}
|
||||
|
||||
// Find the zig executable in PATH
|
||||
var has_zig = false;
|
||||
|
||||
find_zig: {
|
||||
const env_path = std.process.getEnvVarOwned(allocator, "PATH") catch |err| switch (err) {
|
||||
error.EnvironmentVariableNotFound => {
|
||||
std.debug.warn("Could not get PATH.\n", .{});
|
||||
break :find_zig;
|
||||
},
|
||||
else => return err,
|
||||
};
|
||||
defer allocator.free(env_path);
|
||||
|
||||
var it = std.mem.tokenize(env_path,&[_]u8{std.fs.path.delimiter});
|
||||
const exe_extension = @as(std.zig.CrossTarget, .{}).exeFileExt();
|
||||
const zig_exe = try std.fmt.allocPrint(allocator, "zig{}", .{exe_extension});
|
||||
defer allocator.free(zig_exe);
|
||||
|
||||
while (it.next()) |path| {
|
||||
const full_path = try std.fs.path.join(allocator, &[_][]const u8{
|
||||
path,
|
||||
zig_exe,
|
||||
});
|
||||
var buf: [std.fs.MAX_PATH_BYTES]u8 = undefined;
|
||||
const zig_path = std.os.realpath(full_path, &buf) catch continue;
|
||||
std.debug.warn("Found zig in PATH: {}\n", .{zig_path});
|
||||
has_zig = true;
|
||||
break :find_zig;
|
||||
}
|
||||
}
|
||||
|
||||
try document_store.init(allocator);
|
||||
defer document_store.deinit();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user