Skip to content

Commit 38197a7

Browse files
committed
Generate libchewing data files from this app module
Signed-off-by: Hui-Hong You <hiroshi@ghostsinthelab.org>
1 parent 33f3eba commit 38197a7

2 files changed

Lines changed: 47 additions & 1 deletion

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@
1313
.externalNativeBuild
1414
.cxx
1515
local.properties
16+
/libchewing-android-module/src/main/assets/

libchewing-android-module/build.gradle.kts

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ android {
2222
}
2323
}
2424

25-
targetSdk = 34
2625
setProperty("archivesBaseName", "${project.name}_${versionName}")
2726
}
2827

@@ -53,6 +52,52 @@ android {
5352
}
5453
ndkVersion = "26.1.10909125"
5554
buildToolsVersion = "34.0.0"
55+
56+
57+
val chewingLibraryPath: String = "${rootDir}/libchewing-android-module/src/main/cpp/libs/libchewing"
58+
59+
tasks.register<Exec>("prepareChewing") {
60+
workingDir(chewingLibraryPath)
61+
commandLine("cmake", "--preset", "c99-release", "-DBUILD_SHARED_LIBS=OFF", ".")
62+
}
63+
64+
val chewingDataFiles =
65+
listOf<String>("dictionary.dat", "index_tree.dat", "pinyin.tab", "swkb.dat", "symbols.dat")
66+
67+
tasks.register<Exec>("buildChewingData") {
68+
dependsOn("prepareChewing")
69+
workingDir("$chewingLibraryPath/build")
70+
commandLine("make", "data", "all_static_data")
71+
}
72+
73+
tasks.register<Copy>("copyChewingDataFiles") {
74+
dependsOn("buildChewingData")
75+
for (chewingDataFile in chewingDataFiles) {
76+
from("$chewingLibraryPath/build/data/$chewingDataFile")
77+
into("$rootDir/libchewing-android-module/src/main/assets")
78+
}
79+
}
80+
81+
tasks.preBuild {
82+
dependsOn("copyChewingDataFiles")
83+
}
84+
85+
tasks.register<Delete>("cleanChewingDataFiles") {
86+
for (chewingDataFile in chewingDataFiles) {
87+
file("$rootDir/libchewing-android-module/src/main/assets/$chewingDataFile").delete()
88+
}
89+
}
90+
91+
tasks.register<Exec>("execMakeClean") {
92+
onlyIf { file("$chewingLibraryPath/build/Makefile").exists() }
93+
workingDir("$chewingLibraryPath/build")
94+
commandLine("make", "clean")
95+
isIgnoreExitValue = true
96+
}
97+
98+
tasks.clean {
99+
dependsOn("cleanChewingDataFiles", "execMakeClean")
100+
}
56101
}
57102

58103
dependencies {

0 commit comments

Comments
 (0)