| ... | ... | @@ -23,7 +23,6 @@ const Color = std.zig.Color; |
| 23 | 23 | const Client = std.zig.Client; |
| 24 | 24 | const Server = std.zig.Server; |
| 25 | 25 | const EnvVar = std.zig.EnvVar; |
| 26 | | const ErrorBundle = std.zig.ErrorBundle; |
| 27 | 26 | const default_local_zig_cache_basename = std.zig.default_local_zig_cache_basename; |
| 28 | 27 | const stringToEnum = std.meta.stringToEnum; |
| 29 | 28 | |
| ... | ... | @@ -36,7 +35,6 @@ const ScannedConfig = @import("Maker/ScannedConfig.zig"); |
| 36 | 35 | const PkgConfig = @import("Maker/PkgConfig.zig"); |
| 37 | 36 | const Fetch = @import("Maker/Fetch.zig"); |
| 38 | 37 | const Package = @import("Maker/Package.zig"); |
| 39 | | const Manifest = Package.Manifest; |
| 40 | 38 | |
| 41 | 39 | pub const std_options: std.Options = .{ |
| 42 | 40 | .side_channels_mitigations = .none, |
| ... | ... | @@ -103,30 +101,8 @@ const InstallPaths = struct { |
| 103 | 101 | }; |
| 104 | 102 | |
| 105 | 103 | const PrintNode = struct { |
| 106 | | parent: ?*const PrintNode, |
| 104 | parent: ?*PrintNode, |
| 107 | 105 | last: bool = false, |
| 108 | | |
| 109 | | fn printPrefix(node: *const PrintNode, writer: *Writer, mode: Io.Terminal.Mode) Writer.Error!void { |
| 110 | | const parent = node.parent orelse return; |
| 111 | | if (parent.parent == null) return; |
| 112 | | try printPrefix(parent, writer, mode); |
| 113 | | if (parent.last) { |
| 114 | | try writer.writeAll(" "); |
| 115 | | } else { |
| 116 | | try printTreeSibling(writer, mode); |
| 117 | | } |
| 118 | | } |
| 119 | | |
| 120 | | fn printPrefixedChild(node: *const PrintNode, writer: *Writer, mode: Io.Terminal.Mode) Writer.Error!void { |
| 121 | | try printPrefix(node, writer, mode); |
| 122 | | if (node.parent != null) { |
| 123 | | if (node.last) { |
| 124 | | try printTreeChildLast(writer, mode); |
| 125 | | } else { |
| 126 | | try printTreeChild(writer, mode); |
| 127 | | } |
| 128 | | } |
| 129 | | } |
| 130 | 106 | }; |
| 131 | 107 | |
| 132 | 108 | const ErrorStyle = enum { |
| ... | ... | @@ -149,7 +125,7 @@ const ErrorStyle = enum { |
| 149 | 125 | }; |
| 150 | 126 | const MultilineErrors = enum { indent, newline, none }; |
| 151 | 127 | const Summary = enum { all, new, failures, line, none }; |
| 152 | | const PrintConfiguration = enum { none, zon, path, tree, stop }; |
| 128 | const PrintConfiguration = enum { none, zon, path }; |
| 153 | 129 | |
| 154 | 130 | const GeneratedFile = struct { |
| 155 | 131 | data: ?[]const u8, |
| ... | ... | @@ -300,6 +276,7 @@ pub fn main(init: process.Init.Minimal) !void { |
| 300 | 276 | var cached_passthru_configure: std.ArrayList(u32) = .empty; |
| 301 | 277 | var forks: std.ArrayList(Fork) = .empty; |
| 302 | 278 | var system_pkg_dir_path: ?[]const u8 = null; |
| 279 | var fetch_only = false; |
| 303 | 280 | var fetch_mode: Fetch.JobQueue.Mode = .needed; |
| 304 | 281 | var debug_target: ?[]const u8 = null; |
| 305 | 282 | var cache_poison: std.Build.Graph.CachePoison = .pure; |
| ... | ... | @@ -384,12 +361,12 @@ pub fn main(init: process.Init.Minimal) !void { |
| 384 | 361 | override_local_cache_dir = nextArgOrFatal(args, &arg_i); |
| 385 | 362 | } else if (mem.eql(u8, arg, "--pkg-dir")) { |
| 386 | 363 | override_pkg_dir = nextArgOrFatal(args, &arg_i); |
| 387 | | } else if (mem.eql(u8, arg, "--print-tree")) { |
| 388 | | print_configuration = .tree; |
| 389 | | } else if (mem.eql(u8, arg, "--configure")) { |
| 390 | | print_configuration = .stop; |
| 391 | 364 | } else if (mem.eql(u8, arg, "--fetch")) { |
| 392 | | fetch_mode = .all; |
| 365 | fetch_only = true; |
| 366 | } else if (mem.cutPrefix(u8, arg, "--fetch=")) |rest| { |
| 367 | fetch_only = true; |
| 368 | fetch_mode = stringToEnum(Fetch.JobQueue.Mode, rest) orelse |
| 369 | fatal("expected [needed|all] after \"--fetch=\", found {q}", .{rest}); |
| 393 | 370 | } else if (mem.cutPrefix(u8, arg, "--fork=")) |rest| { |
| 394 | 371 | try forks.append(arena, .init(rest)); |
| 395 | 372 | } else if (mem.eql(u8, arg, "--fork")) { |
| ... | ... | @@ -616,7 +593,7 @@ pub fn main(init: process.Init.Minimal) !void { |
| 616 | 593 | } |
| 617 | 594 | } |
| 618 | 595 | |
| 619 | | const early_exit_mode = fetch_mode == .all or help_menu or steps_menu or print_configuration != .none; |
| 596 | const early_exit_mode = fetch_only or help_menu or steps_menu or print_configuration != .none; |
| 620 | 597 | const server_mode = !early_exit_mode and (watch_flag or webui_listen != null or fuzz != null or listen); |
| 621 | 598 | |
| 622 | 599 | process.raiseFileDescriptorLimit(); |
| ... | ... | @@ -624,16 +601,10 @@ pub fn main(init: process.Init.Minimal) !void { |
| 624 | 601 | const cwd_path = std.zig.getResolvedCwd(io, arena) catch |err| |
| 625 | 602 | fatal("resolving current directory path failed: {t}", .{err}); |
| 626 | 603 | |
| 627 | | var build_root = findBuildRoot(arena, io, .{ |
| 604 | var build_root = try findBuildRoot(arena, io, .{ |
| 628 | 605 | .cwd_path = cwd_path, |
| 629 | 606 | .build_file = build_file, |
| 630 | | }) catch |err| switch (err) { |
| 631 | | error.BuildZigNotFound => { |
| 632 | | if (help_menu) printUsageWithoutConfiguration(&graph, "build.zig not found"); |
| 633 | | process.exit(1); |
| 634 | | }, |
| 635 | | else => |e| return e, |
| 636 | | }; |
| 607 | }); |
| 637 | 608 | defer build_root.deinit(io); |
| 638 | 609 | |
| 639 | 610 | graph.build_root_directory = build_root.directory; |
| ... | ... | @@ -769,7 +740,7 @@ pub fn main(init: process.Init.Minimal) !void { |
| 769 | 740 | var configure_source_files: Cache.Manifest.SelfContainedFiles = .empty; |
| 770 | 741 | defer configure_source_files.deinit(gpa); |
| 771 | 742 | |
| 772 | | var configure_error_bundle: ErrorBundle = .empty; |
| 743 | var configure_error_bundle: std.zig.ErrorBundle = .empty; |
| 773 | 744 | defer configure_error_bundle.deinit(gpa); |
| 774 | 745 | |
| 775 | 746 | // If this fails, we can still start the server and wait for user |
| ... | ... | @@ -790,6 +761,7 @@ pub fn main(init: process.Init.Minimal) !void { |
| 790 | 761 | .parent_progress_node = main_progress_node, |
| 791 | 762 | .fetch_mode = fetch_mode, |
| 792 | 763 | .system_pkg_dir_path = system_pkg_dir_path, |
| 764 | .fetch_only = fetch_only, |
| 793 | 765 | .print_configuration = print_configuration, |
| 794 | 766 | .forks = forks.items, |
| 795 | 767 | .src_files = &configure_source_files, |
| ... | ... | @@ -817,8 +789,6 @@ pub fn main(init: process.Init.Minimal) !void { |
| 817 | 789 | return cleanExit(io, &scanned_config); |
| 818 | 790 | }, |
| 819 | 791 | .path => unreachable, |
| 820 | | .tree => unreachable, |
| 821 | | .stop => return cleanExit(io, &scanned_config), |
| 822 | 792 | } |
| 823 | 793 | |
| 824 | 794 | var maker: Maker = .{ |
| ... | ... | @@ -1073,10 +1043,7 @@ pub fn main(init: process.Init.Minimal) !void { |
| 1073 | 1043 | } else |err| { |
| 1074 | 1044 | const can_fs_watch = switch (err) { |
| 1075 | 1045 | error.AlreadyReported => false, |
| 1076 | | error.FailedButCacheIntact => c: { |
| 1077 | | if (help_menu) printUsageWithoutConfiguration(&graph, "build.zig compilation failure"); |
| 1078 | | break :c true; |
| 1079 | | }, |
| 1046 | error.FailedButCacheIntact => true, |
| 1080 | 1047 | else => |e| w: { |
| 1081 | 1048 | log.err("configuration failed: {t}", .{e}); |
| 1082 | 1049 | break :w false; |
| ... | ... | @@ -1098,17 +1065,6 @@ pub fn main(init: process.Init.Minimal) !void { |
| 1098 | 1065 | } |
| 1099 | 1066 | } |
| 1100 | 1067 | |
| 1101 | | fn printUsageWithoutConfiguration(graph: *Graph, reason: []const u8) noreturn { |
| 1102 | | const io = graph.io; |
| 1103 | | _ = io.lockStderr(&.{}, graph.stderr_mode) catch {}; |
| 1104 | | const writer = initStdoutWriter(io); |
| 1105 | | ScannedConfig.printUsageWithoutConfiguration(graph.zig_exe, writer, reason) catch |err| switch (err) { |
| 1106 | | error.WriteFailed => fatal("failed writing to stdout: {t}", .{stdout_writer_allocation.err.?}), |
| 1107 | | }; |
| 1108 | | stdout_writer_allocation.flush() catch |err| fatal("failed writing to stdout: {t}", .{err}); |
| 1109 | | return process.exit(0); |
| 1110 | | } |
| 1111 | | |
| 1112 | 1068 | /// Temporarily adds the reconfigure pseudostep to step_stack, calls |
| 1113 | 1069 | /// `Watch.update`, and then pops it again. |
| 1114 | 1070 | fn updateWatch(maker: *Maker, watch: *Watch) !void { |
| ... | ... | @@ -1132,10 +1088,11 @@ const ConfigureOptions = struct { |
| 1132 | 1088 | parent_progress_node: std.Progress.Node, |
| 1133 | 1089 | fetch_mode: Fetch.JobQueue.Mode, |
| 1134 | 1090 | system_pkg_dir_path: ?[]const u8, |
| 1091 | fetch_only: bool, |
| 1135 | 1092 | print_configuration: PrintConfiguration, |
| 1136 | 1093 | forks: []Fork, |
| 1137 | 1094 | src_files: *Cache.Manifest.SelfContainedFiles, |
| 1138 | | error_bundle: ?*ErrorBundle = null, |
| 1095 | error_bundle: ?*std.zig.ErrorBundle = null, |
| 1139 | 1096 | }; |
| 1140 | 1097 | |
| 1141 | 1098 | fn configure(graph: *Graph, options: ConfigureOptions) !ScannedConfig { |
| ... | ... | @@ -1379,27 +1336,11 @@ fn configure(graph: *Graph, options: ConfigureOptions) !ScannedConfig { |
| 1379 | 1336 | return error.FailedButCacheIntact; |
| 1380 | 1337 | } |
| 1381 | 1338 | |
| 1382 | | if (options.print_configuration == .tree) { |
| 1383 | | const NO_COLOR = EnvVar.NO_COLOR.isSet(&graph.environ_map); |
| 1384 | | const CLICOLOR_FORCE = EnvVar.CLICOLOR_FORCE.isSet(&graph.environ_map); |
| 1385 | | printPkgTree(.{ |
| 1386 | | .writer = initStdoutWriter(io), |
| 1387 | | .mode = try .detect(io, .stdout(), NO_COLOR, CLICOLOR_FORCE), |
| 1388 | | }, arena, &job_queue, &fetch) catch |err| switch (err) { |
| 1389 | | error.WriteFailed => return stdout_writer_allocation.err.?, |
| 1390 | | else => |e| return e, |
| 1391 | | }; |
| 1392 | | try stdout_writer_allocation.flush(); |
| 1393 | | process.exit(0); |
| 1394 | | } |
| 1395 | | |
| 1396 | | if (options.fetch_mode == .all) { |
| 1339 | if (options.fetch_only) { |
| 1397 | 1340 | _ = io.lockStderr(&.{}, .no_color) catch {}; |
| 1398 | 1341 | process.exit(0); |
| 1399 | 1342 | } |
| 1400 | 1343 | |
| 1401 | | try validateFingerprints(gpa, &job_queue); |
| 1402 | | |
| 1403 | 1344 | // Create the dependencies.zig file for configurer to |
| 1404 | 1345 | // obtain via `@import("@dependencies")`. |
| 1405 | 1346 | { |
| ... | ... | @@ -1462,7 +1403,7 @@ fn configure(graph: *Graph, options: ConfigureOptions) !ScannedConfig { |
| 1462 | 1403 | for (fetches) |f| { |
| 1463 | 1404 | if (!f.have_manifest) continue; |
| 1464 | 1405 | if (config_man) |man| { |
| 1465 | | const manifest_path = try f.package_root.join(arena, Manifest.basename); |
| 1406 | const manifest_path = try f.package_root.join(arena, Package.Manifest.basename); |
| 1466 | 1407 | _ = try man.addInputPath(manifest_path, .{}); |
| 1467 | 1408 | } |
| 1468 | 1409 | const mod = f.cli_module orelse continue; |
| ... | ... | @@ -1678,8 +1619,7 @@ fn configure(graph: *Graph, options: ConfigureOptions) !ScannedConfig { |
| 1678 | 1619 | _ = io.lockStderr(&.{}, .no_color) catch {}; |
| 1679 | 1620 | process.exit(0); |
| 1680 | 1621 | }, |
| 1681 | | .none, .zon, .stop => {}, |
| 1682 | | .tree => unreachable, |
| 1622 | .none, .zon => {}, |
| 1683 | 1623 | } |
| 1684 | 1624 | |
| 1685 | 1625 | const configuration = c: { |
| ... | ... | @@ -1717,147 +1657,6 @@ fn configure(graph: *Graph, options: ConfigureOptions) !ScannedConfig { |
| 1717 | 1657 | }; |
| 1718 | 1658 | } |
| 1719 | 1659 | |
| 1720 | | const ValidFingerprintKey = struct { |
| 1721 | | project_id: Package.ProjectId, |
| 1722 | | version: std.SemanticVersion, |
| 1723 | | |
| 1724 | | const Context = struct { |
| 1725 | | pub fn hash(this: @This(), a: ValidFingerprintKey) u32 { |
| 1726 | | _ = this; |
| 1727 | | var hasher: std.hash.Wyhash = .init(a.project_id.fingerprint_id); |
| 1728 | | hasher.update(&a.project_id.padded_name); |
| 1729 | | hasher.update(@ptrCast((&a.version.major)[0..1])); |
| 1730 | | hasher.update(@ptrCast((&a.version.minor)[0..1])); |
| 1731 | | hasher.update(@ptrCast((&a.version.patch)[0..1])); |
| 1732 | | if (a.version.pre) |pre| hasher.update(pre); |
| 1733 | | return @truncate(hasher.final()); |
| 1734 | | } |
| 1735 | | pub fn eql(this: @This(), a: ValidFingerprintKey, b: ValidFingerprintKey, i: usize) bool { |
| 1736 | | _ = this; |
| 1737 | | _ = i; |
| 1738 | | return a.project_id.eql(&b.project_id) and a.version.order(b.version) == .eq; |
| 1739 | | } |
| 1740 | | }; |
| 1741 | | }; |
| 1742 | | |
| 1743 | | const ValidFingerprintTable = std.array_hash_map.Custom( |
| 1744 | | ValidFingerprintKey, |
| 1745 | | struct { fetch: *Fetch, pkg_hash: Package.Hash, printed: bool }, |
| 1746 | | ValidFingerprintKey.Context, |
| 1747 | | true, |
| 1748 | | ); |
| 1749 | | |
| 1750 | | /// Ensure that the dependency tree did not have any fingerprint matches with the same semantic version but |
| 1751 | | /// differing package hashes. |
| 1752 | | fn validateFingerprints(gpa: Allocator, job_queue: *const Fetch.JobQueue) !void { |
| 1753 | | var any_errors = false; |
| 1754 | | |
| 1755 | | var table: ValidFingerprintTable = .empty; |
| 1756 | | defer table.deinit(gpa); |
| 1757 | | |
| 1758 | | for (job_queue.table.keys(), job_queue.table.values()) |pkg_hash, fetch| { |
| 1759 | | if (!fetch.have_manifest) continue; |
| 1760 | | const gop = try table.getOrPut(gpa, .{ |
| 1761 | | .project_id = .init(fetch.manifest.name, fetch.manifest.id), |
| 1762 | | .version = fetch.manifest.version, |
| 1763 | | }); |
| 1764 | | if (gop.found_existing) { |
| 1765 | | any_errors = true; |
| 1766 | | const fingerprint: Package.Fingerprint = .init(fetch.manifest.id, fetch.manifest.name); |
| 1767 | | const stripped_version: std.SemanticVersion = .{ |
| 1768 | | .major = fetch.manifest.version.major, |
| 1769 | | .minor = fetch.manifest.version.minor, |
| 1770 | | .patch = fetch.manifest.version.patch, |
| 1771 | | .pre = fetch.manifest.version.pre, |
| 1772 | | }; |
| 1773 | | if (!gop.value_ptr.printed) { |
| 1774 | | gop.value_ptr.printed = true; |
| 1775 | | log.err("contradictory hash for package with fingerprint 0x{x} and version {f}: {s}", .{ |
| 1776 | | fingerprint.int(), stripped_version, gop.value_ptr.pkg_hash.toSlice(), |
| 1777 | | }); |
| 1778 | | } |
| 1779 | | log.err("contradictory hash for package with fingerprint 0x{x} and version {f}: {s}", .{ |
| 1780 | | fingerprint.int(), stripped_version, pkg_hash.toSlice(), |
| 1781 | | }); |
| 1782 | | } else { |
| 1783 | | gop.value_ptr.* = .{ .fetch = fetch, .pkg_hash = pkg_hash, .printed = false }; |
| 1784 | | } |
| 1785 | | } |
| 1786 | | if (any_errors) { |
| 1787 | | log.info("potential cause: package ownership dispute", .{}); |
| 1788 | | log.info("potential cause: maintainer neglected to bump version after making changes", .{}); |
| 1789 | | log.info("potential cause: dependency on unreleased changes", .{}); |
| 1790 | | log.info("hint: use --print-tree to visualize all package versions and hashes", .{}); |
| 1791 | | return error.FailedButCacheIntact; |
| 1792 | | } |
| 1793 | | } |
| 1794 | | |
| 1795 | | fn printPkgTree( |
| 1796 | | terminal: Io.Terminal, |
| 1797 | | arena: Allocator, |
| 1798 | | job_queue: *const Fetch.JobQueue, |
| 1799 | | root_fetch: *const Fetch, |
| 1800 | | ) !void { |
| 1801 | | if (!root_fetch.have_manifest) return; |
| 1802 | | const names = root_fetch.manifest.dependencies.keys(); |
| 1803 | | for (names, root_fetch.manifest.dependencies.values(), 0..) |name, *dep, i| { |
| 1804 | | var print_node: PrintNode = .{ |
| 1805 | | .parent = null, |
| 1806 | | .last = i == names.len - 1, |
| 1807 | | }; |
| 1808 | | try printPkgTreeChild(terminal, arena, job_queue, &print_node, name, dep.hash); |
| 1809 | | } |
| 1810 | | } |
| 1811 | | |
| 1812 | | fn printPkgTreeChild( |
| 1813 | | terminal: Io.Terminal, |
| 1814 | | arena: Allocator, |
| 1815 | | job_queue: *const Fetch.JobQueue, |
| 1816 | | parent_print_node: *const PrintNode, |
| 1817 | | dep_name: []const u8, |
| 1818 | | opt_hash: ?[]const u8, |
| 1819 | | ) !void { |
| 1820 | | const w = terminal.writer; |
| 1821 | | try parent_print_node.printPrefixedChild(w, terminal.mode); |
| 1822 | | try w.writeAll(dep_name); |
| 1823 | | |
| 1824 | | const hash = opt_hash orelse { |
| 1825 | | try terminal.setColor(.red); |
| 1826 | | try w.writeAll(" (missing hash)\n"); |
| 1827 | | try terminal.setColor(.reset); |
| 1828 | | return; |
| 1829 | | }; |
| 1830 | | try terminal.setColor(.dim); |
| 1831 | | try w.print(" {s}", .{hash}); |
| 1832 | | try terminal.setColor(.reset); |
| 1833 | | const child_fetch = job_queue.table.get(.fromSlice(hash)) orelse { |
| 1834 | | try terminal.setColor(.red); |
| 1835 | | try w.writeAll(" (fetch failed)\n"); |
| 1836 | | try terminal.setColor(.reset); |
| 1837 | | return; |
| 1838 | | }; |
| 1839 | | switch (child_fetch.lazy_status) { |
| 1840 | | .eager, .available => {}, |
| 1841 | | .unavailable => { |
| 1842 | | try terminal.setColor(.yellow); |
| 1843 | | try w.writeAll(" (not fetched)\n"); |
| 1844 | | try terminal.setColor(.reset); |
| 1845 | | return; |
| 1846 | | }, |
| 1847 | | } |
| 1848 | | try w.writeByte('\n'); |
| 1849 | | if (!child_fetch.have_manifest) return; |
| 1850 | | |
| 1851 | | const names = child_fetch.manifest.dependencies.keys(); |
| 1852 | | for (names, child_fetch.manifest.dependencies.values(), 0..) |name, *dep, i| { |
| 1853 | | var print_node: PrintNode = .{ |
| 1854 | | .parent = parent_print_node, |
| 1855 | | .last = i == names.len - 1, |
| 1856 | | }; |
| 1857 | | try printPkgTreeChild(terminal, arena, job_queue, &print_node, name, dep.hash); |
| 1858 | | } |
| 1859 | | } |
| 1860 | | |
| 1861 | 1660 | fn cmdFetch(gpa: Allocator, graph: *Graph, args: []const []const u8) !void { |
| 1862 | 1661 | const environ_map = &graph.environ_map; |
| 1863 | 1662 | const io = graph.io; |
| ... | ... | @@ -2134,8 +1933,8 @@ fn cmdFetch(gpa: Allocator, graph: *Graph, args: []const []const u8) !void { |
| 2134 | 1933 | try ast.render(gpa, &aw.writer, fixups); |
| 2135 | 1934 | const rendered = aw.written(); |
| 2136 | 1935 | |
| 2137 | | build_root.directory.handle.writeFile(io, .{ .sub_path = Manifest.basename, .data = rendered }) catch |err| { |
| 2138 | | fatal("unable to write {s} file: {t}", .{ Manifest.basename, err }); |
| 1936 | build_root.directory.handle.writeFile(io, .{ .sub_path = Package.Manifest.basename, .data = rendered }) catch |err| { |
| 1937 | fatal("unable to write {s} file: {t}", .{ Package.Manifest.basename, err }); |
| 2139 | 1938 | }; |
| 2140 | 1939 | |
| 2141 | 1940 | return process.cleanExit(io); |
| ... | ... | @@ -2337,7 +2136,7 @@ fn cmdInit(gpa: Allocator, graph: *Graph, args: []const []const u8) !void { |
| 2337 | 2136 | const s = Dir.path.sep_str; |
| 2338 | 2137 | const template_paths = [_][]const u8{ |
| 2339 | 2138 | default_build_zig_basename, |
| 2340 | | Manifest.basename, |
| 2139 | Package.Manifest.basename, |
| 2341 | 2140 | "src" ++ s ++ "main.zig", |
| 2342 | 2141 | "src" ++ s ++ "root.zig", |
| 2343 | 2142 | }; |
| ... | ... | @@ -2361,7 +2160,7 @@ fn cmdInit(gpa: Allocator, graph: *Graph, args: []const []const u8) !void { |
| 2361 | 2160 | return process.cleanExit(io); |
| 2362 | 2161 | }, |
| 2363 | 2162 | .minimal => { |
| 2364 | | Templates.writeSimpleFile(io, Io.Dir.cwd(), Manifest.basename, |
| 2163 | Templates.writeSimpleFile(io, Io.Dir.cwd(), Package.Manifest.basename, |
| 2365 | 2164 | \\.{{ |
| 2366 | 2165 | \\ .name = .{s}, |
| 2367 | 2166 | \\ .version = "0.0.1", |
| ... | ... | @@ -2375,8 +2174,8 @@ fn cmdInit(gpa: Allocator, graph: *Graph, args: []const []const u8) !void { |
| 2375 | 2174 | builtin.zig_version_string, |
| 2376 | 2175 | fingerprint.int(), |
| 2377 | 2176 | }) catch |err| switch (err) { |
| 2378 | | else => fatal("failed to create {q}: {t}", .{ Manifest.basename, err }), |
| 2379 | | error.PathAlreadyExists => fatal("refusing to overwrite {q}", .{Manifest.basename}), |
| 2177 | else => fatal("failed to create {q}: {t}", .{ Package.Manifest.basename, err }), |
| 2178 | error.PathAlreadyExists => fatal("refusing to overwrite {q}", .{Package.Manifest.basename}), |
| 2380 | 2179 | }; |
| 2381 | 2180 | Templates.writeSimpleFile(io, Io.Dir.cwd(), default_build_zig_basename, |
| 2382 | 2181 | \\const std = @import("std"); |
| ... | ... | @@ -2391,12 +2190,12 @@ fn cmdInit(gpa: Allocator, graph: *Graph, args: []const []const u8) !void { |
| 2391 | 2190 | // their `build.zig.zon` *after* writing their `build.zig`. So this one isn't fatal. |
| 2392 | 2191 | error.PathAlreadyExists => { |
| 2393 | 2192 | log.info("successfully populated {q}, preserving existing {q}", .{ |
| 2394 | | Manifest.basename, default_build_zig_basename, |
| 2193 | Package.Manifest.basename, default_build_zig_basename, |
| 2395 | 2194 | }); |
| 2396 | 2195 | return process.cleanExit(io); |
| 2397 | 2196 | }, |
| 2398 | 2197 | }; |
| 2399 | | log.info("successfully populated {q} and {q}", .{ Manifest.basename, default_build_zig_basename }); |
| 2198 | log.info("successfully populated {q} and {q}", .{ Package.Manifest.basename, default_build_zig_basename }); |
| 2400 | 2199 | return process.cleanExit(io); |
| 2401 | 2200 | }, |
| 2402 | 2201 | } |
| ... | ... | @@ -3129,7 +2928,18 @@ fn printTreeStep( |
| 3129 | 2928 | .failures => make_step.state == .success, |
| 3130 | 2929 | }; |
| 3131 | 2930 | if (skip) return; |
| 3132 | | try parent_node.printPrefixedChild(writer, stderr.mode); |
| 2931 | try printPrefix(parent_node, stderr); |
| 2932 | |
| 2933 | if (parent_node.parent != null) { |
| 2934 | if (parent_node.last) { |
| 2935 | try printChildNodePrefix(stderr); |
| 2936 | } else { |
| 2937 | try writer.writeAll(switch (stderr.mode) { |
| 2938 | .escape_codes => "\x1B\x28\x30\x74\x71\x1B\x28\x42 ", // ├─ |
| 2939 | else => "+- ", |
| 2940 | }); |
| 2941 | } |
| 2942 | } |
| 3133 | 2943 | |
| 3134 | 2944 | if (!first) try stderr.setColor(.dim); |
| 3135 | 2945 | |
| ... | ... | @@ -3358,22 +3168,23 @@ fn printStepFailure( |
| 3358 | 3168 | } |
| 3359 | 3169 | } |
| 3360 | 3170 | |
| 3361 | | fn printTreeChild(writer: *Writer, mode: Io.Terminal.Mode) Writer.Error!void { |
| 3362 | | return writer.writeAll(switch (mode) { |
| 3363 | | .escape_codes => "\x1B\x28\x30\x74\x71\x1B\x28\x42 ", // ├─ |
| 3364 | | else => "+- ", |
| 3365 | | }); |
| 3366 | | } |
| 3367 | | |
| 3368 | | fn printTreeSibling(writer: *Writer, mode: Io.Terminal.Mode) Writer.Error!void { |
| 3369 | | return writer.writeAll(switch (mode) { |
| 3370 | | .escape_codes => "\x1B\x28\x30\x78\x1B\x28\x42 ", // │ |
| 3371 | | else => "| ", |
| 3372 | | }); |
| 3171 | fn printPrefix(node: *PrintNode, stderr: Io.Terminal) !void { |
| 3172 | const parent = node.parent orelse return; |
| 3173 | const writer = stderr.writer; |
| 3174 | if (parent.parent == null) return; |
| 3175 | try printPrefix(parent, stderr); |
| 3176 | if (parent.last) { |
| 3177 | try writer.writeAll(" "); |
| 3178 | } else { |
| 3179 | try writer.writeAll(switch (stderr.mode) { |
| 3180 | .escape_codes => "\x1B\x28\x30\x78\x1B\x28\x42 ", // │ |
| 3181 | else => "| ", |
| 3182 | }); |
| 3183 | } |
| 3373 | 3184 | } |
| 3374 | 3185 | |
| 3375 | | fn printTreeChildLast(writer: *Writer, mode: Io.Terminal.Mode) !void { |
| 3376 | | try writer.writeAll(switch (mode) { |
| 3186 | fn printChildNodePrefix(stderr: Io.Terminal) !void { |
| 3187 | try stderr.writer.writeAll(switch (stderr.mode) { |
| 3377 | 3188 | .escape_codes => "\x1B\x28\x30\x6d\x71\x1B\x28\x42 ", // └─ |
| 3378 | 3189 | else => "+- ", |
| 3379 | 3190 | }); |
| ... | ... | @@ -3467,7 +3278,7 @@ pub fn invalidateResult(maker: *Maker, step: *Step) error{MustReconfigure}!bool |
| 3467 | 3278 | pub fn printErrorMessages( |
| 3468 | 3279 | maker: *Maker, |
| 3469 | 3280 | failing_step_index: Configuration.Step.Index, |
| 3470 | | options: ErrorBundle.RenderOptions, |
| 3281 | options: std.zig.ErrorBundle.RenderOptions, |
| 3471 | 3282 | stderr: Io.Terminal, |
| 3472 | 3283 | error_style: ErrorStyle, |
| 3473 | 3284 | multiline_errors: MultilineErrors, |
| ... | ... | @@ -3493,7 +3304,7 @@ pub fn printErrorMessages( |
| 3493 | 3304 | while (step_stack.pop()) |step_index| : (indent += 1) { |
| 3494 | 3305 | if (indent > 0) { |
| 3495 | 3306 | try writer.splatByteAll(' ', (indent - 1) * 3); |
| 3496 | | try printTreeChildLast(writer, stderr.mode); |
| 3307 | try printChildNodePrefix(stderr); |
| 3497 | 3308 | } |
| 3498 | 3309 | |
| 3499 | 3310 | try writer.writeAll(step_index.ptr(c).name.slice(c)); |
| ... | ... | @@ -4227,9 +4038,7 @@ const FindBuildRootOptions = struct { |
| 4227 | 4038 | cwd_path: []const u8, |
| 4228 | 4039 | }; |
| 4229 | 4040 | |
| 4230 | | const FindBuildRootError = error{ OutOfMemory, BuildZigNotFound }; |
| 4231 | | |
| 4232 | | fn findBuildRoot(arena: Allocator, io: Io, options: FindBuildRootOptions) FindBuildRootError!BuildRoot { |
| 4041 | fn findBuildRoot(arena: Allocator, io: Io, options: FindBuildRootOptions) !BuildRoot { |
| 4233 | 4042 | const build_zig_basename = if (options.build_file) |bf| |
| 4234 | 4043 | Dir.path.basename(bf) |
| 4235 | 4044 | else |
| ... | ... | @@ -4280,12 +4089,11 @@ fn findBuildRoot(arena: Allocator, io: Io, options: FindBuildRootOptions) FindBu |
| 4280 | 4089 | dirname = Dir.path.dirname(dirname orelse options.cwd_path) orelse { |
| 4281 | 4090 | log.info("initialize {s} template file with \"zig init\"", .{std.zig.build_zig_basename}); |
| 4282 | 4091 | log.info("see \"zig --help\" for more options", .{}); |
| 4283 | | log.err("no build.zig file found, in the current directory or any parent directories", .{}); |
| 4284 | | return error.BuildZigNotFound; |
| 4092 | fatal("no build.zig file found, in the current directory or any parent directories", .{}); |
| 4285 | 4093 | }; |
| 4286 | 4094 | continue; |
| 4287 | 4095 | }, |
| 4288 | | else => |e| fatal("accessing {q} while searching for build.zig file failed: {t}", .{ joined_path, e }), |
| 4096 | else => |e| return e, |
| 4289 | 4097 | } |
| 4290 | 4098 | } |
| 4291 | 4099 | } |
| ... | ... | @@ -4293,8 +4101,8 @@ fn findBuildRoot(arena: Allocator, io: Io, options: FindBuildRootOptions) FindBu |
| 4293 | 4101 | const Fork = struct { |
| 4294 | 4102 | path: Path, |
| 4295 | 4103 | manifest_ast: std.zig.Ast, |
| 4296 | | manifest: Manifest, |
| 4297 | | error_bundle: ErrorBundle.Wip, |
| 4104 | manifest: Package.Manifest, |
| 4105 | error_bundle: std.zig.ErrorBundle.Wip, |
| 4298 | 4106 | failed: bool, |
| 4299 | 4107 | arena_allocator: std.heap.ArenaAllocator, |
| 4300 | 4108 | |
| ... | ... | @@ -4327,12 +4135,12 @@ const Fork = struct { |
| 4327 | 4135 | fork.arena_allocator = .init(gpa); |
| 4328 | 4136 | const arena = fork.arena_allocator.allocator(); |
| 4329 | 4137 | |
| 4330 | | var error_bundle: ErrorBundle.Wip = try .init(gpa); |
| 4138 | var error_bundle: std.zig.ErrorBundle.Wip = try .init(gpa); |
| 4331 | 4139 | defer error_bundle.deinit(); |
| 4332 | 4140 | |
| 4333 | | const manifest_path = try fork.path.join(arena, Manifest.basename); |
| 4141 | const manifest_path = try fork.path.join(arena, Package.Manifest.basename); |
| 4334 | 4142 | |
| 4335 | | Manifest.load( |
| 4143 | Package.Manifest.load( |
| 4336 | 4144 | io, |
| 4337 | 4145 | arena, |
| 4338 | 4146 | manifest_path, |
| ... | ... | @@ -4382,20 +4190,20 @@ fn loadManifest( |
| 4382 | 4190 | arena: Allocator, |
| 4383 | 4191 | io: Io, |
| 4384 | 4192 | options: LoadManifestOptions, |
| 4385 | | ) !struct { Manifest, std.zig.Ast } { |
| 4193 | ) !struct { Package.Manifest, std.zig.Ast } { |
| 4386 | 4194 | const rng: std.Random.IoSource = .{ .io = io }; |
| 4387 | 4195 | |
| 4388 | 4196 | const manifest_bytes = while (true) { |
| 4389 | 4197 | break options.dir.readFileAllocOptions( |
| 4390 | 4198 | io, |
| 4391 | | Manifest.basename, |
| 4199 | Package.Manifest.basename, |
| 4392 | 4200 | arena, |
| 4393 | | .limited(Manifest.max_bytes), |
| 4201 | .limited(Package.Manifest.max_bytes), |
| 4394 | 4202 | .@"1", |
| 4395 | 4203 | 0, |
| 4396 | 4204 | ) catch |err| switch (err) { |
| 4397 | 4205 | error.FileNotFound => { |
| 4398 | | Templates.writeSimpleFile(io, options.dir, Manifest.basename, |
| 4206 | Templates.writeSimpleFile(io, options.dir, Package.Manifest.basename, |
| 4399 | 4207 | \\.{{ |
| 4400 | 4208 | \\ .name = .{s}, |
| 4401 | 4209 | \\ .version = "0.0.1", |
| ... | ... | @@ -4409,29 +4217,29 @@ fn loadManifest( |
| 4409 | 4217 | builtin.zig_version_string, |
| 4410 | 4218 | Package.Fingerprint.generate(rng.interface(), options.root_name).int(), |
| 4411 | 4219 | }) catch |e| { |
| 4412 | | fatal("unable to write {s}: {t}", .{ Manifest.basename, e }); |
| 4220 | fatal("unable to write {s}: {t}", .{ Package.Manifest.basename, e }); |
| 4413 | 4221 | }; |
| 4414 | 4222 | continue; |
| 4415 | 4223 | }, |
| 4416 | | else => |e| fatal("unable to load {s}: {t}", .{ Manifest.basename, e }), |
| 4224 | else => |e| fatal("unable to load {s}: {t}", .{ Package.Manifest.basename, e }), |
| 4417 | 4225 | }; |
| 4418 | 4226 | }; |
| 4419 | 4227 | var ast = try std.zig.Ast.parse(gpa, manifest_bytes, .{ .mode = .zon }); |
| 4420 | 4228 | errdefer ast.deinit(gpa); |
| 4421 | 4229 | |
| 4422 | 4230 | if (ast.errors.len > 0) { |
| 4423 | | try std.zig.printAstErrorsToStderr(gpa, io, ast, Manifest.basename, options.color); |
| 4231 | try std.zig.printAstErrorsToStderr(gpa, io, ast, Package.Manifest.basename, options.color); |
| 4424 | 4232 | process.exit(2); |
| 4425 | 4233 | } |
| 4426 | 4234 | |
| 4427 | | var manifest = try Manifest.parse(gpa, &ast, rng.interface(), .{}); |
| 4235 | var manifest = try Package.Manifest.parse(gpa, &ast, rng.interface(), .{}); |
| 4428 | 4236 | errdefer manifest.deinit(gpa); |
| 4429 | 4237 | |
| 4430 | 4238 | if (manifest.errors.len > 0) { |
| 4431 | | var wip_errors: ErrorBundle.Wip = try .init(gpa); |
| 4239 | var wip_errors: std.zig.ErrorBundle.Wip = try .init(gpa); |
| 4432 | 4240 | defer wip_errors.deinit(); |
| 4433 | 4241 | |
| 4434 | | const src_path = try wip_errors.addString(Manifest.basename); |
| 4242 | const src_path = try wip_errors.addString(Package.Manifest.basename); |
| 4435 | 4243 | try manifest.copyErrorsIntoBundle(ast, src_path, &wip_errors); |
| 4436 | 4244 | |
| 4437 | 4245 | var error_bundle = try wip_errors.toOwnedBundle(""); |
| ... | ... | @@ -4455,8 +4263,8 @@ fn sanitizeExampleName(arena: Allocator, bytes: []const u8) error{OutOfMemory}![ |
| 4455 | 4263 | else => continue, |
| 4456 | 4264 | }; |
| 4457 | 4265 | if (!std.zig.isValidId(result.items)) return "foo"; |
| 4458 | | if (result.items.len > Manifest.max_name_len) |
| 4459 | | result.shrinkRetainingCapacity(Manifest.max_name_len); |
| 4266 | if (result.items.len > Package.Manifest.max_name_len) |
| 4267 | result.shrinkRetainingCapacity(Package.Manifest.max_name_len); |
| 4460 | 4268 | |
| 4461 | 4269 | return result.toOwnedSlice(arena); |
| 4462 | 4270 | } |