Repository navigation
build: stop building OpenCC tools for Android and trim the runtime - #2236
Open
WhiredPlanck wants to merge 1 commit into
Open
WhiredPlanck wants to merge 1 commit into
WhiredPlanck wants to merge 1 commit into
Conversation
OpenCC's tools were built for every ABI although nothing uses them: the dictionaries come from the host build, and an Android executable cannot run on the build machine. Exclude them along with the data target. The host build tree is recreated when its CMake generator or build tool no longer fits, since CMake refuses to change the generator of an existing tree and keeps using a tool that has been uninstalled. An SDK cmake that is not the requested version falls back to the newest installed one. At runtime only a text dictionary the user puts in an opencc data directory needs compiling, so the dictionary listing and conversion API, and the JNI direction that served them, are gone. Such a dictionary is converted only when newer than its compiled copy, and a failed conversion leaves nothing that would look up to date next time. The OpenCC CMake options that already default to off are no longer passed either.
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Approval is blocked by four active findings, including three moderate build-tool cache/version handling issues and an incomplete KDoc comment that still require correction.
4 open issues
What changed in this PR
This pull request trims unnecessary OpenCC work from Android builds and simplifies runtime dictionary handling by relying on host-generated .ocd2 assets while compiling user-provided text dictionaries only when needed.
Changes:
- Excludes OpenCC data-generation targets and command-line tools from Android builds.
- Improves host CMake discovery, stale build-tree handling, and dictionary format defaults.
- Removes unused dictionary APIs and implements timestamp-based runtime conversion for
.txtdictionaries.
| File | Description |
|---|---|
| build-logic/convention/src/main/kotlin/OpenCCDataPlugin.kt | Updates host OpenCC configuration, CMake discovery, stale generator recovery, version selection, and dictionary build behavior. |
| app/src/main/jni/librime_jni/opencc.cc | Retains JNI functionality for converting text dictionaries to .ocd2 files. |
| app/src/main/jni/librime_jni/CMakeLists.txt | Documents and configures the bundled OpenCC dependency for JNI conversion. |
| app/src/main/jni/CMakeLists.txt | Excludes OpenCC data-generation targets and command-line tools from Android builds. |
| app/src/main/java/com/osfans/trime/data/opencc/OpenCCDictManager.kt | Adds timestamp-based compilation of user text dictionaries and removes unused dictionary APIs. |
| app/src/main/java/com/osfans/trime/data/opencc/dict/TextDictionary.kt | Removes the obsolete text dictionary wrapper. |
| app/src/main/java/com/osfans/trime/data/opencc/dict/OpenCCDictionary.kt | Removes the obsolete compiled dictionary wrapper. |
| app/src/main/java/com/osfans/trime/data/opencc/dict/Dictionary.kt | Removes the obsolete dictionary abstraction and conversion API. |
Review effort: Lite
Comment on lines
+268
to
+269
| (ninja == null || entries["CMAKE_GENERATOR"] == "Ninja") && | ||
| (tool.isNullOrBlank() || File(tool).isFile) |
| val tool = entries["CMAKE_MAKE_PROGRAM"] | ||
| val usable = | ||
| (ninja == null || entries["CMAKE_GENERATOR"] == "Ninja") && | ||
| (tool.isNullOrBlank() || File(tool).isFile) |
Comment on lines
+392
to
+397
| fun parts(version: String) = version.split('.', '-').map { it.toIntOrNull() ?: 0 } | ||
| return parts(a) | ||
| .zip(parts(b)) | ||
| .firstOrNull { (left, right) -> left != right } | ||
| ?.let { (left, right) -> left.compareTo(right) } | ||
| ?: 0 |
Comment on lines
+28
to
+29
| * Compile the text dictionaries found in [openccDirs], so that one the user | ||
| * puts there becomes usable and edits to one already compiled are picked up. |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


Pull request
Issue tracker
Fixes # N/A
Feature
Follow-up to the change that generates OpenCC's data with a host build: that
change left the cross-compile tree and the runtime doing work nobody needs.
The Android build no longer builds OpenCC's tools.
opencc,opencc_dictand
opencc_phrase_extractwere built for every ABI although nothing links orships them — the dictionaries come from the host build, and an Android
executable cannot run on the build machine anyway. They are now excluded along
with the
datatarget, whose commands would try to run thatopencc_dict.The host build recovers from a stale tree. CMake refuses to change the
generator of an existing tree and keeps using the build tool recorded in it even
after that tool has been uninstalled, so the tree is recreated when either no
longer fits. This matters because Ninja is optional: a host without it gets the
default generator, and installing Ninja later must not wedge the build. An SDK
cmake that is not the requested version now falls back to the newest installed
one rather than the alphabetically first, and a blank
OPENCC_DICT_FORMATfallsback to
ocd2.The runtime keeps only what still has a purpose. With the built-in
dictionaries shipping as
.ocd2, the deploy-time conversion had nothing left todo. The dictionary listing and conversion API it belonged to had no caller, so
it is gone, together with the JNI direction that only served it. What remains is
the case that does matter: a text dictionary the user drops into an opencc data
directory is compiled, and only when it is newer than its compiled copy. A
failed conversion no longer leaves a truncated
.ocd2that would look up todate on the next deploy.
The OpenCC CMake options that already default to off are no longer passed
either, leaving only the four the build actually depends on.
Net change: 8 files, +96 / −310.
Verification
opencc_dictand friends no longer appear inall;buildCMakeDebugpasses for all four ABIs andlibrime_jni.sois produced.librime_jni.soexports…OpenCCDictManager_openCCDictConvfor everyABI; the removed
openCCLineConvhas no caller left..ocd2+ 16.json) on Ninja;idempotent rerun is 0.7 s.
removing the recorded build tool, both log
Recreating …and succeed.OPENCC_DICT_FORMAT=textround trip still rewrites configs and restorescleanly; a blank value falls back to
ocd2.s2twpgives 内存→記憶體, 方便面→泡麵, 打印机→印表機;t2sgives漢字轉換測試→汉字转换测试.
assets/shared/openccentries, no.txt, no host binaries../gradlew spotlessCheckandvalidatePluginspass.Code of conduct
Code style
make style-lintBuild pass
make debugManually test
Code Review
Daily build
Login and download artifact at https://github.com/osfans/trime/actions
Additional Info
F-Droid: the app no longer builds the OpenCC tools at all, which removes three
executables per ABI from the build server's work. Ninja stays optional, so a
build host that only has make keeps working.
No unit tests are added. Both areas are decided at build or deploy time — a
CMake tree's generator, and a dictionary's timestamp — and the repository has no
harness for either; the checks above were run against the host build and a real
assembleDebuginstead.