authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-04-04 14:05:49-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-04-04 14:05:49-04:00
logdc7e8b2fdcc35bc78abfe2413201ca6a74aa20d4
treefe0f72cfbe5c2421ac245277f405c6b5ac56ef9f
parent12cdea452524e4b852cb433728c834a7b0203b67
signaturelock-open Commit is signed but in an unrecognized format.

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.

1 files changed, 4 insertions(+), 2 deletions(-)

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