Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fetch: Keep .lazy = true #19816

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/Package/Manifest.zig
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ pub const MultiHashHexDigest = [multihash_hex_digest_len]u8;
pub const Dependency = struct {
location: Location,
location_tok: Ast.TokenIndex,
location_node: Ast.Node.Index,
hash: ?[]const u8,
hash_tok: Ast.TokenIndex,
hash_node: Ast.Node.Index,
node: Ast.Node.Index,
name_tok: Ast.TokenIndex,
lazy: bool,
Expand Down Expand Up @@ -302,8 +304,10 @@ const Parse = struct {
var dep: Dependency = .{
.location = undefined,
.location_tok = 0,
.location_node = undefined,
.hash = null,
.hash_tok = 0,
.hash_node = undefined,
.node = node,
.name_tok = 0,
.lazy = false,
Expand All @@ -329,6 +333,7 @@ const Parse = struct {
};
has_location = true;
dep.location_tok = main_tokens[field_init];
dep.location_node = field_init;
} else if (mem.eql(u8, field_name, "path")) {
if (has_location) {
return fail(p, main_tokens[field_init], "dependency should specify only one of 'url' and 'path' fields.", .{});
Expand All @@ -341,12 +346,14 @@ const Parse = struct {
};
has_location = true;
dep.location_tok = main_tokens[field_init];
dep.location_node = field_init;
} else if (mem.eql(u8, field_name, "hash")) {
dep.hash = parseHash(p, field_init) catch |err| switch (err) {
error.ParseFailure => continue,
else => |e| return e,
};
dep.hash_tok = main_tokens[field_init];
dep.hash_node = field_init;
} else if (mem.eql(u8, field_name, "lazy")) {
dep.lazy = parseBool(p, field_init) catch |err| switch (err) {
error.ParseFailure => continue,
Expand Down
15 changes: 14 additions & 1 deletion src/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -7130,8 +7130,21 @@ fn cmdFetch(
.path => {},
}
}

const location_replace = try std.fmt.allocPrint(
arena,
"\"{}\"",
.{std.zig.fmtEscapes(path_or_url)},
);
const hash_replace = try std.fmt.allocPrint(
arena,
"\"{}\"",
.{std.zig.fmtEscapes(&hex_digest)},
);

warn("overwriting existing dependency named '{s}'", .{name});
try fixups.replace_nodes_with_string.put(gpa, dep.node, new_node_init);
try fixups.replace_nodes_with_string.put(gpa, dep.location_node, location_replace);
try fixups.replace_nodes_with_string.put(gpa, dep.hash_node, hash_replace);
} else if (manifest.dependencies.count() > 0) {
// Add fixup for adding another dependency.
const deps = manifest.dependencies.values();
Expand Down