mirror of
https://codeberg.org/ziglang/zig.git
synced 2025-12-06 05:44:20 +00:00
Merge pull request #24090 from fardragon/handle-empty-hash
zig build: Handle empty hashes in build.zig.zon
This commit is contained in:
commit
e96d86064e
2 changed files with 10 additions and 3 deletions
|
|
@ -66,10 +66,11 @@ pub const Hash = struct {
|
|||
|
||||
pub fn toSlice(ph: *const Hash) []const u8 {
|
||||
var end: usize = ph.bytes.len;
|
||||
while (true) {
|
||||
while (end > 0) {
|
||||
end -= 1;
|
||||
if (ph.bytes[end] != 0) return ph.bytes[0 .. end + 1];
|
||||
}
|
||||
return ph.bytes[0..0];
|
||||
}
|
||||
|
||||
pub fn eql(a: *const Hash, b: *const Hash) bool {
|
||||
|
|
@ -195,6 +196,11 @@ test Hash {
|
|||
try std.testing.expectEqualStrings("nasm-2.16.1-3-vrr-ygAAoADH9XG3tOdvPNuHen_d-XeHndOG-nNXmved", result.toSlice());
|
||||
}
|
||||
|
||||
test "empty hash" {
|
||||
const hash = Hash.fromSlice("");
|
||||
try std.testing.expectEqualStrings("", hash.toSlice());
|
||||
}
|
||||
|
||||
test {
|
||||
_ = Fetch;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -568,14 +568,14 @@ fn runResource(
|
|||
const actual_hex = Package.multiHashHexDigest(f.computed_hash.digest);
|
||||
if (!std.mem.eql(u8, declared_hash.toSlice(), &actual_hex)) {
|
||||
return f.fail(hash_tok, try eb.printString(
|
||||
"hash mismatch: manifest declares {s} but the fetched package has {s}",
|
||||
"hash mismatch: manifest declares '{s}' but the fetched package has '{s}'",
|
||||
.{ declared_hash.toSlice(), actual_hex },
|
||||
));
|
||||
}
|
||||
} else {
|
||||
if (!computed_package_hash.eql(&declared_hash)) {
|
||||
return f.fail(hash_tok, try eb.printString(
|
||||
"hash mismatch: manifest declares {s} but the fetched package has {s}",
|
||||
"hash mismatch: manifest declares '{s}' but the fetched package has '{s}'",
|
||||
.{ declared_hash.toSlice(), computed_package_hash.toSlice() },
|
||||
));
|
||||
}
|
||||
|
|
@ -726,6 +726,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…
Add table
Reference in a new issue