diff options
Diffstat (limited to 'Scripts/update-parser.sh')
| -rwxr-xr-x | Scripts/update-parser.sh | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/Scripts/update-parser.sh b/Scripts/update-parser.sh new file mode 100755 index 0000000..f4fab95 --- /dev/null +++ b/Scripts/update-parser.sh | |||
| @@ -0,0 +1,64 @@ | |||
| 1 | #!/bin/sh | ||
| 2 | # | ||
| 3 | # update-parser.sh — Bump vendored tree-sitter-zig and rebuild the dylib. | ||
| 4 | # | ||
| 5 | # Purpose: | ||
| 6 | # Refresh the vendored snapshot under vendor/tree-sitter-zig/ to a newer | ||
| 7 | # upstream commit, update VENDORING.md, and rebuild the parser dylib. | ||
| 8 | # | ||
| 9 | # What it does: | ||
| 10 | # - clones tree-sitter-grammars/tree-sitter-zig into a temp dir | ||
| 11 | # - checks out the requested ref (default: HEAD of the default branch) | ||
| 12 | # - exits early if the upstream SHA matches the pinned SHA | ||
| 13 | # - replaces src/, queries/, grammar.js, tree-sitter.json, LICENSE | ||
| 14 | # with the upstream copies; leaves VENDORING.md and README.upstream.md | ||
| 15 | # untouched | ||
| 16 | # - rewrites the "Pinned commit:" line in VENDORING.md | ||
| 17 | # - invokes build-parser.sh to rebuild Syntaxes/libtree-sitter-zig.dylib | ||
| 18 | # - prints a GitHub compare link for the diff | ||
| 19 | # | ||
| 20 | # Usage: | ||
| 21 | # ./Scripts/update-parser.sh # bump to upstream HEAD | ||
| 22 | # ./Scripts/update-parser.sh <ref> # bump to a tag, branch, or SHA | ||
| 23 | # | ||
| 24 | # Caveats: | ||
| 25 | # - any local edits inside the listed paths are overwritten — review | ||
| 26 | # `git diff vendor/` afterwards before committing | ||
| 27 | # - parses VENDORING.md by an exact "Pinned commit: <sha>" line prefix; | ||
| 28 | # keep that line format intact | ||
| 29 | # | ||
| 30 | # Requirements: | ||
| 31 | # git, plus everything build-parser.sh needs. | ||
| 32 | |||
| 33 | set -eu | ||
| 34 | |||
| 35 | ROOT="$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd)" | ||
| 36 | VENDOR_DIR="$ROOT/vendor/tree-sitter-zig" | ||
| 37 | UPSTREAM="https://github.com/tree-sitter-grammars/tree-sitter-zig.git" | ||
| 38 | REF="${1:-HEAD}" | ||
| 39 | |||
| 40 | TMP="$(mktemp -d)" | ||
| 41 | trap 'rm -rf "$TMP"' EXIT | ||
| 42 | |||
| 43 | git clone --quiet "$UPSTREAM" "$TMP/repo" | ||
| 44 | git -C "$TMP/repo" checkout --quiet "$REF" | ||
| 45 | SHA="$(git -C "$TMP/repo" rev-parse HEAD)" | ||
| 46 | |||
| 47 | OLD_SHA="$(awk '/^Pinned commit:/ {print $3}' "$VENDOR_DIR/VENDORING.md")" | ||
| 48 | if [ "$SHA" = "$OLD_SHA" ]; then | ||
| 49 | echo "Already at $SHA — nothing to do." | ||
| 50 | exit 0 | ||
| 51 | fi | ||
| 52 | |||
| 53 | for path in src queries grammar.js tree-sitter.json LICENSE; do | ||
| 54 | rm -rf "$VENDOR_DIR/$path" | ||
| 55 | cp -R "$TMP/repo/$path" "$VENDOR_DIR/$path" | ||
| 56 | done | ||
| 57 | |||
| 58 | sed -i.bak "s/^Pinned commit: .*/Pinned commit: $SHA/" "$VENDOR_DIR/VENDORING.md" | ||
| 59 | rm "$VENDOR_DIR/VENDORING.md.bak" | ||
| 60 | |||
| 61 | "$ROOT/Scripts/build-parser.sh" | ||
| 62 | |||
| 63 | echo "Updated $OLD_SHA -> $SHA" | ||
| 64 | echo "Compare: https://github.com/tree-sitter-grammars/tree-sitter-zig/compare/$OLD_SHA...$SHA" | ||
