forked from aniyomiorg/aniyomi-extensions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsettings.gradle.kts
106 lines (91 loc) · 3.39 KB
/
settings.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
apply(from = "repositories.gradle.kts")
pluginManagement {
includeBuild("build-plugins")
}
include(":core")
// Load all modules under /lib
File(rootDir, "lib").eachDir { include("lib:${it.name}") }
// Fix deprecation warnings with Gradle 8.5+.
// See https://docs.gradle.org/8.5/userguide/upgrading_version_8.html#deprecated_missing_project_directory
listOf(
":extensions" to "$rootDir/gradle", // Temporary workaround.
":extensions:individual" to "$rootDir/src",
":extensions:multisrc" to "$rootDir/generated-src",
).forEach { (name, path) ->
val projectDir = file(path)
if (projectDir.exists()) {
include(name)
project(name).projectDir = projectDir
}
}
if (System.getenv("CI") == null || System.getenv("CI_MODULE_GEN") == "true") {
// Local development (full project build)
include(":multisrc")
project(":multisrc").projectDir = File("multisrc")
/**
* Add or remove modules to load as needed for local development here.
* To generate multisrc extensions first, run the `:multisrc:generateExtensions` task first.
*/
loadAllIndividualExtensions()
loadAllGeneratedMultisrcExtensions()
// loadIndividualExtension("all", "jellyfin")
// loadGeneratedMultisrcExtension("en", "aniwatch")
} else {
// Running in CI (GitHub Actions)
val isMultisrc = System.getenv("CI_MULTISRC") == "true"
val chunkSize = System.getenv("CI_CHUNK_SIZE").toInt()
val chunk = System.getenv("CI_CHUNK_NUM").toInt()
if (isMultisrc) {
include(":multisrc")
project(":multisrc").projectDir = File("multisrc")
// Loads generated extensions from multisrc
File(rootDir, "generated-src").getChunk(chunk, chunkSize)?.forEach {
loadGeneratedMultisrcExtension(it.parentFile.name, it.name, log = true)
}
} else {
// Loads individual extensions
File(rootDir, "src").getChunk(chunk, chunkSize)?.forEach {
loadIndividualExtension(it.parentFile.name, it.name, log = true)
}
}
}
fun loadAllIndividualExtensions() {
File(rootDir, "src").eachDir { lang ->
lang.eachDir { extension ->
loadIndividualExtension(lang.name, extension.name)
}
}
}
fun loadAllGeneratedMultisrcExtensions() {
File(rootDir, "generated-src").eachDir { lang ->
lang.eachDir { extension ->
loadGeneratedMultisrcExtension(lang.name, extension.name)
}
}
}
fun loadIndividualExtension(lang: String, name: String, log: Boolean = false) {
val projectName = ":extensions:individual:$lang:$name"
if (log) println(projectName)
include(projectName)
project(projectName).projectDir = File("src/$lang/$name")
}
fun loadGeneratedMultisrcExtension(lang: String, name: String, log: Boolean = false) {
val projectName = ":extensions:multisrc:$lang:$name"
if (log) println(projectName)
include(projectName)
project(projectName).projectDir = File("generated-src/$lang/$name")
}
fun File.getChunk(chunk: Int, chunkSize: Int): List<File>? {
return listFiles()
// Lang folder
?.filter { it.isDirectory }
// Extension subfolders
?.mapNotNull { dir -> dir.listFiles()?.filter { it.isDirectory } }
?.flatten()
?.sortedBy { it.name }
?.chunked(chunkSize)
?.get(chunk)
}
fun File.eachDir(block: (File) -> Unit) {
listFiles()?.filter { it.isDirectory }?.forEach { block(it) }
}