-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathbuild.gradle.kts
More file actions
333 lines (287 loc) · 12.1 KB
/
build.gradle.kts
File metadata and controls
333 lines (287 loc) · 12.1 KB
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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import java.io.FileOutputStream
import java.net.HttpURLConnection
import java.net.URI
import java.net.URL
import java.security.MessageDigest
import java.util.*
buildscript {
val antlrKotlinVersion = "a2cf9c3064" // commit hash for custom antlr runtime
extra.set("antlrKotlinVersion", antlrKotlinVersion)
dependencies {
classpath("com.github.alchitry.antlr-kotlin:antlr-kotlin-gradle-plugin:$antlrKotlinVersion")
}
}
val antlrKotlinVersion = extra.get("antlrKotlinVersion") as String
plugins {
kotlin("jvm") version "2.2.21"
id("org.jetbrains.kotlin.plugin.compose") version "2.2.21"
kotlin("plugin.serialization") version "2.2.21"
id("org.jetbrains.compose") version "1.9.3"
id("dev.hydraulic.conveyor") version "1.12"
id("at.stnwtr.gradle-secrets-plugin") version "1.0.1"
}
val fullVersion = "2.0.52-BETA"
val numOnlyVersion = fullVersion.split('-').first()
group = "com.alchitry"
version = numOnlyVersion
repositories {
google()
mavenLocal()
mavenCentral()
maven("https://maven.pkg.jetbrains.space/public/p/compose/dev")
maven("https://jitpack.io")
}
dependencies {
implementation("com.github.alchitry.antlr-kotlin:antlr-kotlin-runtime:$antlrKotlinVersion")
implementation("org.apache.commons:commons-text:1.14.0")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.10.2")
implementation("org.jetbrains.kotlinx:kotlinx-collections-immutable:0.4.0")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-swing:1.10.2")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.9.0")
implementation(kotlin("reflect"))
implementation("org.jdom:jdom2:2.0.6.1")
implementation("org.jetbrains.kotlinx:kotlinx-cli:0.3.6")
implementation("org.usb4java:usb4java:1.3.0")
macAarch64("io.github.dsheirer:libusb4java-darwin-aarch64:1.3.1") // ARM Mac binary
implementation("com.fazecast:jSerialComm:2.11.4")
implementation("com.github.alchitry.yad2xx:yad2xxJava:8d48cda")
implementation("me.tongfei:progressbar:0.10.1")
implementation("org.jline:jline:3.30.6")
implementation("org.fusesource.jansi:jansi:2.4.2")
implementation("io.github.vinceglb:filekit-dialogs:0.12.0")
implementation("org.slf4j:slf4j-nop:2.0.17")
linuxAmd64(compose.desktop.linux_x64)
linuxAarch64(compose.desktop.linux_arm64)
macAmd64(compose.desktop.macos_x64)
macAarch64(compose.desktop.macos_arm64)
windowsAmd64(compose.desktop.windows_x64)
implementation("org.jetbrains.compose.material3:material3-desktop:1.9.0")
testImplementation(kotlin("test"))
}
configurations.all {
attributes {
attribute(Attribute.of("ui", String::class.java), "awt")
}
}
tasks.test {
useJUnitPlatform()
}
tasks.withType<KotlinCompile> {
compilerOptions {
jvmTarget.set(JvmTarget.JVM_22)
freeCompilerArgs.add("-opt-in=kotlin.contracts.ExperimentalContracts")
freeCompilerArgs.add("-opt-in=kotlin.ExperimentalStdlibApi")
freeCompilerArgs.add("-opt-in=kotlinx.serialization.ExperimentalSerializationApi")
freeCompilerArgs.add("-opt-in=androidx.compose.foundation.ExperimentalFoundationApi")
freeCompilerArgs.add("-opt-in=androidx.compose.material3.ExperimentalMaterial3Api")
freeCompilerArgs.add("-Xcontext-parameters")
}
}
kotlin {
jvmToolchain(22)
}
compose.desktop {
application {
mainClass = "com.alchitry.labs2.GUIKt"
}
}
val conveyorCommand = "/home/justin/.npm-global/bin/conveyor"
fun TaskContainer.registerConveyorTask(name: String, arg: String? = null) {
register(name) {
group = "conveyor"
dependsOn.add("jar")
doLast {
exec {
if (arg == null) {
commandLine(conveyorCommand, "--passphrase=${secrets.get("conveyorRootKey")}", "make", name)
} else {
commandLine(conveyorCommand, "--passphrase=${secrets.get("conveyorRootKey")}", arg, "make", name)
}
}
}
}
}
tasks.register("version") {
group = "conveyor"
doLast { exec { commandLine(conveyorCommand, "--version") } }
}
tasks.registerConveyorTask("app")
tasks.registerConveyorTask("site") // makes the site files locally
tasks.registerConveyorTask("windows-msix") // builds a windows msix
tasks.registerConveyorTask("windows-app") // builds a windows app
tasks.registerConveyorTask("ms-store-release") // publish to microsoft store
tasks.registerConveyorTask("copied-site") // pushes the site files to GitHub
tasks.registerConveyorTask("mac-app", "-Kapp.machines=mac.aarch64")
val generatedVersionDir = "${layout.buildDirectory.get()}/resources/main"
tasks.register("generateVersionProperties") {
doLast {
val propertiesFile = file("$generatedVersionDir/version.properties")
propertiesFile.parentFile.mkdirs()
val properties = Properties()
properties.setProperty("version", fullVersion)
val out = FileOutputStream(propertiesFile)
properties.store(out, null)
}
}
tasks.named("compileKotlin") {
dependsOn("processResources")
}
tasks.named("processResources") {
dependsOn("generateVersionProperties")
}
tasks.register<com.strumenta.antlrkotlin.gradle.AntlrKotlinTask>("generateKotlinGrammarSource") {
// the classpath used to run antlr code generation
antlrClasspath = configurations.detachedConfiguration(
// antlr itself
// antlr is transitive added by antlr-kotlin-target,
// add another dependency if you want to choose another antlr4 version (not recommended)
// project.dependencies.create("org.antlr:antlr4:$antlrVersion"),
// antlr target, required to create kotlin code
project.dependencies.create("com.github.alchitry.antlr-kotlin:antlr-kotlin-target:$antlrKotlinVersion")
)
maxHeapSize = "64m"
packageName = "com.alchitry.labs2.parsers.grammar"
arguments = listOf("-no-visitor", "-listener")
source = project.objects
.sourceDirectorySet("antlr", "antlr")
.srcDir("src/main/kotlin/com/alchitry/labs2/parsers/grammar").apply {
include("*.g4")
}
// outputDirectory is required, put it into the build directory
// if you do not want to add the generated sources to version control
//outputDirectory = File("build/generated-src/antlr/main")
// use this setting if you want to add the generated sources to version control
outputDirectory = File("src/main/kotlin/com/alchitry/labs2/parsers/grammar")
}
tasks.register("publish") {
group = "publishing"
dependsOn("copied-site", "updateAUR", "ms-store-release")
}
tasks.register("download-oss-cad-suite") {
group = "build setup"
doLast {
val includesDirectory = project.buildFile.parentFile.resolve("includes")
val latestReleaseUrl = getRedirectedUrl("https://github.com/alchitry/oss-cad-suite-build/releases/latest")
?: error("Failed to get latest release URL!")
val urlDate = latestReleaseUrl.split('/').last()
val dateStamp = urlDate.replace("-", "")
listOf("windows-x64", "linux-x64", "darwin-x64", "darwin-arm64").forEach { arch ->
val extension = if (arch == "windows-x64") "exe" else "tgz"
val archive = temporaryDir.resolve("$arch.$extension")
downloadFile(
"https://github.com/alchitry/oss-cad-suite-build/releases/download/$urlDate/oss-cad-suite-$arch-$dateStamp.$extension",
archive
)
val toolsDir = includesDirectory.resolve(arch).resolve("tools")
val target = toolsDir.resolve("oss-cad-suite")
if (target.exists())
target.deleteRecursively()
target.mkdirs()
if (arch == "windows-x64") {
project.exec { commandLine("7z", "x", archive.absolutePath, "-o${toolsDir.absolutePath}") }
// work around for windows not finding the .dlls
target.resolve("lib").apply {
listFiles()?.forEach {
if (it.extension == "dll") {
it.copyTo(target.resolve("bin").resolve(it.name), overwrite = true)
}
}
}
} else {
project.exec { commandLine("tar", "-xzf", archive.absolutePath, "-C", toolsDir.absolutePath) }
if (arch.startsWith("darwin")) {
// these files aren't needed and cause failures during signing
target.resolve("lib/python3.11/config-3.11-darwin/python.o").delete()
}
}
}
}
}
tasks.register("updateAUR") {
group = "publishing"
description = "Updates the PKGBUILD with the latest version and sha256sum, then pushes to AUR."
doLast {
val pkgbuildFile = file("${System.getProperty("user.home")}/AUR/alchitry-labs-bin/PKGBUILD")
if (!pkgbuildFile.exists()) {
throw GradleException("PKGBUILD not found at ${pkgbuildFile.absolutePath}")
}
val downloadUrl =
"https://github.com/alchitry/Alchitry-Labs-V2/releases/download/$numOnlyVersion/alchitry-labs-$numOnlyVersion-linux-amd64.tar.gz"
println("Downloading $downloadUrl to calculate SHA256...")
val digest = MessageDigest.getInstance("SHA-256")
URI(downloadUrl).toURL().openStream().use { input ->
val buffer = ByteArray(8192)
var bytesRead = input.read(buffer)
while (bytesRead != -1) {
digest.update(buffer, 0, bytesRead)
bytesRead = input.read(buffer)
}
}
val sha256sum = digest.digest().joinToString("") { "%02x".format(it) }
println("New SHA256: $sha256sum")
var content = pkgbuildFile.readText()
content = content.replace(Regex("pkgver=.*"), "pkgver=$numOnlyVersion")
content = content.replace(Regex("pkgrel=.*"), "pkgrel=1") // Reset pkgrel on version bump
content = content.replace(Regex("sha256sums=\\(\".*\"\\)"), "sha256sums=(\"$sha256sum\")")
pkgbuildFile.writeText(content)
val aurDir = pkgbuildFile.parentFile
val commands = listOf(
listOf("makepkg", "--printsrcinfo"),
listOf("git", "add", "PKGBUILD", ".SRCINFO"),
listOf("git", "commit", "-m", "Updated to $numOnlyVersion"),
listOf("git", "push")
)
commands.forEachIndexed { index, cmd ->
println("Executing: ${cmd.joinToString(" ")}")
exec {
workingDir = aurDir
commandLine = cmd
// For the first command, redirect output to .SRCINFO
if (index == 0) {
standardOutput = FileOutputStream(file("${aurDir.absolutePath}/.SRCINFO"))
}
}
}
}
}
fun downloadFile(url: String, destination: File) {
try {
val urlObj = URL(url)
val connection = urlObj.openConnection()
val inputStream = connection.getInputStream()
val buffer = ByteArray(4096)
var bytesRead: Int
val outputStream = FileOutputStream(destination)
while (inputStream.read(buffer).also { bytesRead = it } != -1) {
outputStream.write(buffer, 0, bytesRead)
}
outputStream.close()
inputStream.close()
} catch (e: Exception) {
println("Error downloading file: ${e.message}")
}
}
fun getRedirectedUrl(url: String): String? {
var currentUrl = url
var connection: HttpURLConnection? = null
try {
do {
connection = URL(currentUrl).openConnection() as HttpURLConnection
connection.instanceFollowRedirects = false
connection.connect()
val location = connection.getHeaderField("Location")
if (location != null) {
currentUrl = location
} else {
return currentUrl
}
} while (connection!!.responseCode in 300..399)
} catch (e: Exception) {
e.printStackTrace()
} finally {
connection?.disconnect()
}
return null
}