mirror of
https://github.com/ziglang/zig.git
synced 2026-02-12 20:37:54 +00:00
Handle empty hashes in build.zig.zon
This commit is contained in:
parent
b6d9046242
commit
3c151f0b1c
@ -67,6 +67,7 @@ pub const Hash = struct {
|
||||
pub fn toSlice(ph: *const Hash) []const u8 {
|
||||
var end: usize = ph.bytes.len;
|
||||
while (true) {
|
||||
if (end == 0) return &.{};
|
||||
end -= 1;
|
||||
if (ph.bytes[end] != 0) return ph.bytes[0 .. end + 1];
|
||||
}
|
||||
@ -195,6 +196,11 @@ test Hash {
|
||||
try std.testing.expectEqualStrings("nasm-2.16.1-3-vrr-ygAAoADH9XG3tOdvPNuHen_d-XeHndOG-nNXmved", result.toSlice());
|
||||
}
|
||||
|
||||
test "EmptyHash" {
|
||||
const hash = Hash.fromSlice("");
|
||||
try std.testing.expectEqualStrings("", hash.toSlice());
|
||||
}
|
||||
|
||||
test {
|
||||
_ = Fetch;
|
||||
}
|
||||
|
||||
@ -567,16 +567,18 @@ fn runResource(
|
||||
if (declared_hash.isOld()) {
|
||||
const actual_hex = Package.multiHashHexDigest(f.computed_hash.digest);
|
||||
if (!std.mem.eql(u8, declared_hash.toSlice(), &actual_hex)) {
|
||||
const declared = if (declared_hash.toSlice().len > 0) declared_hash.toSlice() else "<empty>";
|
||||
return f.fail(hash_tok, try eb.printString(
|
||||
"hash mismatch: manifest declares {s} but the fetched package has {s}",
|
||||
.{ declared_hash.toSlice(), actual_hex },
|
||||
.{ declared, actual_hex },
|
||||
));
|
||||
}
|
||||
} else {
|
||||
if (!computed_package_hash.eql(&declared_hash)) {
|
||||
const declared = if (declared_hash.toSlice().len > 0) declared_hash.toSlice() else "<empty>";
|
||||
return f.fail(hash_tok, try eb.printString(
|
||||
"hash mismatch: manifest declares {s} but the fetched package has {s}",
|
||||
.{ declared_hash.toSlice(), computed_package_hash.toSlice() },
|
||||
.{ declared, computed_package_hash.toSlice() },
|
||||
));
|
||||
}
|
||||
}
|
||||
@ -726,6 +728,7 @@ fn queueJobsForDeps(f: *Fetch) RunError!void {
|
||||
.hash = h: {
|
||||
const h = dep.hash orelse break :h null;
|
||||
const pkg_hash: Package.Hash = .fromSlice(h);
|
||||
if (h.len == 0) break :h pkg_hash;
|
||||
const gop = f.job_queue.table.getOrPutAssumeCapacity(pkg_hash);
|
||||
if (gop.found_existing) {
|
||||
if (!dep.lazy) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user