| ... | ... | @@ -5098,6 +5098,7 @@ fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !void { |
| 5098 | 5098 | .job_queue = &job_queue, |
| 5099 | 5099 | .omit_missing_hash_error = true, |
| 5100 | 5100 | .allow_missing_paths_field = false, |
| 5101 | .use_latest_commit = false, |
| 5101 | 5102 | |
| 5102 | 5103 | .package_root = undefined, |
| 5103 | 5104 | .error_bundle = undefined, |
| ... | ... | @@ -5106,6 +5107,7 @@ fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !void { |
| 5106 | 5107 | .actual_hash = undefined, |
| 5107 | 5108 | .has_build_zig = true, |
| 5108 | 5109 | .oom_flag = false, |
| 5110 | .latest_commit = undefined, |
| 5109 | 5111 | |
| 5110 | 5112 | .module = build_mod, |
| 5111 | 5113 | }; |
| ... | ... | @@ -6757,6 +6759,7 @@ const usage_fetch = |
| 6757 | 6759 | \\ --debug-hash Print verbose hash information to stdout |
| 6758 | 6760 | \\ --save Add the fetched package to build.zig.zon |
| 6759 | 6761 | \\ --save=[name] Add the fetched package to build.zig.zon as name |
| 6762 | \\ --resolve-commit Before saving, replace the name of a Git branch/tag with its commit SHA |
| 6760 | 6763 | \\ |
| 6761 | 6764 | ; |
| 6762 | 6765 | |
| ... | ... | @@ -6772,6 +6775,7 @@ fn cmdFetch( |
| 6772 | 6775 | var override_global_cache_dir: ?[]const u8 = try EnvVar.ZIG_GLOBAL_CACHE_DIR.get(arena); |
| 6773 | 6776 | var debug_hash: bool = false; |
| 6774 | 6777 | var save: union(enum) { no, yes, name: []const u8 } = .no; |
| 6778 | var resolve_commit: bool = false; |
| 6775 | 6779 | |
| 6776 | 6780 | { |
| 6777 | 6781 | var i: usize = 0; |
| ... | ... | @@ -6792,6 +6796,8 @@ fn cmdFetch( |
| 6792 | 6796 | save = .yes; |
| 6793 | 6797 | } else if (mem.startsWith(u8, arg, "--save=")) { |
| 6794 | 6798 | save = .{ .name = arg["--save=".len..] }; |
| 6799 | } else if (mem.eql(u8, arg, "--resolve-commit")) { |
| 6800 | resolve_commit = true; |
| 6795 | 6801 | } else { |
| 6796 | 6802 | fatal("unrecognized parameter: '{s}'", .{arg}); |
| 6797 | 6803 | } |
| ... | ... | @@ -6803,6 +6809,9 @@ fn cmdFetch( |
| 6803 | 6809 | } |
| 6804 | 6810 | } |
| 6805 | 6811 | |
| 6812 | if (resolve_commit and save == .no) |
| 6813 | warn("'--resolve-commit' has no effect unless used with '--save'", .{}); |
| 6814 | |
| 6806 | 6815 | const path_or_url = opt_path_or_url orelse fatal("missing url or path parameter", .{}); |
| 6807 | 6816 | |
| 6808 | 6817 | var thread_pool: ThreadPool = undefined; |
| ... | ... | @@ -6851,6 +6860,7 @@ fn cmdFetch( |
| 6851 | 6860 | .job_queue = &job_queue, |
| 6852 | 6861 | .omit_missing_hash_error = true, |
| 6853 | 6862 | .allow_missing_paths_field = false, |
| 6863 | .use_latest_commit = resolve_commit, |
| 6854 | 6864 | |
| 6855 | 6865 | .package_root = undefined, |
| 6856 | 6866 | .error_bundle = undefined, |
| ... | ... | @@ -6859,6 +6869,7 @@ fn cmdFetch( |
| 6859 | 6869 | .actual_hash = undefined, |
| 6860 | 6870 | .has_build_zig = false, |
| 6861 | 6871 | .oom_flag = false, |
| 6872 | .latest_commit = undefined, |
| 6862 | 6873 | |
| 6863 | 6874 | .module = null, |
| 6864 | 6875 | }; |
| ... | ... | @@ -6915,13 +6926,22 @@ fn cmdFetch( |
| 6915 | 6926 | var fixups: Ast.Fixups = .{}; |
| 6916 | 6927 | defer fixups.deinit(gpa); |
| 6917 | 6928 | |
| 6929 | const saved_path_or_url = if (resolve_commit) blk: { |
| 6930 | // replace the refspec with the latest commit SHA |
| 6931 | var uri = try std.Uri.parse(path_or_url); |
| 6932 | uri.fragment = try std.fmt.allocPrint(arena, "{}", .{ |
| 6933 | std.fmt.fmtSliceHexLower(&fetch.latest_commit.?), |
| 6934 | }); |
| 6935 | break :blk try std.fmt.allocPrint(arena, "{}", .{uri}); |
| 6936 | } else path_or_url; |
| 6937 | |
| 6918 | 6938 | const new_node_init = try std.fmt.allocPrint(arena, |
| 6919 | 6939 | \\.{{ |
| 6920 | 6940 | \\ .url = "{}", |
| 6921 | 6941 | \\ .hash = "{}", |
| 6922 | 6942 | \\ }} |
| 6923 | 6943 | , .{ |
| 6924 | | std.zig.fmtEscapes(path_or_url), |
| 6944 | std.zig.fmtEscapes(saved_path_or_url), |
| 6925 | 6945 | std.zig.fmtEscapes(&hex_digest), |
| 6926 | 6946 | }); |
| 6927 | 6947 | |