| ... | @@ -28,10 +28,10 @@ const usage = | ... | @@ -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 | const stderr = io.getStdErr().writer(); | 32 | const stderr = io.getStdErr().writer(); |
| 33 | | 33 | |
| 34 | stderr.print("error: " ++ format, args) catch {}; | 34 | stderr.print("error: " ++ format ++ "\n", args) catch {}; |
| 35 | process.exit(1); | 35 | process.exit(1); |
| 36 | } | 36 | } |
| 37 | | 37 | |
| ... | @@ -45,6 +45,7 @@ pub fn main() !void { | ... | @@ -45,6 +45,7 @@ pub fn main() !void { |
| 45 | if (!args_it.skip()) @panic("expected self arg"); | 45 | if (!args_it.skip()) @panic("expected self arg"); |
| 46 | | 46 | |
| 47 | var zig_exe: []const u8 = "zig"; | 47 | var zig_exe: []const u8 = "zig"; |
| | 48 | var opt_zig_lib_dir: ?[]const u8 = null; |
| 48 | var do_code_tests = true; | 49 | var do_code_tests = true; |
| 49 | var files = [_][]const u8{ "", "" }; | 50 | var files = [_][]const u8{ "", "" }; |
| 50 | | 51 | |
| ... | @@ -59,24 +60,29 @@ pub fn main() !void { | ... | @@ -59,24 +60,29 @@ pub fn main() !void { |
| 59 | if (args_it.next()) |param| { | 60 | if (args_it.next()) |param| { |
| 60 | zig_exe = param; | 61 | zig_exe = param; |
| 61 | } else { | 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 | } else if (mem.eql(u8, arg, "--skip-code-tests")) { | 71 | } else if (mem.eql(u8, arg, "--skip-code-tests")) { |
| 65 | do_code_tests = false; | 72 | do_code_tests = false; |
| 66 | } else { | 73 | } else { |
| 67 | errorf("unrecognized option: '{s}'\n", .{arg}); | 74 | fatal("unrecognized option: '{s}'", .{arg}); |
| 68 | } | 75 | } |
| 69 | } else { | 76 | } else { |
| 70 | if (i > 1) { | 77 | if (i > 1) { |
| 71 | errorf("too many arguments\n", .{}); | 78 | fatal("too many arguments", .{}); |
| 72 | } | 79 | } |
| 73 | files[i] = arg; | 80 | files[i] = arg; |
| 74 | i += 1; | 81 | i += 1; |
| 75 | } | 82 | } |
| 76 | } | 83 | } |
| 77 | if (i < 2) { | 84 | if (i < 2) { |
| 78 | errorf("not enough arguments\n", .{}); | 85 | fatal("not enough arguments", .{}); |
| 79 | process.exit(1); | | |
| 80 | } | 86 | } |
| 81 | | 87 | |
| 82 | var in_file = try fs.cwd().openFile(files[0], .{ .mode = .read_only }); | 88 | var in_file = try fs.cwd().openFile(files[0], .{ .mode = .read_only }); |
| ... | @@ -95,7 +101,7 @@ pub fn main() !void { | ... | @@ -95,7 +101,7 @@ pub fn main() !void { |
| 95 | try fs.cwd().makePath(tmp_dir_name); | 101 | try fs.cwd().makePath(tmp_dir_name); |
| 96 | defer fs.cwd().deleteTree(tmp_dir_name) catch {}; | 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 | try buffered_writer.flush(); | 105 | try buffered_writer.flush(); |
| 100 | } | 106 | } |
| 101 | | 107 | |
| ... | @@ -1268,6 +1274,7 @@ fn genHtml( | ... | @@ -1268,6 +1274,7 @@ fn genHtml( |
| 1268 | toc: *Toc, | 1274 | toc: *Toc, |
| 1269 | out: anytype, | 1275 | out: anytype, |
| 1270 | zig_exe: []const u8, | 1276 | zig_exe: []const u8, |
| | 1277 | opt_zig_lib_dir: ?[]const u8, |
| 1271 | do_code_tests: bool, | 1278 | do_code_tests: bool, |
| 1272 | ) !void { | 1279 | ) !void { |
| 1273 | var progress = Progress{ .dont_print_on_dumb = true }; | 1280 | var progress = Progress{ .dont_print_on_dumb = true }; |
| ... | @@ -1278,7 +1285,7 @@ fn genHtml( | ... | @@ -1278,7 +1285,7 @@ fn genHtml( |
| 1278 | try env_map.put("ZIG_DEBUG_COLOR", "1"); | 1285 | try env_map.put("ZIG_DEBUG_COLOR", "1"); |
| 1279 | | 1286 | |
| 1280 | const host = try std.zig.system.NativeTargetInfo.detect(.{}); | 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 | for (toc.nodes) |node| { | 1290 | for (toc.nodes) |node| { |
| 1284 | defer root_node.completeOne(); | 1291 | defer root_node.completeOne(); |
| ... | @@ -1370,6 +1377,9 @@ fn genHtml( | ... | @@ -1370,6 +1377,9 @@ fn genHtml( |
| 1370 | "--color", "on", | 1377 | "--color", "on", |
| 1371 | "--enable-cache", tmp_source_file_name, | 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 | try shell_out.print("$ zig build-exe {s} ", .{name_plus_ext}); | 1384 | try shell_out.print("$ zig build-exe {s} ", .{name_plus_ext}); |
| 1375 | | 1385 | |
| ... | @@ -1512,8 +1522,12 @@ fn genHtml( | ... | @@ -1512,8 +1522,12 @@ fn genHtml( |
| 1512 | defer test_args.deinit(); | 1522 | defer test_args.deinit(); |
| 1513 | | 1523 | |
| 1514 | try test_args.appendSlice(&[_][]const u8{ | 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 | try shell_out.print("$ zig test {s}.zig ", .{code.name}); | 1531 | try shell_out.print("$ zig test {s}.zig ", .{code.name}); |
| 1518 | | 1532 | |
| 1519 | switch (code.mode) { | 1533 | switch (code.mode) { |
| ... | @@ -1564,12 +1578,13 @@ fn genHtml( | ... | @@ -1564,12 +1578,13 @@ fn genHtml( |
| 1564 | defer test_args.deinit(); | 1578 | defer test_args.deinit(); |
| 1565 | | 1579 | |
| 1566 | try test_args.appendSlice(&[_][]const u8{ | 1580 | try test_args.appendSlice(&[_][]const u8{ |
| 1567 | zig_exe, | 1581 | zig_exe, "test", |
| 1568 | "test", | 1582 | "--color", "on", |
| 1569 | "--color", | | |
| 1570 | "on", | | |
| 1571 | tmp_source_file_name, | 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 | try shell_out.print("$ zig test {s}.zig ", .{code.name}); | 1588 | try shell_out.print("$ zig test {s}.zig ", .{code.name}); |
| 1574 | | 1589 | |
| 1575 | switch (code.mode) { | 1590 | switch (code.mode) { |
| ... | @@ -1624,8 +1639,12 @@ fn genHtml( | ... | @@ -1624,8 +1639,12 @@ fn genHtml( |
| 1624 | defer test_args.deinit(); | 1639 | defer test_args.deinit(); |
| 1625 | | 1640 | |
| 1626 | try test_args.appendSlice(&[_][]const u8{ | 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 | var mode_arg: []const u8 = ""; | 1648 | var mode_arg: []const u8 = ""; |
| 1630 | switch (code.mode) { | 1649 | switch (code.mode) { |
| 1631 | .Debug => {}, | 1650 | .Debug => {}, |
| ... | @@ -1684,17 +1703,17 @@ fn genHtml( | ... | @@ -1684,17 +1703,17 @@ fn genHtml( |
| 1684 | defer build_args.deinit(); | 1703 | defer build_args.deinit(); |
| 1685 | | 1704 | |
| 1686 | try build_args.appendSlice(&[_][]const u8{ | 1705 | try build_args.appendSlice(&[_][]const u8{ |
| 1687 | zig_exe, | 1706 | zig_exe, "build-obj", |
| 1688 | "build-obj", | 1707 | "--color", "on", |
| | 1708 | "--name", code.name, |
| 1689 | tmp_source_file_name, | 1709 | tmp_source_file_name, |
| 1690 | "--color", | | |
| 1691 | "on", | | |
| 1692 | "--name", | | |
| 1693 | code.name, | | |
| 1694 | try std.fmt.allocPrint(allocator, "-femit-bin={s}{c}{s}", .{ | 1710 | try std.fmt.allocPrint(allocator, "-femit-bin={s}{c}{s}", .{ |
| 1695 | tmp_dir_name, fs.path.sep, name_plus_obj_ext, | 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 | try shell_out.print("$ zig build-obj {s}.zig ", .{code.name}); | 1718 | try shell_out.print("$ zig build-obj {s}.zig ", .{code.name}); |
| 1700 | | 1719 | |
| ... | @@ -1758,13 +1777,15 @@ fn genHtml( | ... | @@ -1758,13 +1777,15 @@ fn genHtml( |
| 1758 | defer test_args.deinit(); | 1777 | defer test_args.deinit(); |
| 1759 | | 1778 | |
| 1760 | try test_args.appendSlice(&[_][]const u8{ | 1779 | try test_args.appendSlice(&[_][]const u8{ |
| 1761 | zig_exe, | 1780 | zig_exe, "build-lib", |
| 1762 | "build-lib", | | |
| 1763 | tmp_source_file_name, | 1781 | tmp_source_file_name, |
| 1764 | try std.fmt.allocPrint(allocator, "-femit-bin={s}{s}{s}", .{ | 1782 | try std.fmt.allocPrint(allocator, "-femit-bin={s}{s}{s}", .{ |
| 1765 | tmp_dir_name, fs.path.sep_str, bin_basename, | 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 | try shell_out.print("$ zig build-lib {s}.zig ", .{code.name}); | 1789 | try shell_out.print("$ zig build-lib {s}.zig ", .{code.name}); |
| 1769 | | 1790 | |
| 1770 | switch (code.mode) { | 1791 | switch (code.mode) { |
| ... | @@ -1829,9 +1850,23 @@ fn exec(allocator: Allocator, env_map: *process.EnvMap, args: []const []const u8 | ... | @@ -1829,9 +1850,23 @@ fn exec(allocator: Allocator, env_map: *process.EnvMap, args: []const []const u8 |
| 1829 | return result; | 1850 | return result; |
| 1830 | } | 1851 | } |
| 1831 | | 1852 | |
| 1832 | fn getBuiltinCode(allocator: Allocator, env_map: *process.EnvMap, zig_exe: []const u8) ![]const u8 { | 1853 | fn getBuiltinCode( |
| 1833 | const result = try exec(allocator, env_map, &[_][]const u8{ zig_exe, "build-obj", "--show-builtin" }); | 1854 | allocator: Allocator, |
| 1834 | return result.stdout; | 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 | fn dumpArgs(args: []const []const u8) void { | 1872 | fn dumpArgs(args: []const []const u8) void { |