From: Yuan Fu Date: Tue, 6 Dec 2022 23:55:14 +0000 (-0800) Subject: Fix admin/notes/tree-sitter/build-module/build.sh (bug#59789) X-Git-Tag: emacs-29.0.90~1328 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=6acf95cbea6;p=emacs.git 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. --- diff --git a/admin/notes/tree-sitter/build-module/batch.sh b/admin/notes/tree-sitter/build-module/batch.sh index deed18978a1..d45f37f4b64 100755 --- a/admin/notes/tree-sitter/build-module/batch.sh +++ b/admin/notes/tree-sitter/build-module/batch.sh @@ -12,6 +12,7 @@ languages=( 'python' 'rust' 'typescript' + 'tsx' ) for language in "${languages[@]}" diff --git a/admin/notes/tree-sitter/build-module/build.sh b/admin/notes/tree-sitter/build-module/build.sh index 102ab310fa0..a71ccaa4edb 100755 --- a/admin/notes/tree-sitter/build-module/build.sh +++ b/admin/notes/tree-sitter/build-module/build.sh @@ -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}"