diff --git a/buildSrc/src/main/kotlin/mihon/buildlogic/ProjectExtensions.kt b/buildSrc/src/main/kotlin/mihon/buildlogic/ProjectExtensions.kt index 4b9e762b9..ae18dd637 100644 --- a/buildSrc/src/main/kotlin/mihon/buildlogic/ProjectExtensions.kt +++ b/buildSrc/src/main/kotlin/mihon/buildlogic/ProjectExtensions.kt @@ -15,6 +15,7 @@ import org.gradle.kotlin.dsl.the import org.gradle.kotlin.dsl.withType import org.jetbrains.kotlin.compose.compiler.gradle.ComposeCompilerGradlePluginExtension import org.jetbrains.kotlin.gradle.tasks.KotlinCompile +import java.io.File val Project.androidx get() = the() val Project.compose get() = the() @@ -106,3 +107,5 @@ internal fun Project.configureTest() { } } } + +val Project.generatedBuildDir: File get() = project.layout.buildDirectory.asFile.get().resolve("generated/mihon") diff --git a/buildSrc/src/main/kotlin/mihon/buildlogic/tasks/LocalesConfigPlugin.kt b/buildSrc/src/main/kotlin/mihon/buildlogic/tasks/LocalesConfigPlugin.kt index d84d2cb64..329e4a769 100644 --- a/buildSrc/src/main/kotlin/mihon/buildlogic/tasks/LocalesConfigPlugin.kt +++ b/buildSrc/src/main/kotlin/mihon/buildlogic/tasks/LocalesConfigPlugin.kt @@ -3,10 +3,11 @@ package mihon.buildlogic.tasks import org.gradle.api.Project import org.gradle.api.Task import org.gradle.api.tasks.TaskProvider +import java.io.File -private val emptyResourcesElement = "\\s*|".toRegex() +private val emptyResourcesElement = "\\s*|".toRegex() -fun Project.getLocalesConfigTask(): TaskProvider { +fun Project.getLocalesConfigTask(outputResourceDir: File): TaskProvider { return tasks.register("generateLocalesConfig") { val locales = fileTree("$projectDir/src/commonMain/moko-resources/") .matching { include("**/strings.xml") } @@ -16,7 +17,6 @@ fun Project.getLocalesConfigTask(): TaskProvider { .replace("base", "en") .replace("-r", "-") .replace("+", "-") - .takeIf(String::isNotBlank) ?: "en" } .sorted() .joinToString("\n") { "| " } @@ -28,10 +28,9 @@ fun Project.getLocalesConfigTask(): TaskProvider { | """.trimMargin() - file("$projectDir/src/androidMain/res/xml/locales_config.xml").apply { + outputResourceDir.resolve("xml/locales_config.xml").apply { parentFile.mkdirs() writeText(content) } } } - diff --git a/i18n/.gitignore b/i18n/.gitignore index 601f2b1cd..e69de29bb 100644 --- a/i18n/.gitignore +++ b/i18n/.gitignore @@ -1,2 +0,0 @@ -# Generated -locales_config.xml \ No newline at end of file diff --git a/i18n/build.gradle.kts b/i18n/build.gradle.kts index 7c7256acc..a7d5b889a 100644 --- a/i18n/build.gradle.kts +++ b/i18n/build.gradle.kts @@ -1,3 +1,4 @@ +import mihon.buildlogic.generatedBuildDir import mihon.buildlogic.tasks.getLocalesConfigTask import org.jetbrains.kotlin.gradle.tasks.KotlinCompile @@ -21,13 +22,17 @@ kotlin { } } +val generatedAndroidResourceDir = generatedBuildDir.resolve("android/res") + android { namespace = "tachiyomi.i18n" sourceSets { - named("main") { - res.srcDir("src/commonMain/resources") - } + val main by getting + main.res.srcDirs( + "src/commonMain/resources", + generatedAndroidResourceDir, + ) } lint { @@ -40,7 +45,7 @@ multiplatformResources { } tasks { - val localesConfigTask = project.getLocalesConfigTask() + val localesConfigTask = project.getLocalesConfigTask(generatedAndroidResourceDir) preBuild { dependsOn(localesConfigTask) }