Skip to content

Commit

Permalink
Merge pull request #77 from semgrep/martin/upgrade-tree-sitter
Browse files Browse the repository at this point in the history
Upgrade to tree-sitter 0.22.6
  • Loading branch information
mjambon authored Jun 19, 2024
2 parents b7d8468 + fe3f385 commit c085bc5
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 1 deletion.
53 changes: 53 additions & 0 deletions patch/tree-sitter-0.22.6/Makefile.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
--- ../../downloads/tree-sitter-0.22.6/Makefile.orig 2024-05-05 13:47:18.000000000 -0700
+++ ../../downloads/tree-sitter-0.22.6/Makefile 2024-06-18 19:52:35.772310737 -0700
@@ -8,12 +8,12 @@

# collect sources
ifneq ($(AMALGAMATED),1)
- SRC := $(wildcard lib/src/*.c)
- # do not double-include amalgamation
- SRC := $(filter-out lib/src/lib.c,$(SRC))
+ SRC := $(wildcard lib/src/*.c)
+ # do not double-include amalgamation
+ SRC := $(filter-out lib/src/lib.c,$(SRC))
else
- # use amalgamated build
- SRC := lib/src/lib.c
+ # use amalgamated build
+ SRC := lib/src/lib.c
endif
OBJ := $(SRC:.c=.o)

@@ -28,21 +28,20 @@
SONAME_MINOR := $(word 2,$(subst ., ,$(VERSION)))

# OS-specific bits
-ifeq ($(OS),Windows_NT)
- $(error "Windows is not supported")
-else ifeq ($(shell uname),Darwin)
- SOEXT = dylib
- SOEXTVER_MAJOR = $(SONAME_MAJOR).dylib
- SOEXTVER = $(SONAME_MAJOR).$(SONAME_MINOR).dylib
- LINKSHARED += -dynamiclib -Wl,-install_name,$(LIBDIR)/libtree-sitter.$(SONAME_MAJOR).dylib
+
+ifeq ($(shell uname),Darwin)
+ SOEXT = dylib
+ SOEXTVER_MAJOR = $(SONAME_MAJOR).dylib
+ SOEXTVER = $(SONAME_MAJOR).$(SONAME_MINOR).dylib
+ LINKSHARED += -dynamiclib -Wl,-install_name,$(LIBDIR)/libtree-sitter.$(SONAME_MAJOR).dylib
else
- SOEXT = so
- SOEXTVER_MAJOR = so.$(SONAME_MAJOR)
- SOEXTVER = so.$(SONAME_MAJOR).$(SONAME_MINOR)
- LINKSHARED += -shared -Wl,-soname,libtree-sitter.so.$(SONAME_MAJOR)
+ SOEXT = so
+ SOEXTVER_MAJOR = so.$(SONAME_MAJOR)
+ SOEXTVER = so.$(SONAME_MAJOR).$(SONAME_MINOR)
+ LINKSHARED += -shared -Wl,-soname,libtree-sitter.so.$(SONAME_MAJOR)
endif
ifneq ($(filter $(shell uname),FreeBSD NetBSD DragonFly),)
- PCLIBDIR := $(PREFIX)/libdata/pkgconfig
+ PCLIBDIR := $(PREFIX)/libdata/pkgconfig
endif

all: libtree-sitter.a libtree-sitter.$(SOEXT) tree-sitter.pc
20 changes: 19 additions & 1 deletion scripts/download-tree-sitter
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ prog_name=$(basename "$0")
# The official version of tree-sitter we use for the code generator and
# for the runtime library. Please try to keep this as the single source
# of truth.
default_version="0.20.6"
default_version="0.22.6"

error() {
echo "Current directory: $(pwd)" >&2
Expand Down Expand Up @@ -87,5 +87,23 @@ EOF
if [[ ! -d "$src_dir" ]]; then
error "Archive didn't unpack into the expected folder '$src_dir'."
fi

case "$version" in
0.20.6)
;;
0.22.6)
# See https://github.com/tree-sitter/tree-sitter/pull/3417
# regarding Windows/Cygwin support
patch --backup \
tree-sitter-0.22.6/Makefile \
../patch/tree-sitter-0.22.6/Makefile.patch
;;
*)
cat >&2 <<EOF
*** tree-sitter version: $version
*** Warning: tree-sitter 0.22.6 required patching the Makefile!
*** Remove this code once we're fully migrated to a version > 0.22.6
EOF
esac
fi
)
10 changes: 10 additions & 0 deletions scripts/ocaml-tree-sitter-gen-c
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,16 @@ else
# This mechanism is used with languages whose base grammar is defined
# in a tree-sitter-* submodule.

# tree-sitter 0.22.6 creates a dummy 'grammar.js' file if
# there isn't one already. This creates confusing situations
# because our input grammar as created by ocaml-tree-sitter is
# 'src/grammar.json', not the usual 'grammar.js'. Creating our
# own unparseable 'grammar.js' is a protection against using
# the wrong grammar.
# Tracked at https://github.com/tree-sitter/tree-sitter/issues/3415
echo "..... not the input grammar! Use 'tree-sitter generate src/grammar.json'" \
> grammar.js

orig_grammar_json="$import_from"/src/grammar.json
if [[ ! -e "$orig_grammar_json" ]]; then
cat >&2 <<EOF
Expand Down

0 comments on commit c085bc5

Please sign in to comment.