| author | |
| committer | |
| log | fda2458f6ac9c4f5ddc7d0fb70ab6194ce1adc47 |
| tree | 8bf0091d50ad426e800e3a1ce69136fd9a6ec4f0 |
| parent | 2c373b0fb6e9f37919115d53c110070be9ccb401 |
| parent | cb1d1bdf59f2979de9c534c21813d824f9736cfb |
| signature |
enhance `std.Build.Step.Fmt` and use it more9 files changed, 43 insertions(+), 50 deletions(-)
build.zig+5-5| ... | ... | @@ -428,18 +428,21 @@ pub fn build(b: *std.Build) !void { |
| 428 | 428 | } |
| 429 | 429 | const optimization_modes = chosen_opt_modes_buf[0..chosen_mode_index]; |
| 430 | 430 | |
| 431 | const fmt_include_paths = &.{ "doc", "lib", "src", "test", "tools", "build.zig" }; | |
| 431 | const fmt_include_paths = &.{ "lib", "src", "test", "tools", "build.zig", "build.zig.zon" }; | |
| 432 | 432 | const fmt_exclude_paths = &.{"test/cases"}; |
| 433 | 433 | const do_fmt = b.addFmt(.{ |
| 434 | 434 | .paths = fmt_include_paths, |
| 435 | 435 | .exclude_paths = fmt_exclude_paths, |
| 436 | 436 | }); |
| 437 | b.step("fmt", "Modify source files in place to have conforming formatting").dependOn(&do_fmt.step); | |
| 437 | 438 | |
| 438 | b.step("test-fmt", "Check source files having conforming formatting").dependOn(&b.addFmt(.{ | |
| 439 | const check_fmt = b.step("test-fmt", "Check source files having conforming formatting"); | |
| 440 | check_fmt.dependOn(&b.addFmt(.{ | |
| 439 | 441 | .paths = fmt_include_paths, |
| 440 | 442 | .exclude_paths = fmt_exclude_paths, |
| 441 | 443 | .check = true, |
| 442 | 444 | }).step); |
| 445 | test_step.dependOn(check_fmt); | |
| 443 | 446 | |
| 444 | 447 | const test_cases_step = b.step("test-cases", "Run the main compiler test cases"); |
| 445 | 448 | try tests.addCases(b, test_cases_step, test_filters, check_case_exe, target, .{ |
| ... | ... | @@ -534,9 +537,6 @@ pub fn build(b: *std.Build) !void { |
| 534 | 537 | |
| 535 | 538 | try addWasiUpdateStep(b, version); |
| 536 | 539 | |
| 537 | b.step("fmt", "Modify source files in place to have conforming formatting") | |
| 538 | .dependOn(&do_fmt.step); | |
| 539 | ||
| 540 | 540 | const update_mingw_step = b.step("update-mingw", "Update zig's bundled mingw"); |
| 541 | 541 | const opt_mingw_src_path = b.option([]const u8, "mingw-src", "path to mingw-w64 source directory"); |
| 542 | 542 | const update_mingw_exe = b.addExecutable(.{ |
ci/aarch64-linux-debug.sh-7| ... | ... | @@ -49,13 +49,6 @@ unset CXX |
| 49 | 49 | |
| 50 | 50 | ninja install |
| 51 | 51 | |
| 52 | # TODO: move this to a build.zig step (check-fmt) | |
| 53 | echo "Looking for non-conforming code formatting..." | |
| 54 | stage3-debug/bin/zig fmt --check .. \ | |
| 55 | --exclude ../test/cases/ \ | |
| 56 | --exclude ../doc/ \ | |
| 57 | --exclude ../build-debug | |
| 58 | ||
| 59 | 52 | # simultaneously test building self-hosted without LLVM and with 32-bit arm |
| 60 | 53 | stage3-debug/bin/zig build \ |
| 61 | 54 | -Dtarget=arm-linux-musleabihf \ |
ci/aarch64-linux-release.sh-7| ... | ... | @@ -49,13 +49,6 @@ unset CXX |
| 49 | 49 | |
| 50 | 50 | ninja install |
| 51 | 51 | |
| 52 | # TODO: move this to a build.zig step (check-fmt) | |
| 53 | echo "Looking for non-conforming code formatting..." | |
| 54 | stage3-release/bin/zig fmt --check .. \ | |
| 55 | --exclude ../test/cases/ \ | |
| 56 | --exclude ../doc/ \ | |
| 57 | --exclude ../build-release | |
| 58 | ||
| 59 | 52 | # simultaneously test building self-hosted without LLVM and with 32-bit arm |
| 60 | 53 | stage3-release/bin/zig build \ |
| 61 | 54 | -Dtarget=arm-linux-musleabihf \ |
ci/x86_64-linux-debug.sh-7| ... | ... | @@ -57,13 +57,6 @@ unset CXX |
| 57 | 57 | |
| 58 | 58 | ninja install |
| 59 | 59 | |
| 60 | # TODO: move this to a build.zig step (check-fmt) | |
| 61 | echo "Looking for non-conforming code formatting..." | |
| 62 | stage3-debug/bin/zig fmt --check .. \ | |
| 63 | --exclude ../test/cases/ \ | |
| 64 | --exclude ../doc/ \ | |
| 65 | --exclude ../build-debug | |
| 66 | ||
| 67 | 60 | # simultaneously test building self-hosted without LLVM and with 32-bit arm |
| 68 | 61 | stage3-debug/bin/zig build \ |
| 69 | 62 | -Dtarget=arm-linux-musleabihf \ |
ci/x86_64-linux-release.sh-8| ... | ... | @@ -57,14 +57,6 @@ unset CXX |
| 57 | 57 | |
| 58 | 58 | ninja install |
| 59 | 59 | |
| 60 | # TODO: move this to a build.zig step (check-fmt) | |
| 61 | echo "Looking for non-conforming code formatting..." | |
| 62 | stage3-release/bin/zig fmt --check .. \ | |
| 63 | --exclude ../test/cases/ \ | |
| 64 | --exclude ../doc/ \ | |
| 65 | --exclude ../build-debug \ | |
| 66 | --exclude ../build-release | |
| 67 | ||
| 68 | 60 | # simultaneously test building self-hosted without LLVM and with 32-bit arm |
| 69 | 61 | stage3-release/bin/zig build \ |
| 70 | 62 | -Dtarget=arm-linux-musleabihf \ |
lib/std/Build/Step.zig+13-2| ... | ... | @@ -272,7 +272,17 @@ const Allocator = std.mem.Allocator; |
| 272 | 272 | const assert = std.debug.assert; |
| 273 | 273 | const builtin = @import("builtin"); |
| 274 | 274 | |
| 275 | pub fn evalChildProcess(s: *Step, argv: []const []const u8) !void { | |
| 275 | pub fn evalChildProcess(s: *Step, argv: []const []const u8) ![]u8 { | |
| 276 | const run_result = try captureChildProcess(s, std.Progress.Node.none, argv); | |
| 277 | try handleChildProcessTerm(s, run_result.term, null, argv); | |
| 278 | return run_result.stdout; | |
| 279 | } | |
| 280 | ||
| 281 | pub fn captureChildProcess( | |
| 282 | s: *Step, | |
| 283 | progress_node: std.Progress.Node, | |
| 284 | argv: []const []const u8, | |
| 285 | ) !std.process.Child.RunResult { | |
| 276 | 286 | const arena = s.owner.allocator; |
| 277 | 287 | |
| 278 | 288 | try handleChildProcUnsupported(s, null, argv); |
| ... | ... | @@ -281,13 +291,14 @@ pub fn evalChildProcess(s: *Step, argv: []const []const u8) !void { |
| 281 | 291 | const result = std.process.Child.run(.{ |
| 282 | 292 | .allocator = arena, |
| 283 | 293 | .argv = argv, |
| 294 | .progress_node = progress_node, | |
| 284 | 295 | }) catch |err| return s.fail("unable to spawn {s}: {s}", .{ argv[0], @errorName(err) }); |
| 285 | 296 | |
| 286 | 297 | if (result.stderr.len > 0) { |
| 287 | 298 | try s.result_error_msgs.append(arena, result.stderr); |
| 288 | 299 | } |
| 289 | 300 | |
| 290 | try handleChildProcessTerm(s, result.term, null, argv); | |
| 301 | return result; | |
| 291 | 302 | } |
| 292 | 303 | |
| 293 | 304 | pub fn fail(step: *Step, comptime fmt: []const u8, args: anytype) error{ OutOfMemory, MakeFailed } { |
lib/std/Build/Step/Fmt.zig+11-4| ... | ... | @@ -37,9 +37,6 @@ pub fn create(owner: *std.Build, options: Options) *Fmt { |
| 37 | 37 | } |
| 38 | 38 | |
| 39 | 39 | fn make(step: *Step, prog_node: std.Progress.Node) !void { |
| 40 | // zig fmt is fast enough that no progress is needed. | |
| 41 | _ = prog_node; | |
| 42 | ||
| 43 | 40 | // TODO: if check=false, this means we are modifying source files in place, which |
| 44 | 41 | // is an operation that could race against other operations also modifying source files |
| 45 | 42 | // in place. In this case, this step should obtain a write lock while making those |
| ... | ... | @@ -68,5 +65,15 @@ fn make(step: *Step, prog_node: std.Progress.Node) !void { |
| 68 | 65 | argv.appendAssumeCapacity(b.pathFromRoot(p)); |
| 69 | 66 | } |
| 70 | 67 | |
| 71 | return step.evalChildProcess(argv.items); | |
| 68 | const run_result = try step.captureChildProcess(prog_node, argv.items); | |
| 69 | if (fmt.check) switch (run_result.term) { | |
| 70 | .Exited => |code| if (code != 0 and run_result.stdout.len != 0) { | |
| 71 | var it = std.mem.tokenizeScalar(u8, run_result.stdout, '\n'); | |
| 72 | while (it.next()) |bad_file_name| { | |
| 73 | try step.addError("{s}: non-conforming formatting", .{bad_file_name}); | |
| 74 | } | |
| 75 | }, | |
| 76 | else => {}, | |
| 77 | }; | |
| 78 | try step.handleChildProcessTerm(run_result.term, null, argv.items); | |
| 72 | 79 | } |
lib/std/Progress.zig+11-9| ... | ... | @@ -80,6 +80,8 @@ pub const Options = struct { |
| 80 | 80 | pub const Node = struct { |
| 81 | 81 | index: OptionalIndex, |
| 82 | 82 | |
| 83 | pub const none: Node = .{ .index = .none }; | |
| 84 | ||
| 83 | 85 | pub const max_name_len = 40; |
| 84 | 86 | |
| 85 | 87 | const Storage = extern struct { |
| ... | ... | @@ -177,9 +179,9 @@ pub const Node = struct { |
| 177 | 179 | pub fn start(node: Node, name: []const u8, estimated_total_items: usize) Node { |
| 178 | 180 | if (noop_impl) { |
| 179 | 181 | assert(node.index == .none); |
| 180 | return .{ .index = .none }; | |
| 182 | return Node.none; | |
| 181 | 183 | } |
| 182 | const node_index = node.index.unwrap() orelse return .{ .index = .none }; | |
| 184 | const node_index = node.index.unwrap() orelse return Node.none; | |
| 183 | 185 | const parent = node_index.toParent(); |
| 184 | 186 | |
| 185 | 187 | const freelist_head = &global_progress.node_freelist_first; |
| ... | ... | @@ -196,7 +198,7 @@ pub const Node = struct { |
| 196 | 198 | if (free_index >= global_progress.node_storage.len) { |
| 197 | 199 | // Ran out of node storage memory. Progress for this node will not be tracked. |
| 198 | 200 | _ = @atomicRmw(u32, &global_progress.node_end_index, .Sub, 1, .monotonic); |
| 199 | return .{ .index = .none }; | |
| 201 | return Node.none; | |
| 200 | 202 | } |
| 201 | 203 | |
| 202 | 204 | return init(@enumFromInt(free_index), parent, name, estimated_total_items); |
| ... | ... | @@ -357,7 +359,7 @@ pub fn start(options: Options) Node { |
| 357 | 359 | global_progress.initial_delay_ns = options.initial_delay_ns; |
| 358 | 360 | |
| 359 | 361 | if (noop_impl) |
| 360 | return .{ .index = .none }; | |
| 362 | return Node.none; | |
| 361 | 363 | |
| 362 | 364 | if (std.process.parseEnvVarInt("ZIG_PROGRESS", u31, 10)) |ipc_fd| { |
| 363 | 365 | global_progress.update_thread = std.Thread.spawn(.{}, ipcThreadRun, .{ |
| ... | ... | @@ -368,12 +370,12 @@ pub fn start(options: Options) Node { |
| 368 | 370 | }), |
| 369 | 371 | }) catch |err| { |
| 370 | 372 | std.log.warn("failed to spawn IPC thread for communicating progress to parent: {s}", .{@errorName(err)}); |
| 371 | return .{ .index = .none }; | |
| 373 | return Node.none; | |
| 372 | 374 | }; |
| 373 | 375 | } else |env_err| switch (env_err) { |
| 374 | 376 | error.EnvironmentVariableNotFound => { |
| 375 | 377 | if (options.disable_printing) { |
| 376 | return .{ .index = .none }; | |
| 378 | return Node.none; | |
| 377 | 379 | } |
| 378 | 380 | const stderr = std.io.getStdErr(); |
| 379 | 381 | global_progress.terminal = stderr; |
| ... | ... | @@ -386,7 +388,7 @@ pub fn start(options: Options) Node { |
| 386 | 388 | } |
| 387 | 389 | |
| 388 | 390 | if (global_progress.terminal_mode == .off) { |
| 389 | return .{ .index = .none }; | |
| 391 | return Node.none; | |
| 390 | 392 | } |
| 391 | 393 | |
| 392 | 394 | if (have_sigwinch) { |
| ... | ... | @@ -408,12 +410,12 @@ pub fn start(options: Options) Node { |
| 408 | 410 | global_progress.update_thread = thread; |
| 409 | 411 | } else |err| { |
| 410 | 412 | std.log.warn("unable to spawn thread for printing progress to terminal: {s}", .{@errorName(err)}); |
| 411 | return .{ .index = .none }; | |
| 413 | return Node.none; | |
| 412 | 414 | } |
| 413 | 415 | }, |
| 414 | 416 | else => |e| { |
| 415 | 417 | std.log.warn("invalid ZIG_PROGRESS file descriptor integer: {s}", .{@errorName(e)}); |
| 416 | return .{ .index = .none }; | |
| 418 | return Node.none; | |
| 417 | 419 | }, |
| 418 | 420 | } |
| 419 | 421 |
lib/std/process/Child.zig+3-1| ... | ... | @@ -101,7 +101,7 @@ resource_usage_statistics: ResourceUsageStatistics = .{}, |
| 101 | 101 | /// |
| 102 | 102 | /// The child's progress tree will be grafted into the parent's progress tree, |
| 103 | 103 | /// by substituting this node with the child's root node. |
| 104 | progress_node: std.Progress.Node = .{ .index = .none }, | |
| 104 | progress_node: std.Progress.Node = std.Progress.Node.none, | |
| 105 | 105 | |
| 106 | 106 | pub const ResourceUsageStatistics = struct { |
| 107 | 107 | rusage: @TypeOf(rusage_init) = rusage_init, |
| ... | ... | @@ -376,6 +376,7 @@ pub fn run(args: struct { |
| 376 | 376 | env_map: ?*const EnvMap = null, |
| 377 | 377 | max_output_bytes: usize = 50 * 1024, |
| 378 | 378 | expand_arg0: Arg0Expand = .no_expand, |
| 379 | progress_node: std.Progress.Node = std.Progress.Node.none, | |
| 379 | 380 | }) RunError!RunResult { |
| 380 | 381 | var child = ChildProcess.init(args.argv, args.allocator); |
| 381 | 382 | child.stdin_behavior = .Ignore; |
| ... | ... | @@ -385,6 +386,7 @@ pub fn run(args: struct { |
| 385 | 386 | child.cwd_dir = args.cwd_dir; |
| 386 | 387 | child.env_map = args.env_map; |
| 387 | 388 | child.expand_arg0 = args.expand_arg0; |
| 389 | child.progress_node = args.progress_node; | |
| 388 | 390 | |
| 389 | 391 | var stdout = std.ArrayList(u8).init(args.allocator); |
| 390 | 392 | var stderr = std.ArrayList(u8).init(args.allocator); |