aboutsummaryrefslogtreecommitdiff
path: root/buildSrc/src
diff options
context:
space:
mode:
authorLinnea Gräf <nea@nea.moe>2024-04-19 20:57:07 +0200
committerGitHub <noreply@github.com>2024-04-19 20:57:07 +0200
commit40309bc8acb7afb37bbc99d7a758c24ffd962b4c (patch)
treecfabc8d261d820ea63921bead05e20feb67f4a4f /buildSrc/src
parentf3b6288fed75eacede95627282cb9bfec73f0c9e (diff)
downloadskyhanni-40309bc8acb7afb37bbc99d7a758c24ffd962b4c.tar.gz
skyhanni-40309bc8acb7afb37bbc99d7a758c24ffd962b4c.tar.bz2
skyhanni-40309bc8acb7afb37bbc99d7a758c24ffd962b4c.zip
Backend: Add unimined build system (#1456)
Diffstat (limited to 'buildSrc/src')
-rw-r--r--buildSrc/src/AutoMixinDiscovery.kt50
-rw-r--r--buildSrc/src/EnvFile.kt12
2 files changed, 62 insertions, 0 deletions
diff --git a/buildSrc/src/AutoMixinDiscovery.kt b/buildSrc/src/AutoMixinDiscovery.kt
new file mode 100644
index 000000000..f66229030
--- /dev/null
+++ b/buildSrc/src/AutoMixinDiscovery.kt
@@ -0,0 +1,50 @@
+import com.google.gson.GsonBuilder
+import com.google.gson.JsonArray
+import com.google.gson.JsonObject
+import com.google.gson.JsonPrimitive
+import org.apache.tools.ant.filters.BaseParamFilterReader
+import org.gradle.api.file.FileCopyDetails
+import org.gradle.api.tasks.SourceSet
+import java.io.File
+import java.io.Reader
+import java.io.StringReader
+
+class MixinFilterReader(reader: Reader) : BaseParamFilterReader() {
+ lateinit var sourceRoots: Collection<File>
+ val gson = GsonBuilder().setPrettyPrinting().create()
+ val betterReader: StringReader by lazy {
+ StringReader(run {
+ val json = gson.fromJson(reader.readText(), JsonObject::class.java)
+ val mixinPackage = (json["package"] as JsonPrimitive).asString
+ val allMixins = (json["mixins"] as JsonArray?)?.map { it.asString }?.toMutableSet() ?: mutableSetOf()
+ sourceRoots
+ .forEach { base ->
+ base.walk()
+ .filter { it.isFile }
+ .forEach {
+ val relativeString = it.toRelativeString(base).replace("\\", "/")
+ if (relativeString.startsWith(mixinPackage.replace(".", "/") + "/")
+ && relativeString.endsWith(".java")
+ && it.readText().contains("@Mixin")
+ )
+ allMixins.add(
+ relativeString.replace("/", ".").dropLast(5).drop(mixinPackage.length + 1)
+ )
+ }
+ }
+ json.add("mixins", JsonArray().also { jsonAllMixins ->
+ allMixins.forEach { jsonAllMixins.add(it) }
+ })
+ gson.toJson(json)
+ })
+
+ }
+
+ override fun read(): Int {
+ return betterReader.read()
+ }
+}
+
+fun FileCopyDetails.autoDiscoverMixins(sourceSet: SourceSet) {
+ filter(mapOf("sourceRoots" to sourceSet.allSource.srcDirs), MixinFilterReader::class.java)
+}
diff --git a/buildSrc/src/EnvFile.kt b/buildSrc/src/EnvFile.kt
new file mode 100644
index 000000000..76d6fa959
--- /dev/null
+++ b/buildSrc/src/EnvFile.kt
@@ -0,0 +1,12 @@
+import java.io.File
+
+fun parseEnvFile(file: File): Map<String, String> {
+ if (!file.exists()) return mapOf()
+ val map = mutableMapOf<String, String>()
+ for (line in file.readText().lines()) {
+ if (line.isEmpty() || line.startsWith("#")) continue
+ val parts = line.split("=", limit = 2)
+ map[parts[0]] = parts.getOrNull(1) ?: ""
+ }
+ return map
+}