-
Notifications
You must be signed in to change notification settings - Fork 17
/
build.gradle.kts
172 lines (146 loc) · 5.85 KB
/
build.gradle.kts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
/*
* This file is part of android-tree-sitter.
*
* android-tree-sitter library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* android-tree-sitter library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with android-tree-sitter. If not, see <https://www.gnu.org/licenses/>.
*/
@file:Suppress("UnstableApiUsage")
import com.android.build.gradle.BaseExtension
import com.itsaky.androidide.treesitter.BuildTreeSitterTask
import com.itsaky.androidide.treesitter.CleanTreeSitterBuildTask
import com.itsaky.androidide.treesitter.projectVersionCode
import com.vanniktech.maven.publish.AndroidSingleVariantLibrary
import com.vanniktech.maven.publish.MavenPublishBaseExtension
import com.vanniktech.maven.publish.SonatypeHost
@Suppress("DSL_SCOPE_VIOLATION") plugins {
id("build-logic.root-project")
alias(libs.plugins.maven.publish) apply false
}
fun Project.configureBaseExtension() {
extensions.configure<BaseExtension> {
compileSdkVersion(33)
defaultConfig {
minSdk = 21
targetSdk = 33
versionCode = project.projectVersionCode
versionName = rootProject.version.toString()
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}
buildTypes {
getByName("release") {
isMinifyEnabled = false
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro")
}
}
}
}
subprojects {
plugins.withId("com.android.application") { configureBaseExtension() }
plugins.withId("com.android.library") { configureBaseExtension() }
plugins.withId("android-tree-sitter.ts") {
configureTsModule()
// set java library path for tests
tasks.withType<Test> {
systemProperty("java.library.path",
rootProject.buildDir.resolve("host").absolutePath)
}
}
plugins.withId("com.vanniktech.maven.publish.base") {
configure<MavenPublishBaseExtension> {
group = "com.itsaky.androidide"
var versionName = rootProject.version.toString()
if (System.getenv("PublishToMaven").isNullOrBlank()) {
versionName = "$versionName-SNAPSHOT"
}
versionName = versionName.substring(1) // remove 'v' prefix
pom {
name.set(project.name)
description.set(
if (project.description.isNullOrBlank()) "${project.name} grammar for android-tree-sitter."
else project.description)
inceptionYear.set("2022")
url.set("https://github.com/itsaky/android-tree-sitter/")
licenses {
license {
name.set("LGPL-v2.1")
url.set(
"https://github.com/itsaky/android-tree-sitter/blob/main/LICENSE")
distribution.set("repo")
}
}
scm {
url.set("https://github.com/itsaky/android-tree-sitter/")
connection.set(
"scm:git:git://github.com/itsaky/android-tree-sitter.git")
developerConnection.set(
"scm:git:ssh://[email protected]/itsaky/android-tree-sitter.git")
}
developers {
developer {
id.set("androidide")
name.set("AndroidIDE")
url.set("https://androidide.com")
}
}
}
coordinates(project.group.toString(), project.name, versionName)
publishToMavenCentral(host = SonatypeHost.S01)
signAllPublications()
configure(AndroidSingleVariantLibrary(publishJavadocJar = false))
}
}
}
tasks.register<BuildTreeSitterTask>("buildTreeSitter")
tasks.register<CleanTreeSitterBuildTask>("cleanTreeSitterBuild")
tasks.register<Delete>("clean").configure {
dependsOn("cleanTreeSitterBuild")
delete(rootProject.buildDir)
delete(rootProject.file("tree-sitter-lib/cli/build"))
}
fun Project.configureTsModule() {
extensions.configure<BaseExtension> {
val grammarName =
project.project.name.substringAfter("tree-sitter-", "")
if (grammarName.isNotBlank()) {
namespace = "com.itsaky.androidide.treesitter.$grammarName"
logger.lifecycle("Set namespace '$namespace' to $project")
}
ndkVersion = "24.0.8215888"
defaultConfig {
val rootProjDir = project.rootProject.projectDir.absolutePath
val tsDir = "${rootProjDir}/tree-sitter-lib"
externalNativeBuild {
cmake {
arguments("-DPROJECT_DIR=${rootProjDir}",
"-DTS_DIR=${tsDir}")
}
}
}
externalNativeBuild {
cmake {
path = project.file("src/main/cpp/CMakeLists.txt")
version = "3.22.1"
}
}
}
// avoid circular dependency
if (project.projects.androidTreeSitter.name != project.name) {
configurations.getByName("api").dependencies.add(
project.projects.androidTreeSitter)
}
}