Skip to content

Commit 8ef88f4

Browse files
feat(plugin): implement grammar generator
1 parent 4a70200 commit 8ef88f4

File tree

29 files changed

+766
-175
lines changed

29 files changed

+766
-175
lines changed

.github/detekt.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,6 @@ style:
2626
- "3"
2727
- "10"
2828
- "16"
29+
- "0x7F"
2930
ReturnCount:
3031
max: 3

.github/scripts/build-jni.ps1

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@
22

33
& cmake -S ktreesitter -B ktreesitter/.cmake/build `
44
-DCMAKE_VERBOSE_MAKEFILE=ON `
5+
-DCMAKE_INSTALL_PREFIX=ktreesitter/src/jvmMain/resources `
56
-DCMAKE_INSTALL_BINDIR="$env:CMAKE_INSTALL_LIBDIR"
67
& cmake --build ktreesitter/.cmake/build --config Debug
7-
& cmake --install ktreesitter/.cmake/build --config Debug --prefix ktreesitter/src/jvmMain/resources
8+
& cmake --install ktreesitter/.cmake/build --config Debug
89

910
foreach ($dir in Get-ChildItem -Directory -Path languages) {
10-
& cmake -S "$dir" -B "$dir/.cmake/build" `
11+
& cmake -S "$dir/build/generated" -B "$dir/.cmake/build" `
12+
-DCMAKE_INSTALL_PREFIX="$dir/build/generated/src/jvmMain/resources" `
1113
-DCMAKE_INSTALL_BINDIR="$env:CMAKE_INSTALL_LIBDIR"
1214
& cmake --build "$dir/.cmake/build" --config Debug
13-
& cmake --install "$dir/.cmake/build" --config Debug --prefix "$dir/src/jvmMain/resources"
15+
& cmake --install "$dir/.cmake/build" --config Debug
1416
}

.github/scripts/build-jni.sh

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,17 @@ cmake -S ktreesitter -B ktreesitter/.cmake/build \
44
-DCMAKE_BUILD_TYPE=RelWithDebugInfo \
55
-DCMAKE_VERBOSE_MAKEFILE=ON \
66
-DCMAKE_OSX_ARCHITECTURES=arm64 \
7+
-DCMAKE_INSTALL_PREFIX=ktreesitter/src/jvmMain/resources \
78
-DCMAKE_INSTALL_LIBDIR="$CMAKE_INSTALL_LIBDIR"
8-
99
cmake --build ktreesitter/.cmake/build
10-
cmake --install ktreesitter/.cmake/build --prefix ktreesitter/src/jvmMain/resources
10+
cmake --install ktreesitter/.cmake/build
1111

1212
for dir in languages/*/; do
13-
cmake -S "$dir" -B "${dir}.cmake/build" \
13+
cmake -S "${dir}build/generated" -B "${dir}.cmake/build" \
1414
-DCMAKE_BUILD_TYPE=RelWithDebugInfo \
1515
-DCMAKE_OSX_ARCHITECTURES=arm64 \
16+
-DCMAKE_INSTALL_PREFIX="${dir}build/generated/src/jvmMain/resources" \
1617
-DCMAKE_INSTALL_LIBDIR="$CMAKE_INSTALL_LIBDIR"
1718
cmake --build "${dir}.cmake/build"
18-
cmake --install "${dir}.cmake/build" --prefix "${dir}src/jvmMain/resources"
19+
cmake --install "${dir}.cmake/build"
1920
done

.github/workflows/ci.yml

Lines changed: 54 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,42 +23,80 @@ permissions:
2323
contents: write
2424

2525
jobs:
26+
generate:
27+
runs-on: ubuntu-latest
28+
name: Generate grammar files
29+
steps:
30+
- name: Checkout repository
31+
uses: actions/checkout@v4
32+
with:
33+
submodules: true
34+
- name: Set up Java
35+
uses: actions/setup-java@v4
36+
with:
37+
distribution: temurin
38+
java-version: 17
39+
cache: gradle
40+
cache-dependency-path: |
41+
gradle/libs.versions.toml
42+
gradle/wrapper/gradle-wrapper.properties
43+
- name: Cache Kotlin/Native prebuilt
44+
uses: actions/cache@v4
45+
with:
46+
path: ${{runner.tool_cache}}/konan/kotlin-native-prebuilt-*
47+
key: konan-${{runner.os}}-prebuilt-1.9
48+
- name: Generate files
49+
run: ./gradlew --no-daemon generateGrammarFiles
50+
env:
51+
KONAN_DATA_DIR: ${{runner.tool_cache}}/konan
52+
- name: Upload artifact
53+
uses: actions/upload-artifact@v4
54+
with:
55+
name: generated-files
56+
path: languages/*/build/generated/**
57+
retention-days: 1
2658
test:
2759
runs-on: ${{matrix.os}}
2860
name: >-
2961
Test ${{matrix.platform}} platform
3062
${{matrix.lib_platform && format('({0}-{1})', matrix.lib_platform, matrix.lib_arch)}}
63+
needs: [generate]
3164
strategy:
3265
fail-fast: false
3366
matrix:
3467
include:
3568
- os: ubuntu-latest
3669
platform: JVM
37-
targets: jvmTest
70+
targets: :ktreesitter:jvmTest
3871
lib_platform: linux
3972
lib_arch: x64
4073
- os: windows-latest
4174
platform: JVM
42-
targets: jvmTest
75+
targets: :ktreesitter:jvmTest
4376
lib_platform: windows
4477
lib_arch: x64
4578
- os: macos-latest
4679
platform: JVM
47-
targets: jvmTest
80+
targets: :ktreesitter:jvmTest
4881
lib_platform: macos
4982
lib_arch: aarch64
50-
# - os: ubuntu-latest
51-
# platform: Android
52-
# targets: connectedDebugAndroidTest
83+
- os: ubuntu-latest
84+
platform: Android
85+
targets: :ktreesitter:assembleDebug
5386
- os: ubuntu-latest
5487
platform: Linux
55-
targets: compileKotlinLinuxArm64 linuxX64Test
88+
targets: >-
89+
:ktreesitter:compileKotlinLinuxArm64
90+
:ktreesitter:linuxX64Test
5691
- os: windows-latest
5792
platform: Windows
58-
targets: mingwX64Test
93+
targets: :ktreesitter:mingwX64Test
5994
- os: macos-latest
6095
platform: macOS/iOS
61-
targets: macosX64Test macosArm64Test iosSimulatorArm64Test
96+
targets: >-
97+
:ktreesitter:macosX64Test
98+
:ktreesitter:macosArm64Test
99+
:ktreesitter:iosSimulatorArm64Test
62100
steps:
63101
- name: Checkout repository
64102
uses: actions/checkout@v4
@@ -76,11 +114,16 @@ jobs:
76114
- name: Set up cross compilation
77115
run: sudo apt-get install -qy {binutils,gcc}-aarch64-linux-gnu
78116
if: matrix.platform == 'Linux'
79-
- name: Cache Kotlin/Native prebuilt
80-
uses: actions/cache@v4
117+
- name: Restore Kotlin/Native prebuilt
118+
uses: actions/cache/restore@v4
81119
with:
82120
path: ${{runner.tool_cache}}/konan/kotlin-native-prebuilt-*
83121
key: konan-${{runner.os}}-prebuilt-1.9
122+
- name: Download generated files
123+
uses: actions/download-artifact@v4
124+
with:
125+
path: languages
126+
name: generated-files
84127
- name: Build JNI libraries
85128
if: matrix.platform == 'JVM'
86129
run: .github/scripts/build-jni.${{matrix.os == 'windows-latest' && 'ps1' || 'sh'}}

.github/workflows/docs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ jobs:
4949
path: ${{runner.tool_cache}}/konan/dependencies
5050
key: konan-${{runner.os}}-dependencies
5151
- name: Build documentation
52-
run: ./gradlew --no-daemon :ktreesitter:dokkaHtml
52+
run: ./gradlew --no-daemon generateFiles :ktreesitter:dokkaHtml
5353
env:
5454
KONAN_DATA_DIR: ${{runner.tool_cache}}/konan
5555
- name: Upload pages artifact

.github/workflows/publish.yml

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,6 @@ jobs:
146146
pattern: ktreesitter-lib-*
147147
merge-multiple: true
148148
- name: Build packages
149-
shell: bash
150149
run: ./gradlew --no-daemon ${{matrix.targets}}
151150
env:
152151
SIGNING_KEY: ${{secrets.SIGNING_KEY}}
@@ -160,7 +159,7 @@ jobs:
160159
ktreesitter/build/repo/**
161160
!ktreesitter/build/repo/**/maven-metadata.*
162161
retention-days: 2
163-
publish:
162+
publish-library:
164163
runs-on: ubuntu-latest
165164
name: Publish packages on Maven Central
166165
needs: [build-jars]
@@ -201,3 +200,28 @@ jobs:
201200
run: gh release create $GITHUB_REF_NAME --generate-notes
202201
env:
203202
GH_TOKEN: ${{github.token}}
203+
publish-plugin:
204+
runs-on: ubuntu-latest
205+
name: Publish Gradle plugin
206+
needs: [build-jars]
207+
steps:
208+
- name: Checkout repository
209+
uses: actions/checkout@v4
210+
with:
211+
submodules: true
212+
- name: Set up Java
213+
uses: actions/setup-java@v4
214+
with:
215+
distribution: temurin
216+
java-version: 17
217+
cache: gradle
218+
cache-dependency-path: |
219+
gradle/libs.versions.toml
220+
gradle/wrapper/gradle-wrapper.properties
221+
- name: Publish plugin
222+
run: >-
223+
./gradlew --no-daemon :ktreesitter-plugin:publishPlugins
224+
-Pgradle.publish.key=$PUBLISH_KEY -Pgradle.publish.secret=$PUBLISH_SECRET
225+
env:
226+
PUBLISH_KEY: ${{secrets.GRADLE_PUBLISH_KEY}}
227+
PUBLISH_SECRET: ${{secrets.GRADLE_PUBLISH_SECRET}}

.idea/conventionalCommit.json

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,6 @@ Kotlin bindings to the Tree-sitter parsing library
2323
- [ ] Swift
2424
- [ ] Markdown
2525
- [ ] CMake
26-
- [ ] Gradle plugin
26+
- [x] Gradle plugin
2727
- [ ] Package
2828
- [ ] DSL?

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ sdk.version.min=23
88
# The Android NDK version that is used to compile the project.
99
ndk.version=26.3.11579264
1010
# The CMake version that is used to compile the project.
11-
cmake.version=3.29.3
11+
cmake.version=3.29.4
1212

1313
# Specifies the JVM arguments used for the daemon process.
1414
org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8

gradle/libs.versions.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ version.ref = "kotest"
5353
id = "org.jetbrains.dokka"
5454
version.ref = "dokka"
5555

56+
[plugins.gradle-publish]
57+
id = "com.gradle.plugin-publish"
58+
version = "1.2.1"
59+
5660
[bundles]
5761
kotest-core = [
5862
"kotest-engine",

0 commit comments

Comments
 (0)