]> git.eshelyaron.com Git - emacs.git/commitdiff
Fix admin/notes/tree-sitter/build-module/build.sh (bug#59789)
authorYuan Fu <casouri@gmail.com>
Tue, 6 Dec 2022 23:55:14 +0000 (15:55 -0800)
committerYuan Fu <casouri@gmail.com>
Wed, 7 Dec 2022 00:11:35 +0000 (16:11 -0800)
Besides the problem mentioned by Juri, which is fixed by removing

-cp tree-sitter-lang.in "tree-sitter-${lang}/src"
-cp emacs-module.h "tree-sitter-${lang}/src"

(we removed those files in an earlier commit, because they are not
used anymore.)

Now it also more parameterized and builds typescript and tsx
separately.

* admin/notes/tree-sitter/build-module/build.sh (topdir)
(repo, sourcedir, grammardir): New variables.
(Build): Make it parametric.
(Copy out): Use absolute path.

* admin/notes/tree-sitter/build-module/batch.sh (languages): Add tsx.

admin/notes/tree-sitter/build-module/batch.sh
admin/notes/tree-sitter/build-module/build.sh

index deed18978a196d02f4a8c750f5cce835258e54a0..d45f37f4b648fffd100ce721b30ab7dc23d9938f 100755 (executable)
@@ -12,6 +12,7 @@ languages=(
     'python'
     'rust'
     'typescript'
+    'tsx'
 )
 
 for language in "${languages[@]}"
index 102ab310fa04e7aed84522ec591d14e6c8724fd3..a71ccaa4edbc6655fce217c139119755641afef5 100755 (executable)
@@ -1,6 +1,7 @@
 #!/bin/bash
 
 lang=$1
+topdir="$PWD"
 
 if [ $(uname) == "Darwin" ]
 then
@@ -11,24 +12,33 @@ fi
 
 echo "Building ${lang}"
 
-# Retrieve sources.
-git clone "https://github.com/tree-sitter/tree-sitter-${lang}.git" \
+### Retrieve sources
+
+repo="tree-sitter-${lang}"
+sourcedir="tree-sitter-${lang}/src"
+grammardir="tree-sitter-${lang}"
+
+case "${lang}" in
+    "typescript")
+        sourcedir="tree-sitter-typescript/typescript/src"
+        grammardir="tree-sitter-typescript/typescript"
+        ;;
+    "tsx")
+        repo="tree-sitter-typescript"
+        sourcedir="tree-sitter-typescript/tsx/src"
+        grammardir="tree-sitter-typescript/tsx"
+        ;;
+esac
+
+git clone "https://github.com/tree-sitter/${repo}.git" \
     --depth 1 --quiet
-if [ "${lang}" == "typescript" ]
-then
-    lang="typescript/tsx"
-fi
-cp tree-sitter-lang.in "tree-sitter-${lang}/src"
-cp emacs-module.h "tree-sitter-${lang}/src"
-cp "tree-sitter-${lang}/grammar.js" "tree-sitter-${lang}/src"
-cd "tree-sitter-${lang}/src"
+cp "${grammardir}"/grammar.js "${sourcedir}"
+# We have to go into the source directory to compile, because some
+# C files referes to files like "../../common/scanner.h".
+cd "${sourcedir}"
 
-if [ "${lang}" == "typescript/tsx" ]
-then
-    lang="tsx"
-fi
+### Build
 
-# Build.
 cc -c -I. parser.c
 # Compile scanner.c.
 if test -f scanner.c
@@ -48,15 +58,9 @@ else
     cc -fPIC -shared *.o -o "libtree-sitter-${lang}.${soext}"
 fi
 
-# Copy out.
-
-if [ "${lang}" == "typescript" ]
-then
-    cp "libtree-sitter-${lang}.${soext}" ..
-    cd ..
-fi
+### Copy out
 
-mkdir -p ../../dist
-cp "libtree-sitter-${lang}.${soext}" ../../dist
-cd ../../
-rm -rf "tree-sitter-${lang}"
+mkdir -p "${topdir}/dist"
+cp "libtree-sitter-${lang}.${soext}" "${topdir}/dist"
+cd "${topdir}"
+rm -rf "${repo}"