| ... | ... | @@ -13,6 +13,7 @@ const assert = std.debug.assert; |
| 13 | 13 | const mem = std.mem; |
| 14 | 14 | const process = std.process; |
| 15 | 15 | const allocPrint = std.fmt.allocPrint; |
| 16 | const Allocator = std.mem.Allocator; |
| 16 | 17 | |
| 17 | 18 | const Step = @import("../Step.zig"); |
| 18 | 19 | const Maker = @import("../../Maker.zig"); |
| ... | ... | @@ -28,13 +29,6 @@ cached_test_metadata: ?CachedTestMetadata = null, |
| 28 | 29 | /// executable that contains fuzz tests. |
| 29 | 30 | rebuilt_executable: ?Path = null, |
| 30 | 31 | |
| 31 | | /// Persisted to reuse memory on subsequent calls to `make`. |
| 32 | | argv: std.ArrayList([]const u8) = .empty, |
| 33 | | /// Persisted to reuse memory on subsequent calls to `make`. |
| 34 | | output_placeholders: std.ArrayList(IndexedOutput) = .empty, |
| 35 | | /// Persisted to reuse memory on subsequent calls to `make`. |
| 36 | | environ_map: std.process.Environ.Map = .{ .array_hash_map = .empty, .allocator = undefined }, |
| 37 | | |
| 38 | 32 | pub fn make( |
| 39 | 33 | run: *Run, |
| 40 | 34 | run_index: Configuration.Step.Index, |
| ... | ... | @@ -45,16 +39,17 @@ pub fn make( |
| 45 | 39 | const gpa = maker.gpa; |
| 46 | 40 | const step = maker.stepByIndex(run_index); |
| 47 | 41 | const io = graph.io; |
| 48 | | const arena = graph.arena; // TODO don't leak into the process arena |
| 49 | 42 | const conf = &maker.scanned_config.configuration; |
| 50 | 43 | const conf_step = run_index.ptr(conf); |
| 51 | 44 | const conf_run = conf_step.extended.get(conf.extra).run; |
| 52 | | const argv_list = &run.argv; |
| 53 | | const output_placeholders = &run.output_placeholders; |
| 54 | 45 | const cache_root = graph.local_cache_root; |
| 55 | 46 | |
| 56 | | argv_list.clearRetainingCapacity(); |
| 57 | | output_placeholders.clearRetainingCapacity(); |
| 47 | var arena_allocator: std.heap.ArenaAllocator = .init(gpa); |
| 48 | defer arena_allocator.deinit(); |
| 49 | const arena = arena_allocator.allocator(); |
| 50 | |
| 51 | var argv_list: std.ArrayList([]const u8) = .empty; |
| 52 | var output_placeholders: std.ArrayList(IndexedOutput) = .empty; |
| 58 | 53 | |
| 59 | 54 | var man = graph.cache.obtain(); |
| 60 | 55 | defer man.deinit(); |
| ... | ... | @@ -89,7 +84,7 @@ pub fn make( |
| 89 | 84 | const suffix = if (arg.suffix.value) |p| p.slice(conf) else ""; |
| 90 | 85 | const file_path = try maker.resolveLazyPathIndex(arena, arg.path.value.?, run_index); |
| 91 | 86 | argv_list.appendAssumeCapacity(try mem.concat(arena, u8, &.{ |
| 92 | | prefix, try convertPathArg(run_index, maker, file_path), suffix, |
| 87 | prefix, try convertPathArg(arena, run_index, maker, file_path), suffix, |
| 93 | 88 | })); |
| 94 | 89 | man.hash.addBytesZ(prefix); |
| 95 | 90 | man.hash.addBytesZ(suffix); |
| ... | ... | @@ -100,7 +95,7 @@ pub fn make( |
| 100 | 95 | const suffix = if (arg.suffix.value) |p| p.slice(conf) else ""; |
| 101 | 96 | const file_path = try maker.resolveLazyPathIndex(arena, arg.path.value.?, run_index); |
| 102 | 97 | const resolved_arg = try mem.concat(arena, u8, &.{ |
| 103 | | prefix, try convertPathArg(run_index, maker, file_path), suffix, |
| 98 | prefix, try convertPathArg(arena, run_index, maker, file_path), suffix, |
| 104 | 99 | }); |
| 105 | 100 | argv_list.appendAssumeCapacity(resolved_arg); |
| 106 | 101 | man.hash.addBytes(resolved_arg); |
| ... | ... | @@ -144,7 +139,7 @@ pub fn make( |
| 144 | 139 | const file_path = producer_make_comp.installed_path orelse maker.generatedPath(producer.generated_bin.value.?).*; |
| 145 | 140 | |
| 146 | 141 | argv_list.appendAssumeCapacity(try mem.concat(arena, u8, &.{ |
| 147 | | prefix, try convertPathArg(run_index, maker, file_path), suffix, |
| 142 | prefix, try convertPathArg(arena, run_index, maker, file_path), suffix, |
| 148 | 143 | })); |
| 149 | 144 | |
| 150 | 145 | _ = try man.addFilePath(file_path, null); |
| ... | ... | @@ -183,7 +178,7 @@ pub fn make( |
| 183 | 178 | |
| 184 | 179 | man.hash.add(conf_run.flags.test_runner_mode); |
| 185 | 180 | if (conf_run.flags.test_runner_mode) { |
| 186 | | const cache_dir_string = try convertPathArg(run_index, maker, .{ .root_dir = cache_root }); |
| 181 | const cache_dir_string = try convertPathArg(arena, run_index, maker, .{ .root_dir = cache_root }); |
| 187 | 182 | |
| 188 | 183 | try argv_list.ensureUnusedCapacity(gpa, 3); |
| 189 | 184 | argv_list.appendAssumeCapacity(try allocPrint(arena, "--cache-dir={s}", .{cache_dir_string})); |
| ... | ... | @@ -259,8 +254,8 @@ pub fn make( |
| 259 | 254 | const digest = if (has_side_effects) man.hash.final() else man.final(); |
| 260 | 255 | const output_dir_path = "o" ++ Dir.path.sep_str ++ &digest; |
| 261 | 256 | try populateGeneratedStdIo(maker, &conf_run, cache_root, &digest); |
| 262 | | try populateGeneratedPathsCreateDirs(run, run_index, maker, output_dir_path); |
| 263 | | try runCommand(run, run_index, maker, progress_node, argv_list.items, has_side_effects, output_dir_path, null); |
| 257 | try populateGeneratedPathsCreateDirs(arena, run_index, maker, output_dir_path, output_placeholders.items, argv_list.items); |
| 258 | try runCommand(arena, run, run_index, maker, progress_node, argv_list.items, has_side_effects, output_dir_path, null); |
| 264 | 259 | if (!has_side_effects) try step.writeManifestAndWatch(maker, &man); |
| 265 | 260 | return; |
| 266 | 261 | } |
| ... | ... | @@ -270,8 +265,8 @@ pub fn make( |
| 270 | 265 | io.random(@ptrCast(&rand_int)); |
| 271 | 266 | const tmp_dir_path = "tmp" ++ Dir.path.sep_str ++ std.fmt.hex(rand_int); |
| 272 | 267 | |
| 273 | | try populateGeneratedPathsCreateDirs(run, run_index, maker, tmp_dir_path); |
| 274 | | try runCommand(run, run_index, maker, progress_node, argv_list.items, has_side_effects, tmp_dir_path, null); |
| 268 | try populateGeneratedPathsCreateDirs(arena, run_index, maker, tmp_dir_path, output_placeholders.items, argv_list.items); |
| 269 | try runCommand(arena, run, run_index, maker, progress_node, argv_list.items, has_side_effects, tmp_dir_path, null); |
| 275 | 270 | |
| 276 | 271 | for (output_placeholders.items) |placeholder| { |
| 277 | 272 | const arg = placeholder.arg_index.get(conf); |
| ... | ... | @@ -341,6 +336,7 @@ pub fn make( |
| 341 | 336 | /// * A test (or a response from the test runner) times out |
| 342 | 337 | /// * The wait fails, indicating the child closed stdout and stderr |
| 343 | 338 | fn waitZigTest( |
| 339 | arena: Allocator, |
| 344 | 340 | run: *Run, |
| 345 | 341 | run_index: Configuration.Step.Index, |
| 346 | 342 | maker: *Maker, |
| ... | ... | @@ -363,7 +359,6 @@ fn waitZigTest( |
| 363 | 359 | const graph = maker.graph; |
| 364 | 360 | const gpa = maker.gpa; |
| 365 | 361 | const io = graph.io; |
| 366 | | const arena = graph.arena; // TODO don't leak into the process arena |
| 367 | 362 | const step = maker.stepByIndex(run_index); |
| 368 | 363 | |
| 369 | 364 | var sub_prog_node: ?std.Progress.Node = null; |
| ... | ... | @@ -715,7 +710,7 @@ const FuzzTestRunner = struct { |
| 715 | 710 | } |
| 716 | 711 | } |
| 717 | 712 | |
| 718 | | fn listen(f: *FuzzTestRunner) !void { |
| 713 | fn listen(f: *FuzzTestRunner, arena: Allocator) !void { |
| 719 | 714 | const maker = f.ctx.fuzz.maker; |
| 720 | 715 | const graph = maker.graph; |
| 721 | 716 | const io = graph.io; |
| ... | ... | @@ -739,7 +734,7 @@ const FuzzTestRunner = struct { |
| 739 | 734 | else => |read_e| return read_e, |
| 740 | 735 | }), |
| 741 | 736 | 2 => try f.completeStderrRead(id, result.file_read_streaming catch |e| switch (e) { |
| 742 | | error.EndOfStream => return f.instanceEos(id), |
| 737 | error.EndOfStream => return f.instanceEos(arena, id), |
| 743 | 738 | else => |read_e| return read_e, |
| 744 | 739 | }), |
| 745 | 740 | else => unreachable, |
| ... | ... | @@ -901,7 +896,7 @@ const FuzzTestRunner = struct { |
| 901 | 896 | } }); |
| 902 | 897 | } |
| 903 | 898 | |
| 904 | | fn instanceEos(f: *FuzzTestRunner, id: u32) !void { |
| 899 | fn instanceEos(f: *FuzzTestRunner, arena: Allocator, id: u32) !void { |
| 905 | 900 | const maker = f.ctx.fuzz.maker; |
| 906 | 901 | const instance = &f.instances[id]; |
| 907 | 902 | const run_index = f.run_index; |
| ... | ... | @@ -914,7 +909,7 @@ const FuzzTestRunner = struct { |
| 914 | 909 | instance.child.stdin = null; |
| 915 | 910 | const term = try instance.child.wait(io); |
| 916 | 911 | if (!termMatches(.{ .exited = 0 }, term)) { |
| 917 | | step.result_stderr = try f.mergedStderr(); |
| 912 | step.result_stderr = try f.mergedStderr(arena); |
| 918 | 913 | try f.saveCrash(id, term); |
| 919 | 914 | return step.fail(maker, "test process unexpectedly {f}", .{fmtTerm(term)}); |
| 920 | 915 | } |
| ... | ... | @@ -1057,11 +1052,7 @@ const FuzzTestRunner = struct { |
| 1057 | 1052 | } |
| 1058 | 1053 | } |
| 1059 | 1054 | |
| 1060 | | fn mergedStderr(f: *FuzzTestRunner) std.mem.Allocator.Error![]const u8 { |
| 1061 | | const maker = f.ctx.fuzz.maker; |
| 1062 | | const graph = maker.graph; |
| 1063 | | const arena = graph.arena; // TODO don't leak into the process arena |
| 1064 | | |
| 1055 | fn mergedStderr(f: *FuzzTestRunner, arena: Allocator) Allocator.Error![]const u8 { |
| 1065 | 1056 | // Collect any available stderr |
| 1066 | 1057 | while (f.batch.next()) |completion| { |
| 1067 | 1058 | if (completion.index % 3 != 2) continue; |
| ... | ... | @@ -1092,12 +1083,13 @@ fn evalFuzzTest( |
| 1092 | 1083 | var f: FuzzTestRunner = try .init(run, run_index, fuzz_context, progress_node, spawn_options); |
| 1093 | 1084 | defer f.deinit(); |
| 1094 | 1085 | try f.startInstances(); |
| 1095 | | try f.listen(); |
| 1086 | try f.listen(fuzz_context.fuzz.maker.graph.arena); |
| 1096 | 1087 | } |
| 1097 | 1088 | |
| 1098 | 1089 | const StdioPollEnum = enum { stdout, stderr }; |
| 1099 | 1090 | |
| 1100 | 1091 | fn evalZigTest( |
| 1092 | arena: Allocator, |
| 1101 | 1093 | run: *Run, |
| 1102 | 1094 | run_index: Configuration.Step.Index, |
| 1103 | 1095 | maker: *Maker, |
| ... | ... | @@ -1113,7 +1105,6 @@ fn evalZigTest( |
| 1113 | 1105 | const graph = maker.graph; |
| 1114 | 1106 | const gpa = maker.gpa; |
| 1115 | 1107 | const io = graph.io; |
| 1116 | | const arena = graph.arena; // TODO don't leak into the process arena |
| 1117 | 1108 | const step = maker.stepByIndex(run_index); |
| 1118 | 1109 | |
| 1119 | 1110 | // We will update this every time a child runs. |
| ... | ... | @@ -1146,6 +1137,7 @@ fn evalZigTest( |
| 1146 | 1137 | }; |
| 1147 | 1138 | |
| 1148 | 1139 | switch (try waitZigTest( |
| 1140 | arena, |
| 1149 | 1141 | run, |
| 1150 | 1142 | run_index, |
| 1151 | 1143 | maker, |
| ... | ... | @@ -1380,13 +1372,13 @@ fn sendRunFuzzTestMessage( |
| 1380 | 1372 | } |
| 1381 | 1373 | |
| 1382 | 1374 | fn evalGeneric( |
| 1375 | arena: Allocator, |
| 1383 | 1376 | run_index: Configuration.Step.Index, |
| 1384 | 1377 | maker: *Maker, |
| 1385 | 1378 | spawn_options: process.SpawnOptions, |
| 1386 | 1379 | ) !EvalGenericResult { |
| 1387 | 1380 | const graph = maker.graph; |
| 1388 | 1381 | const io = graph.io; |
| 1389 | | const arena = graph.arena; // TODO don't leak into the process arena |
| 1390 | 1382 | const gpa = maker.gpa; |
| 1391 | 1383 | const conf = &maker.scanned_config.configuration; |
| 1392 | 1384 | const conf_step = run_index.ptr(conf); |
| ... | ... | @@ -1520,15 +1512,17 @@ pub fn rerunInFuzzMode( |
| 1520 | 1512 | const graph = maker.graph; |
| 1521 | 1513 | const step = maker.stepByIndex(run_index); |
| 1522 | 1514 | const io = graph.io; |
| 1523 | | const arena = graph.arena; // TODO don't leak into the process arena |
| 1524 | 1515 | const gpa = maker.gpa; |
| 1525 | 1516 | const conf = &maker.scanned_config.configuration; |
| 1526 | 1517 | const conf_step = run_index.ptr(conf); |
| 1527 | 1518 | const conf_run = conf_step.extended.get(conf.extra).run; |
| 1528 | | const argv_list = &run.argv; |
| 1529 | 1519 | const cache_root = graph.local_cache_root; |
| 1530 | 1520 | |
| 1531 | | argv_list.clearRetainingCapacity(); |
| 1521 | var arena_allocator: std.heap.ArenaAllocator = .init(gpa); |
| 1522 | defer arena_allocator.deinit(); |
| 1523 | const arena = arena_allocator.allocator(); |
| 1524 | |
| 1525 | var argv_list: std.ArrayList([]const u8) = .empty; |
| 1532 | 1526 | |
| 1533 | 1527 | for (conf_run.args.slice) |arg_index| { |
| 1534 | 1528 | const arg = arg_index.get(conf); |
| ... | ... | @@ -1543,7 +1537,7 @@ pub fn rerunInFuzzMode( |
| 1543 | 1537 | const suffix = if (arg.suffix.value) |p| p.slice(conf) else ""; |
| 1544 | 1538 | const file_path = try maker.resolveLazyPathIndex(arena, arg.path.value.?, run_index); |
| 1545 | 1539 | argv_list.appendAssumeCapacity(try mem.concat(arena, u8, &.{ |
| 1546 | | prefix, try convertPathArg(run_index, maker, file_path), suffix, |
| 1540 | prefix, try convertPathArg(arena, run_index, maker, file_path), suffix, |
| 1547 | 1541 | })); |
| 1548 | 1542 | }, |
| 1549 | 1543 | .path_directory => { |
| ... | ... | @@ -1551,7 +1545,7 @@ pub fn rerunInFuzzMode( |
| 1551 | 1545 | const suffix = if (arg.suffix.value) |p| p.slice(conf) else ""; |
| 1552 | 1546 | const file_path = try maker.resolveLazyPathIndex(arena, arg.path.value.?, run_index); |
| 1553 | 1547 | const resolved_arg = try mem.concat(arena, u8, &.{ |
| 1554 | | prefix, try convertPathArg(run_index, maker, file_path), suffix, |
| 1548 | prefix, try convertPathArg(arena, run_index, maker, file_path), suffix, |
| 1555 | 1549 | }); |
| 1556 | 1550 | argv_list.appendAssumeCapacity(resolved_arg); |
| 1557 | 1551 | }, |
| ... | ... | @@ -1593,7 +1587,7 @@ pub fn rerunInFuzzMode( |
| 1593 | 1587 | producer_make_comp.installed_path orelse |
| 1594 | 1588 | maker.generatedPath(producer.generated_bin.value.?).*; |
| 1595 | 1589 | argv_list.appendAssumeCapacity(try mem.concat(arena, u8, &.{ |
| 1596 | | prefix, try convertPathArg(run_index, maker, file_path), suffix, |
| 1590 | prefix, try convertPathArg(arena, run_index, maker, file_path), suffix, |
| 1597 | 1591 | })); |
| 1598 | 1592 | }, |
| 1599 | 1593 | .output_file => unreachable, |
| ... | ... | @@ -1603,7 +1597,7 @@ pub fn rerunInFuzzMode( |
| 1603 | 1597 | } |
| 1604 | 1598 | |
| 1605 | 1599 | if (conf_run.flags.test_runner_mode) { |
| 1606 | | const cache_dir_string = try convertPathArg(run_index, maker, .{ .root_dir = cache_root }); |
| 1600 | const cache_dir_string = try convertPathArg(arena, run_index, maker, .{ .root_dir = cache_root }); |
| 1607 | 1601 | |
| 1608 | 1602 | try argv_list.ensureUnusedCapacity(gpa, 3); |
| 1609 | 1603 | argv_list.appendAssumeCapacity(try allocPrint(arena, "--cache-dir={s}", .{cache_dir_string})); |
| ... | ... | @@ -1620,7 +1614,7 @@ pub fn rerunInFuzzMode( |
| 1620 | 1614 | var rand_int: u64 = undefined; |
| 1621 | 1615 | io.random(@ptrCast(&rand_int)); |
| 1622 | 1616 | const tmp_dir_path = "tmp" ++ Dir.path.sep_str ++ std.fmt.hex(rand_int); |
| 1623 | | try runCommand(run, run_index, maker, prog_node, argv_list.items, has_side_effects, tmp_dir_path, .{ |
| 1617 | try runCommand(arena, run, run_index, maker, prog_node, argv_list.items, has_side_effects, tmp_dir_path, .{ |
| 1624 | 1618 | .fuzz = fuzz, |
| 1625 | 1619 | }); |
| 1626 | 1620 | } |
| ... | ... | @@ -1633,13 +1627,12 @@ fn populateGeneratedPaths( |
| 1633 | 1627 | ) !void { |
| 1634 | 1628 | const conf = &maker.scanned_config.configuration; |
| 1635 | 1629 | const graph = maker.graph; |
| 1636 | | const arena = graph.arena; // TODO don't leak into the process arena |
| 1637 | 1630 | |
| 1638 | 1631 | for (output_placeholders) |placeholder| { |
| 1639 | 1632 | const arg = placeholder.arg_index.get(conf); |
| 1640 | 1633 | maker.generatedPath(arg.generated.value.?).* = .{ |
| 1641 | 1634 | .root_dir = cache_root, |
| 1642 | | .sub_path = try Dir.path.join(arena, &.{ |
| 1635 | .sub_path = try Dir.path.join(graph.arena, &.{ |
| 1643 | 1636 | "o", digest, arg.basename.value.?.slice(conf), |
| 1644 | 1637 | }), |
| 1645 | 1638 | }; |
| ... | ... | @@ -1647,20 +1640,20 @@ fn populateGeneratedPaths( |
| 1647 | 1640 | } |
| 1648 | 1641 | |
| 1649 | 1642 | fn populateGeneratedPathsCreateDirs( |
| 1650 | | run: *Run, |
| 1643 | arena: Allocator, |
| 1651 | 1644 | run_index: Configuration.Step.Index, |
| 1652 | 1645 | maker: *Maker, |
| 1653 | 1646 | output_dir_path: []const u8, |
| 1647 | output_placeholders: []const IndexedOutput, |
| 1648 | argv: [][]const u8, |
| 1654 | 1649 | ) !void { |
| 1655 | 1650 | const step = maker.stepByIndex(run_index); |
| 1656 | 1651 | const conf = &maker.scanned_config.configuration; |
| 1657 | 1652 | const graph = maker.graph; |
| 1658 | 1653 | const io = graph.io; |
| 1659 | | const arena = graph.arena; // TODO don't leak into the process arena |
| 1660 | 1654 | const cache_root = graph.local_cache_root; |
| 1661 | | const argv = run.argv.items; |
| 1662 | 1655 | |
| 1663 | | for (run.output_placeholders.items) |placeholder| { |
| 1656 | for (output_placeholders) |placeholder| { |
| 1664 | 1657 | const arg = placeholder.arg_index.get(conf); |
| 1665 | 1658 | const prefix = if (arg.prefix.value) |p| p.slice(conf) else ""; |
| 1666 | 1659 | const suffix = if (arg.suffix.value) |p| p.slice(conf) else ""; |
| ... | ... | @@ -1668,7 +1661,7 @@ fn populateGeneratedPathsCreateDirs( |
| 1668 | 1661 | |
| 1669 | 1662 | const generated_path: Path = .{ |
| 1670 | 1663 | .root_dir = cache_root, |
| 1671 | | .sub_path = try Dir.path.join(arena, &.{ output_dir_path, basename }), |
| 1664 | .sub_path = try Dir.path.join(graph.arena, &.{ output_dir_path, basename }), |
| 1672 | 1665 | }; |
| 1673 | 1666 | const create_path: Path = .{ |
| 1674 | 1667 | .root_dir = cache_root, |
| ... | ... | @@ -1683,7 +1676,7 @@ fn populateGeneratedPathsCreateDirs( |
| 1683 | 1676 | |
| 1684 | 1677 | maker.generatedPath(arg.generated.value.?).* = generated_path; |
| 1685 | 1678 | |
| 1686 | | const arg_output_path = try convertPathArg(run_index, maker, generated_path); |
| 1679 | const arg_output_path = try convertPathArg(arena, run_index, maker, generated_path); |
| 1687 | 1680 | argv[placeholder.index] = try mem.concat(arena, u8, &.{ prefix, arg_output_path, suffix }); |
| 1688 | 1681 | } |
| 1689 | 1682 | } |
| ... | ... | @@ -1696,12 +1689,11 @@ fn populateGeneratedStdIo( |
| 1696 | 1689 | ) !void { |
| 1697 | 1690 | const conf = &maker.scanned_config.configuration; |
| 1698 | 1691 | const graph = maker.graph; |
| 1699 | | const arena = graph.arena; // TODO don't leak into the process arena |
| 1700 | 1692 | |
| 1701 | 1693 | if (conf_run.captured_stdout.value) |captured| { |
| 1702 | 1694 | maker.generatedPath(captured.generated_file).* = .{ |
| 1703 | 1695 | .root_dir = cache_root, |
| 1704 | | .sub_path = try Dir.path.join(arena, &.{ |
| 1696 | .sub_path = try Dir.path.join(graph.arena, &.{ |
| 1705 | 1697 | "o", digest, captured.basename.slice(conf), |
| 1706 | 1698 | }), |
| 1707 | 1699 | }; |
| ... | ... | @@ -1710,7 +1702,7 @@ fn populateGeneratedStdIo( |
| 1710 | 1702 | if (conf_run.captured_stderr.value) |captured| { |
| 1711 | 1703 | maker.generatedPath(captured.generated_file).* = .{ |
| 1712 | 1704 | .root_dir = cache_root, |
| 1713 | | .sub_path = try Dir.path.join(arena, &.{ |
| 1705 | .sub_path = try Dir.path.join(graph.arena, &.{ |
| 1714 | 1706 | "o", digest, captured.basename.slice(conf), |
| 1715 | 1707 | }), |
| 1716 | 1708 | }; |
| ... | ... | @@ -1736,6 +1728,7 @@ const FuzzContext = struct { |
| 1736 | 1728 | }; |
| 1737 | 1729 | |
| 1738 | 1730 | fn runCommand( |
| 1731 | arena: Allocator, |
| 1739 | 1732 | run: *Run, |
| 1740 | 1733 | run_index: Configuration.Step.Index, |
| 1741 | 1734 | maker: *Maker, |
| ... | ... | @@ -1746,7 +1739,6 @@ fn runCommand( |
| 1746 | 1739 | fuzz_context: ?FuzzContext, |
| 1747 | 1740 | ) Step.ExtendedMakeError!void { |
| 1748 | 1741 | const graph = maker.graph; |
| 1749 | | const arena = graph.arena; // TODO don't leak into process arena |
| 1750 | 1742 | const gpa = maker.gpa; |
| 1751 | 1743 | const step = maker.stepByIndex(run_index); |
| 1752 | 1744 | const io = graph.io; |
| ... | ... | @@ -1754,7 +1746,6 @@ fn runCommand( |
| 1754 | 1746 | const conf = &maker.scanned_config.configuration; |
| 1755 | 1747 | const conf_step = run_index.ptr(conf); |
| 1756 | 1748 | const conf_run = conf_step.extended.get(conf.extra).run; |
| 1757 | | const environ_map = &run.environ_map; |
| 1758 | 1749 | |
| 1759 | 1750 | const cwd: process.Child.Cwd = if (conf_run.cwd.value) |lazy_cwd| |
| 1760 | 1751 | .{ .path = try maker.resolveLazyPathIndexAbs(arena, lazy_cwd, run_index) } |
| ... | ... | @@ -1768,12 +1759,11 @@ fn runCommand( |
| 1768 | 1759 | |
| 1769 | 1760 | var interp_argv: std.ArrayList([]const u8) = .empty; |
| 1770 | 1761 | |
| 1771 | | // `environ_map` is initialized with an undefined `allocator` field; lazily |
| 1772 | | // initialize it here. |
| 1773 | | environ_map.allocator = gpa; |
| 1762 | var environ_map: std.process.Environ.Map = .init(gpa); |
| 1763 | defer environ_map.deinit(); |
| 1764 | |
| 1774 | 1765 | // In either case we add to this mutatable data structure so that we can |
| 1775 | 1766 | // tweak the environment below. |
| 1776 | | environ_map.clearRetainingCapacity(); |
| 1777 | 1767 | if (conf_run.environ_map.value) |env_map_index| { |
| 1778 | 1768 | const conf_env_map = env_map_index.get(conf); |
| 1779 | 1769 | for (conf_env_map.keys.slice(conf), conf_env_map.values.slice(conf)) |k, v| { |
| ... | ... | @@ -1792,7 +1782,7 @@ fn runCommand( |
| 1792 | 1782 | const root_module = producer.root_module.get(conf); |
| 1793 | 1783 | const root_module_target = root_module.resolved_target.get(conf).?.result.get(conf); |
| 1794 | 1784 | if (root_module_target.flags.os_tag == .windows) { |
| 1795 | | try addPathForDynLibs(maker, producer_index, environ_map, argv[0]); |
| 1785 | try addPathForDynLibs(maker, arena, producer_index, &environ_map, argv[0]); |
| 1796 | 1786 | } |
| 1797 | 1787 | } |
| 1798 | 1788 | |
| ... | ... | @@ -1801,15 +1791,16 @@ fn runCommand( |
| 1801 | 1791 | .dir => unreachable, |
| 1802 | 1792 | .inherit => null, |
| 1803 | 1793 | }; |
| 1804 | | try graph.handleVerbose(cwd_string, environ_map, argv); |
| 1794 | try graph.handleVerbose(cwd_string, &environ_map, argv); |
| 1805 | 1795 | |
| 1806 | 1796 | const opt_generic_result = spawnChildAndCollect( |
| 1797 | arena, |
| 1807 | 1798 | run_index, |
| 1808 | 1799 | run, |
| 1809 | 1800 | maker, |
| 1810 | 1801 | progress_node, |
| 1811 | 1802 | argv, |
| 1812 | | environ_map, |
| 1803 | &environ_map, |
| 1813 | 1804 | has_side_effects, |
| 1814 | 1805 | fuzz_context, |
| 1815 | 1806 | ) catch |err| term: { |
| ... | ... | @@ -1863,7 +1854,7 @@ fn runCommand( |
| 1863 | 1854 | try environ_map.put("WINEDEBUG", "-all"); |
| 1864 | 1855 | } |
| 1865 | 1856 | } else { |
| 1866 | | return failForeign(&conf_run, maker, run_index, "-fwine", argv[0], &root_target, &host); |
| 1857 | return failForeign(arena, &conf_run, maker, run_index, "-fwine", argv[0], &root_target, &host); |
| 1867 | 1858 | } |
| 1868 | 1859 | }, |
| 1869 | 1860 | .qemu => |bin_name| { |
| ... | ... | @@ -1887,11 +1878,11 @@ fn runCommand( |
| 1887 | 1878 | root_target.abi, |
| 1888 | 1879 | ) else unreachable, |
| 1889 | 1880 | })); |
| 1890 | | } else return failForeign(&conf_run, maker, run_index, "--libc-runtimes", argv[0], &root_target, &host); |
| 1881 | } else return failForeign(arena, &conf_run, maker, run_index, "--libc-runtimes", argv[0], &root_target, &host); |
| 1891 | 1882 | } |
| 1892 | 1883 | |
| 1893 | 1884 | interp_argv.appendSliceAssumeCapacity(argv); |
| 1894 | | } else return failForeign(&conf_run, maker, run_index, "-fqemu", argv[0], &root_target, &host); |
| 1885 | } else return failForeign(arena, &conf_run, maker, run_index, "-fqemu", argv[0], &root_target, &host); |
| 1895 | 1886 | }, |
| 1896 | 1887 | .darling => |bin_name| { |
| 1897 | 1888 | if (graph.enable_darling) { |
| ... | ... | @@ -1899,7 +1890,7 @@ fn runCommand( |
| 1899 | 1890 | interp_argv.appendAssumeCapacity(bin_name); |
| 1900 | 1891 | interp_argv.appendSliceAssumeCapacity(argv); |
| 1901 | 1892 | } else { |
| 1902 | | return failForeign(&conf_run, maker, run_index, "-fdarling", argv[0], &root_target, &host); |
| 1893 | return failForeign(arena, &conf_run, maker, run_index, "-fdarling", argv[0], &root_target, &host); |
| 1903 | 1894 | } |
| 1904 | 1895 | }, |
| 1905 | 1896 | .wasmtime => |bin_name| { |
| ... | ... | @@ -1912,7 +1903,7 @@ fn runCommand( |
| 1912 | 1903 | interp_argv.appendAssumeCapacity("-Sinherit-env"); |
| 1913 | 1904 | interp_argv.appendSliceAssumeCapacity(argv); |
| 1914 | 1905 | } else { |
| 1915 | | return failForeign(&conf_run, maker, run_index, "-fwasmtime", argv[0], &root_target, &host); |
| 1906 | return failForeign(arena, &conf_run, maker, run_index, "-fwasmtime", argv[0], &root_target, &host); |
| 1916 | 1907 | } |
| 1917 | 1908 | }, |
| 1918 | 1909 | .bad_dl => |foreign_dl| { |
| ... | ... | @@ -1941,15 +1932,16 @@ fn runCommand( |
| 1941 | 1932 | |
| 1942 | 1933 | gpa.free(step.result_failed_command.?); |
| 1943 | 1934 | step.result_failed_command = null; |
| 1944 | | try graph.handleVerbose(cwd_string, environ_map, interp_argv.items); |
| 1935 | try graph.handleVerbose(cwd_string, &environ_map, interp_argv.items); |
| 1945 | 1936 | |
| 1946 | 1937 | break :term spawnChildAndCollect( |
| 1938 | arena, |
| 1947 | 1939 | run_index, |
| 1948 | 1940 | run, |
| 1949 | 1941 | maker, |
| 1950 | 1942 | progress_node, |
| 1951 | 1943 | interp_argv.items, |
| 1952 | | environ_map, |
| 1944 | &environ_map, |
| 1953 | 1945 | has_side_effects, |
| 1954 | 1946 | fuzz_context, |
| 1955 | 1947 | ) catch |e| { |
| ... | ... | @@ -1996,7 +1988,7 @@ fn runCommand( |
| 1996 | 1988 | if (stream.captured) |captured| { |
| 1997 | 1989 | const output_path: Path = .{ |
| 1998 | 1990 | .root_dir = cache_root, |
| 1999 | | .sub_path = try Dir.path.join(arena, &.{ |
| 1991 | .sub_path = try Dir.path.join(graph.arena, &.{ |
| 2000 | 1992 | output_dir_path, captured.basename.slice(conf), |
| 2001 | 1993 | }), |
| 2002 | 1994 | }; |
| ... | ... | @@ -2117,6 +2109,7 @@ const EvalGenericResult = struct { |
| 2117 | 2109 | }; |
| 2118 | 2110 | |
| 2119 | 2111 | fn spawnChildAndCollect( |
| 2112 | arena: Allocator, |
| 2120 | 2113 | run_index: Configuration.Step.Index, |
| 2121 | 2114 | run: *Run, |
| 2122 | 2115 | maker: *Maker, |
| ... | ... | @@ -2129,7 +2122,6 @@ fn spawnChildAndCollect( |
| 2129 | 2122 | const step = maker.stepByIndex(run_index); |
| 2130 | 2123 | const graph = maker.graph; |
| 2131 | 2124 | const io = graph.io; |
| 2132 | | const arena = graph.arena; // TODO don't leak into process arena |
| 2133 | 2125 | const gpa = maker.gpa; |
| 2134 | 2126 | const conf = &maker.scanned_config.configuration; |
| 2135 | 2127 | const conf_step = run_index.ptr(conf); |
| ... | ... | @@ -2189,7 +2181,7 @@ fn spawnChildAndCollect( |
| 2189 | 2181 | |
| 2190 | 2182 | if (conf_run.flags.stdio == .zig_test) { |
| 2191 | 2183 | const started: Io.Clock.Timestamp = .now(io, .awake); |
| 2192 | | const result = evalZigTest(run, run_index, maker, progress_node, spawn_options, fuzz_context) catch |err| switch (err) { |
| 2184 | const result = evalZigTest(graph.arena, run, run_index, maker, progress_node, spawn_options, fuzz_context) catch |err| switch (err) { |
| 2193 | 2185 | error.Canceled => |e| return e, |
| 2194 | 2186 | else => |e| e, |
| 2195 | 2187 | }; |
| ... | ... | @@ -2209,7 +2201,7 @@ fn spawnChildAndCollect( |
| 2209 | 2201 | try setColorEnvironmentVariables(&conf_run, environ_map, terminal_mode); |
| 2210 | 2202 | |
| 2211 | 2203 | const started: Io.Clock.Timestamp = .now(io, .awake); |
| 2212 | | const result = evalGeneric(run_index, maker, spawn_options) catch |err| switch (err) { |
| 2204 | const result = evalGeneric(arena, run_index, maker, spawn_options) catch |err| switch (err) { |
| 2213 | 2205 | error.Canceled => |e| return e, |
| 2214 | 2206 | else => |e| e, |
| 2215 | 2207 | }; |
| ... | ... | @@ -2287,12 +2279,11 @@ fn checksContainStderr(conf_run: *const Configuration.Step.Run) bool { |
| 2287 | 2279 | /// |
| 2288 | 2280 | /// Whenever a path is included in the argv of a child, it should be put through this function first |
| 2289 | 2281 | /// to make sure the child doesn't see paths relative to a cwd other than its own. |
| 2290 | | fn convertPathArg(run_index: Configuration.Step.Index, maker: *Maker, path: Path) ![]const u8 { |
| 2282 | fn convertPathArg(arena: Allocator, run_index: Configuration.Step.Index, maker: *Maker, path: Path) ![]const u8 { |
| 2291 | 2283 | const conf = &maker.scanned_config.configuration; |
| 2292 | 2284 | const conf_step = run_index.ptr(conf); |
| 2293 | 2285 | const conf_run = conf_step.extended.get(conf.extra).run; |
| 2294 | 2286 | const graph = maker.graph; |
| 2295 | | const arena = graph.arena; // TODO don't leak into process arena |
| 2296 | 2287 | |
| 2297 | 2288 | const path_str = try path.toString(arena); |
| 2298 | 2289 | if (Dir.path.isAbsolute(path_str)) { |
| ... | ... | @@ -2319,13 +2310,13 @@ fn convertPathArg(run_index: Configuration.Step.Index, maker: *Maker, path: Path |
| 2319 | 2310 | |
| 2320 | 2311 | fn addPathForDynLibs( |
| 2321 | 2312 | maker: *Maker, |
| 2313 | arena: Allocator, |
| 2322 | 2314 | artifact: Configuration.Step.Index, |
| 2323 | 2315 | environ_map: *process.Environ.Map, |
| 2324 | 2316 | argv0: []const u8, |
| 2325 | 2317 | ) !void { |
| 2326 | 2318 | const conf = &maker.scanned_config.configuration; |
| 2327 | 2319 | const graph = maker.graph; |
| 2328 | | const arena = graph.arena; // TODO don't leak into process arena |
| 2329 | 2320 | const use_wine = graph.enable_wine and builtin.os.tag != .windows and std.ascii.endsWithIgnoreCase(argv0, ".exe"); |
| 2330 | 2321 | const path_key = if (use_wine) "WINEPATH" else "PATH"; |
| 2331 | 2322 | const path_delimiter: u8 = if (builtin.os.tag == .windows or use_wine) |
| ... | ... | @@ -2355,6 +2346,7 @@ fn addPathForDynLibs( |
| 2355 | 2346 | } |
| 2356 | 2347 | |
| 2357 | 2348 | fn failForeign( |
| 2349 | arena: Allocator, |
| 2358 | 2350 | conf_run: *const Configuration.Step.Run, |
| 2359 | 2351 | maker: *Maker, |
| 2360 | 2352 | step_index: Configuration.Step.Index, |
| ... | ... | @@ -2368,10 +2360,8 @@ fn failForeign( |
| 2368 | 2360 | .check, .zig_test => { |
| 2369 | 2361 | if (conf_run.flags.skip_foreign_checks) return error.MakeSkipped; |
| 2370 | 2362 | |
| 2371 | | const graph = maker.graph; |
| 2372 | | const process_arena = graph.arena; // TODO don't leak into process arena |
| 2373 | | const host_name = try host_target.zigTriple(process_arena); |
| 2374 | | const foreign_name = try artifact_target.zigTriple(process_arena); |
| 2363 | const host_name = try host_target.zigTriple(arena); |
| 2364 | const foreign_name = try artifact_target.zigTriple(arena); |
| 2375 | 2365 | |
| 2376 | 2366 | return step.fail(maker, |
| 2377 | 2367 | \\unable to spawn foreign binary '{s}' ({s}) on host system ({s}) |