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' 'python'
'rust' 'rust'
'typescript' 'typescript'
'tsx'
) )
for language in "${languages[@]}" for language in "${languages[@]}"

View file

@ -1,6 +1,7 @@
#!/bin/bash #!/bin/bash
lang=$1 lang=$1
topdir="$PWD"
if [ $(uname) == "Darwin" ] if [ $(uname) == "Darwin" ]
then then
@ -11,24 +12,33 @@ fi
echo "Building ${lang}" echo "Building ${lang}"
# Retrieve sources. ### Retrieve sources
git clone "https://github.com/tree-sitter/tree-sitter-${lang}.git" \
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 --depth 1 --quiet
if [ "${lang}" == "typescript" ] cp "${grammardir}"/grammar.js "${sourcedir}"
then # We have to go into the source directory to compile, because some
lang="typescript/tsx" # C files referes to files like "../../common/scanner.h".
fi cd "${sourcedir}"
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"
if [ "${lang}" == "typescript/tsx" ] ### Build
then
lang="tsx"
fi
# Build.
cc -c -I. parser.c cc -c -I. parser.c
# Compile scanner.c. # Compile scanner.c.
if test -f scanner.c if test -f scanner.c
@ -48,15 +58,9 @@ else
cc -fPIC -shared *.o -o "libtree-sitter-${lang}.${soext}" cc -fPIC -shared *.o -o "libtree-sitter-${lang}.${soext}"
fi fi
# Copy out. ### Copy out
if [ "${lang}" == "typescript" ] mkdir -p "${topdir}/dist"
then cp "libtree-sitter-${lang}.${soext}" "${topdir}/dist"
cp "libtree-sitter-${lang}.${soext}" .. cd "${topdir}"
cd .. rm -rf "${repo}"
fi
mkdir -p ../../dist
cp "libtree-sitter-${lang}.${soext}" ../../dist
cd ../../
rm -rf "tree-sitter-${lang}"