emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

emacs-29 6acf95cbea6: Fix admin/notes/tree-sitter/build-module/build.sh


From: Yuan Fu
Subject: emacs-29 6acf95cbea6: Fix admin/notes/tree-sitter/build-module/build.sh (bug#59789)
Date: Tue, 6 Dec 2022 19:11:59 -0500 (EST)

branch: emacs-29
commit 6acf95cbea6007c1a11e2e7d8e0a535c3cbe2e33
Author: Yuan Fu <casouri@gmail.com>
Commit: Yuan Fu <casouri@gmail.com>

    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.
---
 admin/notes/tree-sitter/build-module/batch.sh |  1 +
 admin/notes/tree-sitter/build-module/build.sh | 56 ++++++++++++++-------------
 2 files changed, 31 insertions(+), 26 deletions(-)

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}"



reply via email to

[Prev in Thread] Current Thread [Next in Thread]