authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-02-28 17:15:06-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-03-15 10:48:13-07:00
log79440d2b470b3906bd87334ecd90b2a0f2cea05b
tree254edd976c4e879872b27c333d80ae0875ed6cbe
parent7a3dabdc4738c2816bede92571ccdf481d400997

std.Build.CompileStep: obtain the build output dir from protocol

Now building successfully works again.

3 files changed, 12 insertions(+), 7 deletions(-)

lib/build_runner.zig+6
...@@ -364,12 +364,17 @@ fn runStepNames(...@@ -364,12 +364,17 @@ fn runStepNames(
364 }364 }
365 }365 }
366366
367 // A proper command line application defaults to silently succeeding.
368 // The user may request verbose mode if they have a different preference.
369 if (failure_count == 0 and !b.verbose) return cleanExit();
370
367 const stderr = std.io.getStdErr();371 const stderr = std.io.getStdErr();
368372
369 const total_count = success_count + failure_count + pending_count;373 const total_count = success_count + failure_count + pending_count;
370 stderr.writer().print("build summary: {d}/{d} steps succeeded; {d} failed\n", .{374 stderr.writer().print("build summary: {d}/{d} steps succeeded; {d} failed\n", .{
371 success_count, total_count, failure_count,375 success_count, total_count, failure_count,
372 }) catch {};376 }) catch {};
377
373 if (failure_count == 0) return cleanExit();378 if (failure_count == 0) return cleanExit();
374379
375 for (step_stack.items) |s| switch (s.state) {380 for (step_stack.items) |s| switch (s.state) {
...@@ -493,6 +498,7 @@ fn workerMakeOneStep(...@@ -493,6 +498,7 @@ fn workerMakeOneStep(
493 stderr.writeAll("error: ") catch break;498 stderr.writeAll("error: ") catch break;
494 ttyconf.setColor(stderr, .Reset) catch break;499 ttyconf.setColor(stderr, .Reset) catch break;
495 stderr.writeAll(msg) catch break;500 stderr.writeAll(msg) catch break;
501 stderr.writeAll("\n") catch break;
496 }502 }
497 }503 }
498504
lib/std/Build.zig+4-5
...@@ -1154,13 +1154,12 @@ fn allocPrintCmd(ally: Allocator, opt_cwd: ?[]const u8, argv: []const []const u8...@@ -1154,13 +1154,12 @@ fn allocPrintCmd(ally: Allocator, opt_cwd: ?[]const u8, argv: []const []const u8
1154 for (argv) |arg| {1154 for (argv) |arg| {
1155 try buf.writer().print("{s} ", .{arg});1155 try buf.writer().print("{s} ", .{arg});
1156 }1156 }
1157 try buf.append('\n');
1158 return buf.toOwnedSlice();1157 return buf.toOwnedSlice();
1159}1158}
11601159
1161fn printCmd(ally: Allocator, cwd: ?[]const u8, argv: []const []const u8) void {1160fn printCmd(ally: Allocator, cwd: ?[]const u8, argv: []const []const u8) void {
1162 const text = allocPrintCmd(ally, cwd, argv) catch @panic("OOM");1161 const text = allocPrintCmd(ally, cwd, argv) catch @panic("OOM");
1163 std.debug.print("{s}", .{text});1162 std.debug.print("{s}\n", .{text});
1164}1163}
11651164
1166pub fn spawnChildEnvMap(self: *Build, cwd: ?[]const u8, env_map: *const EnvMap, argv: []const []const u8) !void {1165pub fn spawnChildEnvMap(self: *Build, cwd: ?[]const u8, env_map: *const EnvMap, argv: []const []const u8) !void {
...@@ -1482,7 +1481,7 @@ pub fn execFromStep(b: *Build, argv: []const []const u8, s: *Step) ![]const u8 {...@@ -1482,7 +1481,7 @@ pub fn execFromStep(b: *Build, argv: []const []const u8, s: *Step) ![]const u8 {
1482 @panic("TODO handle progress message");1481 @panic("TODO handle progress message");
1483 },1482 },
1484 .emit_bin_path => {1483 .emit_bin_path => {
1485 @panic("TODO handle emit_bin_path message");1484 result = try b.allocator.dupe(u8, body);
1486 },1485 },
1487 _ => {1486 _ => {
1488 // Unrecognized message.1487 // Unrecognized message.
...@@ -1553,7 +1552,7 @@ fn sendMessage(file: fs.File, tag: std.zig.Client.Message.Tag) !void {...@@ -1553,7 +1552,7 @@ fn sendMessage(file: fs.File, tag: std.zig.Client.Message.Tag) !void {
1553/// a helpful message.1552/// a helpful message.
1554pub fn exec(b: *Build, argv: []const []const u8) []u8 {1553pub fn exec(b: *Build, argv: []const []const u8) []u8 {
1555 if (!process.can_spawn) {1554 if (!process.can_spawn) {
1556 std.debug.print("unable to spawn the following command: cannot spawn child process\n{s}", .{1555 std.debug.print("unable to spawn the following command: cannot spawn child process\n{s}\n", .{
1557 try allocPrintCmd(b.allocator, null, argv),1556 try allocPrintCmd(b.allocator, null, argv),
1558 });1557 });
1559 process.exit(1);1558 process.exit(1);
...@@ -1562,7 +1561,7 @@ pub fn exec(b: *Build, argv: []const []const u8) []u8 {...@@ -1562,7 +1561,7 @@ pub fn exec(b: *Build, argv: []const []const u8) []u8 {
1562 var code: u8 = undefined;1561 var code: u8 = undefined;
1563 return b.execAllowFail(argv, &code, .Inherit) catch |err| {1562 return b.execAllowFail(argv, &code, .Inherit) catch |err| {
1564 const printed_cmd = allocPrintCmd(b.allocator, null, argv) catch @panic("OOM");1563 const printed_cmd = allocPrintCmd(b.allocator, null, argv) catch @panic("OOM");
1565 std.debug.print("unable to spawn the following command: {s}\n{s}", .{1564 std.debug.print("unable to spawn the following command: {s}\n{s}\n", .{
1566 @errorName(err), printed_cmd,1565 @errorName(err), printed_cmd,
1567 });1566 });
1568 process.exit(1);1567 process.exit(1);
lib/std/Build/CompileStep.zig+2-2
...@@ -1888,8 +1888,8 @@ fn make(step: *Step) !void {...@@ -1888,8 +1888,8 @@ fn make(step: *Step) !void {
1888 try zig_args.append(resolved_args_file);1888 try zig_args.append(resolved_args_file);
1889 }1889 }
18901890
1891 const output_dir_nl = try builder.execFromStep(zig_args.items, &self.step);1891 const output_bin_path = try builder.execFromStep(zig_args.items, &self.step);
1892 const build_output_dir = mem.trimRight(u8, output_dir_nl, "\r\n");1892 const build_output_dir = fs.path.dirname(output_bin_path).?;
18931893
1894 if (self.output_dir) |output_dir| {1894 if (self.output_dir) |output_dir| {
1895 var src_dir = try std.fs.cwd().openIterableDir(build_output_dir, .{});1895 var src_dir = try std.fs.cwd().openIterableDir(build_output_dir, .{});