build.zig: better detection of using outside zig executable

As pointed out by gereeter, dirname("/") successfully returns "/" again.
So checking for null is not sufficient.
This commit is contained in:
Andrew Kelley 2020-04-04 14:05:49 -04:00
parent 12cdea4525
commit dc7e8b2fdc
No known key found for this signature in database
GPG Key ID: 7C5F548F728501A9

View File

@ -352,11 +352,13 @@ fn findAndParseConfigH(b: *Builder) !Context {
const max_bytes = 1 * 1024 * 1024;
const config_h_text = dir.readFileAlloc(b.allocator, "config.h", max_bytes) catch |err| switch (err) {
error.FileNotFound => {
check_dir = fs.path.dirname(check_dir) orelse {
const new_check_dir = fs.path.dirname(check_dir);
if (new_check_dir == null or mem.eql(u8, new_check_dir.?, check_dir)) {
std.debug.warn("Unable to find config.h file relative to Zig executable.\n", .{});
std.debug.warn("`zig build` must be run using a Zig executable within the source tree.\n", .{});
std.process.exit(1);
};
}
check_dir = new_check_dir.?;
continue;
},
else => |e| return e,