Fix admin/notes/tree-sitter/build-module/build.sh (bug#59789)

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.
This commit is contained in:
Yuan Fu 2022-12-06 15:55:14 -08:00
parent cc63c08697
commit 6acf95cbea
No known key found for this signature in database
GPG key ID: 56E19BC57664A442
2 changed files with 31 additions and 26 deletions

View file

@ -12,6 +12,7 @@ languages=(
'python'
'rust'
'typescript'
'tsx'
)
for language in "${languages[@]}"

View file

@ -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.
### Copy out
if [ "${lang}" == "typescript" ]
then
cp "libtree-sitter-${lang}.${soext}" ..
cd ..
fi
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}"