Skip to content

build: stop building OpenCC tools for Android and trim the runtime - #2236

Open
WhiredPlanck wants to merge 1 commit into
osfans:developfrom
WhiredPlanck:opencc-dict
Open

WhiredPlanck wants to merge 1 commit into
osfans:developfrom
WhiredPlanck:opencc-dict

Conversation

@WhiredPlanck

Copy link
Copy Markdown
Collaborator

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_dict
and opencc_phrase_extract were built for every ABI although nothing links or
ships 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 data target, whose commands would try to run that opencc_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_FORMAT falls
back 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 to
do. 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 .ocd2 that would look up to
date 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

  • Cross-compile tree: opencc_dict and friends no longer appear in all;
    buildCMakeDebug passes for all four ABIs and librime_jni.so is produced.
  • JNI: librime_jni.so exports …OpenCCDictManager_openCCDictConv for every
    ABI; the removed openCCLineConv has no caller left.
  • Host build: cold run 14 s / 38 files (22 .ocd2 + 16 .json) on Ninja;
    idempotent rerun is 0.7 s.
  • Stale tree: switching between Ninja and Makefiles in either direction, and
    removing the recorded build tool, both log Recreating … and succeed.
  • OPENCC_DICT_FORMAT=text round trip still rewrites configs and restores
    cleanly; a blank value falls back to ocd2.
  • Conversion: s2twp gives 内存→記憶體, 方便面→泡麵, 打印机→印表機; t2s gives
    漢字轉換測試→汉字转换测试.
  • APK: 38 assets/shared/opencc entries, no .txt, no host binaries.
  • ./gradlew spotlessCheck and validatePlugins pass.

Code of conduct

Code style

Build pass

  • make debug

Manually test

  • Done

Code Review

  1. No wildcards import
  2. Manual build and test pass
  3. GitHub Action CI pass
  4. At least one contributor review and approve
  5. Merged clean without conflicts
  6. PR will be merged by rebase upstream base

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
assembleDebug instead.

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.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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 .txt dictionaries.
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

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants