Skip to content
This repository was archived by the owner on Oct 18, 2024. It is now read-only.

Commit 3352533

Browse files
committed
Added APIs for version info & updated scripts
1 parent c183309 commit 3352533

19 files changed

+100
-13
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.itsaky.androidide.treesitter;
2+
3+
/**
4+
* @author Akash Yadav
5+
*/
6+
public class TreeSitter {
7+
8+
/**
9+
* The latest ABI version that is supported by the current version of the library. When Languages
10+
* are generated by the Tree-sitter CLI, they are assigned an ABI version number that corresponds
11+
* to the current CLI version. The Tree-sitter library is generally backwards-compatible with
12+
* languages generated using older CLI versions, but is not forwards-compatible.
13+
*/
14+
public static native int getLanguageVersion();
15+
16+
/** The earliest ABI version that is supported by the current version of the library. */
17+
public static native int getMinimumCompatibleLanguageVersion();
18+
}
552 Bytes
Binary file not shown.
492 Bytes
Binary file not shown.
472 Bytes
Binary file not shown.
584 Bytes
Binary file not shown.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,17 @@
11
package com.itsaky.androidide.treesitter;
22

3+
import static com.google.common.truth.Truth.assertThat;
4+
5+
import org.junit.Test;
6+
37
public class TestBase {
48
static {
59
System.load(System.getProperty("user.dir") + "/../output/host/libts.so");
610
}
11+
12+
@Test
13+
public void test() {
14+
assertThat(TreeSitter.getLanguageVersion()).isEqualTo(14);
15+
assertThat(TreeSitter.getMinimumCompatibleLanguageVersion()).isEqualTo(13);
16+
}
717
}

build.sh

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ ndk_dir=""
3030
verbose_out=false
3131

3232
OPTIND=1
33-
while getopts "h?sa:o:m:n:" opt; do
33+
while getopts "h?sva:o:m:n:" opt; do
3434
case "$opt" in
3535
h|\?)
3636
print_help
@@ -118,15 +118,14 @@ mkdir -p $dest_dir
118118
macros=""
119119
sources=""
120120
for file in ${script_dir}/lib/*; do
121-
if [[ $file == *.h ]]; then
121+
if [[ $file == *.h || -d $file ]]; then
122122
verbose "Skiping $file"
123123
continue
124124
fi
125125
sources+=${file}
126126
sources+=" "
127127
done
128-
# sources="${script_dir}/lib/ts.cc"
129-
# sources+=" ${script_dir}/lib/langs.cc"
128+
130129
iscpp=""
131130
for lang in $*
132131
do
@@ -147,11 +146,20 @@ do
147146
macros+=" -DTS_LANGUAGE_${g_LANG}=1"
148147
done
149148

150-
verbose "Sources --------------------------------\n" "$sources"
151-
verbose "Macros --------------------------------" "$macros"
149+
verbose
150+
verbose "Sources --------------------------------"
151+
for source in $sources; do
152+
verbose $source
153+
done
154+
verbose ""
155+
verbose "Macros --------------------------------"
156+
for macro in $macros; do
157+
verbose $macro
158+
done
159+
verbose ""
152160

153161
objects=""
154-
includes="-I${script_dir}/tree-sitter/lib/include -I${script_dir}/tree-sitter/lib/src"
162+
includes="-I${script_dir}/tree-sitter/lib/include -I${script_dir}/tree-sitter/lib/src -I${script_dir}/lib/include"
155163
out_dir_base="${script_dir}/output/${clang_qualifier}"
156164

157165
if [ ! -z "${for_host+x}" ]; then

genh.sh

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,18 @@
22

33
set -eu
44

5+
color="\033[32m"
6+
nocolor="\033[0m"
57
script_dir=$(realpath $(dirname $0))
68

7-
for header in TSLanguages.Native TSLanguage.Native TSParser.Native TSTreeCursor.Native TSTree.Native TSQuery.Native TSQueryCursor.Native TSNode
8-
do
9-
javah -d $script_dir/lib -classpath ${script_dir}/android-tree-sitter/src/main/java com.itsaky.androidide.treesitter.${header}
10-
done
9+
printf "${color}Finding java sources...${nocolor}\n"
10+
find ${script_dir}/android-tree-sitter/src/main/java -name "*.java" > sources.txt
11+
12+
printf "${color}Generating headers...${nocolor}\n"
13+
out="${script_dir}/classes"
14+
mkdir $out
15+
javac -d ${out} -h ${script_dir}/lib/include @sources.txt
16+
17+
printf "${color}"
18+
rm -rf ${out} sources.txt
19+
printf "${nocolor}"

lib/.vscode/c_cpp_properties.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"name": "Linux",
55
"includePath": [
66
"${workspaceFolder}/**",
7+
"${workspaceFolder/include}",
78
"${workspaceFolder}/../tree-sitter/lib/src",
89
"${workspaceFolder}/../tree-sitter/lib/include",
910
"${env:JAVA_HOME}/include",
@@ -17,4 +18,4 @@
1718
}
1819
],
1920
"version": 4
20-
}
21+
}

lib/com_itsaky_androidide_treesitter_TSLanguage_Native.h renamed to lib/include/com_itsaky_androidide_treesitter_TSLanguage_Native.h

File renamed without changes.

0 commit comments

Comments
 (0)