Skip to content

Commit ba30742

Browse files
committed
fix(zigfetch): manifest name is enum literal now
1 parent 0f754be commit ba30742

File tree

5 files changed

+42
-18
lines changed

5 files changed

+42
-18
lines changed

.github/zigfetch.sh

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,24 @@
22

33
script_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")" &>/dev/null && pwd -P)
44

5-
pkg=https://github.com/jiacai2050/zig-curl/archive/c8e2f43f8f042f52373c86043ec16b0f2c3388a2.tar.gz
5+
check_hash() {
6+
local pkg="$1"
7+
local expected="$2"
68

7-
zig fetch --debug-hash "${pkg}"
8-
"${script_dir}/../zig-out/bin/zigfetch" "${pkg}"
9+
# zig fetch --debug-hash "${pkg}"
10+
# "${script_dir}/../zig-out/bin/zigfetch" "${pkg}"
11+
local actual=$("${script_dir}/../zig-out/bin/zigfetch" "${pkg}" 2>&1 | tail -1)
912

10-
actual=$("${script_dir}/../zig-out/bin/zigfetch" "${pkg}" 2>&1 | tail -1)
11-
expected="1220e9b279355ce92cd217684a2449bd8024274eb3fc09a576deb33ca1733b9f0a1f"
12-
if [ "${actual}" != "${expected}" ];then
13-
echo "Expected: ${expected}, actual:${actual}"
14-
exit 1
15-
fi
13+
if [ "${actual}" != "${expected}" ]; then
14+
echo "Wrong case: ${pkg}.\nExpected: ${expected}, actual: ${actual}"
15+
return 1
16+
fi
17+
18+
return 0
19+
}
20+
21+
# For zig 0.13.0
22+
check_hash "https://github.com/jiacai2050/zig-curl/archive/c8e2f43f8f042f52373c86043ec16b0f2c3388a2.tar.gz" 1220e9b279355ce92cd217684a2449bd8024274eb3fc09a576deb33ca1733b9f0a1f
23+
24+
# For zig 0.14.0
25+
check_hash "https://github.com/jiacai2050/zig-curl/archive/refs/tags/v0.1.0.tar.gz" 122057495ccd5029387615e6786a56626a88cd39614b4ebeb0bf559989c16fe47a3f

docs/content/_index.org

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
#+TITLE: Introduction
22
#+DATE: 2023-10-21T12:09:48+0800
3-
#+LASTMOD: 2025-03-09T10:58:47+0800
3+
#+LASTMOD: 2025-03-09T16:51:07+0800
44
#+TYPE: docs
55
#+author: Jiacai Liu
66

77
[[https://github.com/jiacai2050/zigcli][https://img.shields.io/github/stars/jiacai2050/zigcli.svg]]
88
[[https://github.com/jiacai2050/loc/actions/workflows/CI.yml][https://github.com/jiacai2050/loc/actions/workflows/CI.yml/badge.svg]]
99
[[https://github.com/jiacai2050/loc/actions/workflows/binary.yml][https://github.com/jiacai2050/loc/actions/workflows/release.yml/badge.svg]]
10-
[[https://img.shields.io/badge/zig%20version-0.13.0-blue.svg]]
10+
[[https://img.shields.io/badge/zig%20version-0.14.0-blue.svg]]
1111

1212
#+begin_quote
1313
[[https://zigcli.liujiacai.net/][Zigcli]] is a toolkit for building command line programs in Zig.

docs/content/install.org

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#+TITLE: Install
22
#+DATE: 2025-01-02T23:20:23+0800
3-
#+LASTMOD: 2025-01-02T23:21:04+0800
3+
#+LASTMOD: 2025-03-09T16:51:26+0800
44
#+TYPE: docs
55
#+WEIGHT: 10
66
#+AUTHOR: Jiacai Liu
@@ -27,7 +27,7 @@ The latest pre-built binaries are available on the [[https://github.com/jiacai20
2727
#+begin_src bash
2828
git clone https://github.com/jiacai2050/zigcli.git
2929
#+end_src
30-
Then build with zig 0.13.0
30+
Then build with zig 0.14.0
3131
#+begin_src bash
3232
make build
3333
#+end_src

src/bin/pkg/Manifest.zig

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ const Parse = struct {
232232
have_included_paths = true;
233233
try parseIncludedPaths(p, field_init);
234234
} else if (mem.eql(u8, field_name, "name")) {
235-
p.name = try parseString(p, field_init);
235+
p.name = try parseName(p, field_init);
236236
have_name = true;
237237
} else if (mem.eql(u8, field_name, "version")) {
238238
p.version_node = field_init;
@@ -402,6 +402,24 @@ const Parse = struct {
402402
}
403403
}
404404

405+
fn parseName(p: *Parse, node: Ast.Node.Index) ![]const u8 {
406+
const ast = p.ast;
407+
const node_tags = ast.nodes.items(.tag);
408+
const main_tokens = ast.nodes.items(.main_token);
409+
const main_token = main_tokens[node];
410+
411+
if (node_tags[node] == .enum_literal) {
412+
const ident_name = ast.tokenSlice(main_token);
413+
if (mem.startsWith(u8, ident_name, "@"))
414+
return fail(p, main_token, "name must be a valid bare zig identifier", .{});
415+
416+
return ident_name;
417+
}
418+
419+
// try string name, used before zig 0.14.
420+
return p.parseString(node);
421+
}
422+
405423
fn parseString(p: *Parse, node: Ast.Node.Index) ![]const u8 {
406424
const ast = p.ast;
407425
const node_tags = ast.nodes.items(.tag);

src/bin/zigfetch.zig

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,6 @@ fn calcHash(allocator: Allocator, dir: fs.Dir, root_dirname: []const u8, deleteI
102102
var manifest = try loadManifest(allocator, dir);
103103
defer if (manifest) |*m| m.deinit(allocator);
104104

105-
if (args.verbose) {
106-
log.info("manifest = {any}", .{manifest});
107-
}
108-
109105
const filter: Filter = .{
110106
.include_paths = if (manifest) |m| m.paths else .{},
111107
};

0 commit comments

Comments
 (0)