| ... | ... | @@ -28,10 +28,10 @@ const usage = |
| 28 | 28 | \\ |
| 29 | 29 | ; |
| 30 | 30 | |
| 31 | | fn errorf(comptime format: []const u8, args: anytype) noreturn { |
| 31 | fn fatal(comptime format: []const u8, args: anytype) noreturn { |
| 32 | 32 | const stderr = io.getStdErr().writer(); |
| 33 | 33 | |
| 34 | | stderr.print("error: " ++ format, args) catch {}; |
| 34 | stderr.print("error: " ++ format ++ "\n", args) catch {}; |
| 35 | 35 | process.exit(1); |
| 36 | 36 | } |
| 37 | 37 | |
| ... | ... | @@ -45,6 +45,7 @@ pub fn main() !void { |
| 45 | 45 | if (!args_it.skip()) @panic("expected self arg"); |
| 46 | 46 | |
| 47 | 47 | var zig_exe: []const u8 = "zig"; |
| 48 | var opt_zig_lib_dir: ?[]const u8 = null; |
| 48 | 49 | var do_code_tests = true; |
| 49 | 50 | var files = [_][]const u8{ "", "" }; |
| 50 | 51 | |
| ... | ... | @@ -59,24 +60,29 @@ pub fn main() !void { |
| 59 | 60 | if (args_it.next()) |param| { |
| 60 | 61 | zig_exe = param; |
| 61 | 62 | } else { |
| 62 | | errorf("expected parameter after --zig\n", .{}); |
| 63 | fatal("expected parameter after --zig", .{}); |
| 64 | } |
| 65 | } else if (mem.eql(u8, arg, "--zig-lib-dir")) { |
| 66 | if (args_it.next()) |param| { |
| 67 | opt_zig_lib_dir = param; |
| 68 | } else { |
| 69 | fatal("expected parameter after --zig-lib-dir", .{}); |
| 63 | 70 | } |
| 64 | 71 | } else if (mem.eql(u8, arg, "--skip-code-tests")) { |
| 65 | 72 | do_code_tests = false; |
| 66 | 73 | } else { |
| 67 | | errorf("unrecognized option: '{s}'\n", .{arg}); |
| 74 | fatal("unrecognized option: '{s}'", .{arg}); |
| 68 | 75 | } |
| 69 | 76 | } else { |
| 70 | 77 | if (i > 1) { |
| 71 | | errorf("too many arguments\n", .{}); |
| 78 | fatal("too many arguments", .{}); |
| 72 | 79 | } |
| 73 | 80 | files[i] = arg; |
| 74 | 81 | i += 1; |
| 75 | 82 | } |
| 76 | 83 | } |
| 77 | 84 | if (i < 2) { |
| 78 | | errorf("not enough arguments\n", .{}); |
| 79 | | process.exit(1); |
| 85 | fatal("not enough arguments", .{}); |
| 80 | 86 | } |
| 81 | 87 | |
| 82 | 88 | var in_file = try fs.cwd().openFile(files[0], .{ .mode = .read_only }); |
| ... | ... | @@ -95,7 +101,7 @@ pub fn main() !void { |
| 95 | 101 | try fs.cwd().makePath(tmp_dir_name); |
| 96 | 102 | defer fs.cwd().deleteTree(tmp_dir_name) catch {}; |
| 97 | 103 | |
| 98 | | try genHtml(allocator, &tokenizer, &toc, buffered_writer.writer(), zig_exe, do_code_tests); |
| 104 | try genHtml(allocator, &tokenizer, &toc, buffered_writer.writer(), zig_exe, opt_zig_lib_dir, do_code_tests); |
| 99 | 105 | try buffered_writer.flush(); |
| 100 | 106 | } |
| 101 | 107 | |
| ... | ... | @@ -1268,6 +1274,7 @@ fn genHtml( |
| 1268 | 1274 | toc: *Toc, |
| 1269 | 1275 | out: anytype, |
| 1270 | 1276 | zig_exe: []const u8, |
| 1277 | opt_zig_lib_dir: ?[]const u8, |
| 1271 | 1278 | do_code_tests: bool, |
| 1272 | 1279 | ) !void { |
| 1273 | 1280 | var progress = Progress{ .dont_print_on_dumb = true }; |
| ... | ... | @@ -1278,7 +1285,7 @@ fn genHtml( |
| 1278 | 1285 | try env_map.put("ZIG_DEBUG_COLOR", "1"); |
| 1279 | 1286 | |
| 1280 | 1287 | const host = try std.zig.system.NativeTargetInfo.detect(.{}); |
| 1281 | | const builtin_code = try getBuiltinCode(allocator, &env_map, zig_exe); |
| 1288 | const builtin_code = try getBuiltinCode(allocator, &env_map, zig_exe, opt_zig_lib_dir); |
| 1282 | 1289 | |
| 1283 | 1290 | for (toc.nodes) |node| { |
| 1284 | 1291 | defer root_node.completeOne(); |
| ... | ... | @@ -1370,6 +1377,9 @@ fn genHtml( |
| 1370 | 1377 | "--color", "on", |
| 1371 | 1378 | "--enable-cache", tmp_source_file_name, |
| 1372 | 1379 | }); |
| 1380 | if (opt_zig_lib_dir) |zig_lib_dir| { |
| 1381 | try build_args.appendSlice(&.{ "--zig-lib-dir", zig_lib_dir }); |
| 1382 | } |
| 1373 | 1383 | |
| 1374 | 1384 | try shell_out.print("$ zig build-exe {s} ", .{name_plus_ext}); |
| 1375 | 1385 | |
| ... | ... | @@ -1512,8 +1522,12 @@ fn genHtml( |
| 1512 | 1522 | defer test_args.deinit(); |
| 1513 | 1523 | |
| 1514 | 1524 | try test_args.appendSlice(&[_][]const u8{ |
| 1515 | | zig_exe, "test", tmp_source_file_name, |
| 1525 | zig_exe, "test", |
| 1526 | tmp_source_file_name, |
| 1516 | 1527 | }); |
| 1528 | if (opt_zig_lib_dir) |zig_lib_dir| { |
| 1529 | try test_args.appendSlice(&.{ "--zig-lib-dir", zig_lib_dir }); |
| 1530 | } |
| 1517 | 1531 | try shell_out.print("$ zig test {s}.zig ", .{code.name}); |
| 1518 | 1532 | |
| 1519 | 1533 | switch (code.mode) { |
| ... | ... | @@ -1564,12 +1578,13 @@ fn genHtml( |
| 1564 | 1578 | defer test_args.deinit(); |
| 1565 | 1579 | |
| 1566 | 1580 | try test_args.appendSlice(&[_][]const u8{ |
| 1567 | | zig_exe, |
| 1568 | | "test", |
| 1569 | | "--color", |
| 1570 | | "on", |
| 1581 | zig_exe, "test", |
| 1582 | "--color", "on", |
| 1571 | 1583 | tmp_source_file_name, |
| 1572 | 1584 | }); |
| 1585 | if (opt_zig_lib_dir) |zig_lib_dir| { |
| 1586 | try test_args.appendSlice(&.{ "--zig-lib-dir", zig_lib_dir }); |
| 1587 | } |
| 1573 | 1588 | try shell_out.print("$ zig test {s}.zig ", .{code.name}); |
| 1574 | 1589 | |
| 1575 | 1590 | switch (code.mode) { |
| ... | ... | @@ -1624,8 +1639,12 @@ fn genHtml( |
| 1624 | 1639 | defer test_args.deinit(); |
| 1625 | 1640 | |
| 1626 | 1641 | try test_args.appendSlice(&[_][]const u8{ |
| 1627 | | zig_exe, "test", tmp_source_file_name, |
| 1642 | zig_exe, "test", |
| 1643 | tmp_source_file_name, |
| 1628 | 1644 | }); |
| 1645 | if (opt_zig_lib_dir) |zig_lib_dir| { |
| 1646 | try test_args.appendSlice(&.{ "--zig-lib-dir", zig_lib_dir }); |
| 1647 | } |
| 1629 | 1648 | var mode_arg: []const u8 = ""; |
| 1630 | 1649 | switch (code.mode) { |
| 1631 | 1650 | .Debug => {}, |
| ... | ... | @@ -1684,17 +1703,17 @@ fn genHtml( |
| 1684 | 1703 | defer build_args.deinit(); |
| 1685 | 1704 | |
| 1686 | 1705 | try build_args.appendSlice(&[_][]const u8{ |
| 1687 | | zig_exe, |
| 1688 | | "build-obj", |
| 1706 | zig_exe, "build-obj", |
| 1707 | "--color", "on", |
| 1708 | "--name", code.name, |
| 1689 | 1709 | tmp_source_file_name, |
| 1690 | | "--color", |
| 1691 | | "on", |
| 1692 | | "--name", |
| 1693 | | code.name, |
| 1694 | 1710 | try std.fmt.allocPrint(allocator, "-femit-bin={s}{c}{s}", .{ |
| 1695 | 1711 | tmp_dir_name, fs.path.sep, name_plus_obj_ext, |
| 1696 | 1712 | }), |
| 1697 | 1713 | }); |
| 1714 | if (opt_zig_lib_dir) |zig_lib_dir| { |
| 1715 | try build_args.appendSlice(&.{ "--zig-lib-dir", zig_lib_dir }); |
| 1716 | } |
| 1698 | 1717 | |
| 1699 | 1718 | try shell_out.print("$ zig build-obj {s}.zig ", .{code.name}); |
| 1700 | 1719 | |
| ... | ... | @@ -1758,13 +1777,15 @@ fn genHtml( |
| 1758 | 1777 | defer test_args.deinit(); |
| 1759 | 1778 | |
| 1760 | 1779 | try test_args.appendSlice(&[_][]const u8{ |
| 1761 | | zig_exe, |
| 1762 | | "build-lib", |
| 1780 | zig_exe, "build-lib", |
| 1763 | 1781 | tmp_source_file_name, |
| 1764 | 1782 | try std.fmt.allocPrint(allocator, "-femit-bin={s}{s}{s}", .{ |
| 1765 | 1783 | tmp_dir_name, fs.path.sep_str, bin_basename, |
| 1766 | 1784 | }), |
| 1767 | 1785 | }); |
| 1786 | if (opt_zig_lib_dir) |zig_lib_dir| { |
| 1787 | try test_args.appendSlice(&.{ "--zig-lib-dir", zig_lib_dir }); |
| 1788 | } |
| 1768 | 1789 | try shell_out.print("$ zig build-lib {s}.zig ", .{code.name}); |
| 1769 | 1790 | |
| 1770 | 1791 | switch (code.mode) { |
| ... | ... | @@ -1829,9 +1850,23 @@ fn exec(allocator: Allocator, env_map: *process.EnvMap, args: []const []const u8 |
| 1829 | 1850 | return result; |
| 1830 | 1851 | } |
| 1831 | 1852 | |
| 1832 | | fn getBuiltinCode(allocator: Allocator, env_map: *process.EnvMap, zig_exe: []const u8) ![]const u8 { |
| 1833 | | const result = try exec(allocator, env_map, &[_][]const u8{ zig_exe, "build-obj", "--show-builtin" }); |
| 1834 | | return result.stdout; |
| 1853 | fn getBuiltinCode( |
| 1854 | allocator: Allocator, |
| 1855 | env_map: *process.EnvMap, |
| 1856 | zig_exe: []const u8, |
| 1857 | opt_zig_lib_dir: ?[]const u8, |
| 1858 | ) ![]const u8 { |
| 1859 | if (opt_zig_lib_dir) |zig_lib_dir| { |
| 1860 | const result = try exec(allocator, env_map, &.{ |
| 1861 | zig_exe, "build-obj", "--show-builtin", "--zig-lib-dir", zig_lib_dir, |
| 1862 | }); |
| 1863 | return result.stdout; |
| 1864 | } else { |
| 1865 | const result = try exec(allocator, env_map, &.{ |
| 1866 | zig_exe, "build-obj", "--show-builtin", |
| 1867 | }); |
| 1868 | return result.stdout; |
| 1869 | } |
| 1835 | 1870 | } |
| 1836 | 1871 | |
| 1837 | 1872 | fn dumpArgs(args: []const []const u8) void { |