diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 000000000..23d9ca20c --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +packaging/ export-ignore diff --git a/CMakeLists.txt b/CMakeLists.txt index 1e61c300b..176dfb343 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -57,6 +57,8 @@ option(USE_SYSTEM_MARISA "Use system version of Marisa" OFF) option(USE_SYSTEM_PYBIND11 "Use system version of pybind11" OFF) option(USE_SYSTEM_RAPIDJSON "Use system version of RapidJSON" OFF) option(USE_SYSTEM_TCLAP "Use system version of TCLAP" OFF) +set(OPENCC_SOURCE_PACKAGE_PROFILE "full" CACHE STRING "Source package profile: full, opencc, or opencc-jieba") +set_property(CACHE OPENCC_SOURCE_PACKAGE_PROFILE PROPERTY STRINGS full opencc opencc-jieba) ######## Package information set (PACKAGE_URL https://github.com/BYVoid/OpenCC) @@ -70,11 +72,68 @@ include(GitVersion) # such as librime to relink instead of loading an ABI-incompatible libopencc. set (OPENCC_ABI_VERSION 1.4) -set(CPACK_SOURCE_PACKAGE_FILE_NAME - "${PACKAGE_NAME}-${OPENCC_VERSION_MAJOR}.${OPENCC_VERSION_MINOR}.${OPENCC_VERSION_REVISION}" +set(_OPENCC_SOURCE_PACKAGE_SUFFIX "") +set(_OPENCC_SOURCE_PACKAGE_IGNORE_FILES "") +set(_OPENCC_TRIMMED_SOURCE_PACKAGE_IGNORE_FILES + "/.appveyor.yml" + "/.bazel[^/]*" + "/.agents/" + "/.claude/" + "/.npmignore" + "/AGENTS.md" + "/BUILD.bazel" + "/CLAUDE.md" + "/CONTRIBUTING.md" + "/DESIGN_PRINCIPLES.md" + "/MODULE.bazel" + "/MODULE.bazel.lock" + "/MANIFEST.in" + "/Makefile" + "/OpenCC.egg-info/" + "/PUBLICATIONS.md" + "/binding.gyp" + "/build.cmd" + "/data/icon/" + "/deps/google-benchmark/" + "/deps/pybind11-2.13.1/" + "/doc/" + "/examples/" + "/node/" + "/package.json" + "/package-lock.json" + "/patches/" + "/pyproject.toml" + "/python[^/]*/" + "/release-pypi-[^/]*" + "${PROJECT_SOURCE_DIR}/scripts/" + "/setup.py" + "/test.cmd" ) +if(OPENCC_SOURCE_PACKAGE_PROFILE STREQUAL "opencc") + set(_OPENCC_SOURCE_PACKAGE_SUFFIX "-opencc-src") + set(_OPENCC_SOURCE_PACKAGE_IGNORE_FILES + ${_OPENCC_TRIMMED_SOURCE_PACKAGE_IGNORE_FILES} + "/plugins/" + ) +elseif(OPENCC_SOURCE_PACKAGE_PROFILE STREQUAL "opencc-jieba") + set(CPACK_SOURCE_PACKAGE_FILE_NAME + "opencc-jieba-${OPENCC_VERSION_MAJOR}.${OPENCC_VERSION_MINOR}.${OPENCC_VERSION_REVISION}-src" + ) + set(_OPENCC_SOURCE_PACKAGE_IGNORE_FILES + ${_OPENCC_TRIMMED_SOURCE_PACKAGE_IGNORE_FILES} + "/plugins/jieba/node/" + ) +elseif(NOT OPENCC_SOURCE_PACKAGE_PROFILE STREQUAL "full") + message(FATAL_ERROR "OPENCC_SOURCE_PACKAGE_PROFILE must be 'full', 'opencc', or 'opencc-jieba'.") +endif() + +if(NOT CPACK_SOURCE_PACKAGE_FILE_NAME) + set(CPACK_SOURCE_PACKAGE_FILE_NAME + "${PACKAGE_NAME}-${OPENCC_VERSION_MAJOR}.${OPENCC_VERSION_MINOR}.${OPENCC_VERSION_REVISION}${_OPENCC_SOURCE_PACKAGE_SUFFIX}" + ) +endif() set(CPACK_SOURCE_IGNORE_FILES - "/build/;/test/dict.ocd;/test/dict.txt;/test/dict.bin;/other/;/opencc.xcodeproj/;/.git/;.gitignore;~$;.pyc;/bazel*;/node_modules;/.github;/.pytest_cache;/.vscode;${CPACK_SOURCE_IGNORE_FILES}" + "/build[^/]*/;/test/dict.ocd;/test/dict.txt;/test/dict.bin;/dict.ocd;/.DS_Store;/.zig-[^/]*/;/dist[^/]*/;/other/;/opencc.xcodeproj/;/.git/;.gitignore;~$;.pyc;/bazel*;/node_modules;/.github;/.pytest_cache;/.vscode;/packaging/;${_OPENCC_SOURCE_PACKAGE_IGNORE_FILES};${CPACK_SOURCE_IGNORE_FILES}" ) include(CPack) @@ -283,10 +342,22 @@ endif() ######## Subdirectories add_subdirectory(src) -add_subdirectory(doc) +if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/doc/CMakeLists.txt") + add_subdirectory(doc) +elseif(BUILD_DOCUMENTATION) + message(FATAL_ERROR "BUILD_DOCUMENTATION requires the doc source directory.") +endif() add_subdirectory(data) -add_subdirectory(plugins) -add_subdirectory(test) +if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/plugins/CMakeLists.txt") + add_subdirectory(plugins) +elseif(BUILD_OPENCC_JIEBA_PLUGIN) + message(FATAL_ERROR "BUILD_OPENCC_JIEBA_PLUGIN requires the plugins source directory.") +endif() +if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/test/CMakeLists.txt") + add_subdirectory(test) +elseif(ENABLE_GTEST) + message(FATAL_ERROR "ENABLE_GTEST requires the test source directory.") +endif() if (ENABLE_BENCHMARK AND TARGET performance AND TARGET opencc_jieba) target_compile_definitions(performance PRIVATE @@ -307,6 +378,9 @@ endif() ######## Testing if (ENABLE_GTEST) + if(NOT USE_SYSTEM_GTEST AND NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/deps/googletest-1.15.0/CMakeLists.txt") + message(FATAL_ERROR "ENABLE_GTEST with bundled GoogleTest requires deps/googletest-1.15.0.") + endif() if(NOT USE_SYSTEM_GTEST) add_subdirectory(deps/googletest-1.15.0) endif() @@ -314,6 +388,9 @@ if (ENABLE_GTEST) endif() if (ENABLE_BENCHMARK) + if(NOT USE_SYSTEM_GOOGLE_BENCHMARK AND NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/deps/google-benchmark/CMakeLists.txt") + message(FATAL_ERROR "ENABLE_BENCHMARK with bundled Google Benchmark requires deps/google-benchmark.") + endif() set(BENCHMARK_ENABLE_TESTING OFF) if(NOT USE_SYSTEM_GOOGLE_BENCHMARK) add_subdirectory(deps/google-benchmark) @@ -327,6 +404,9 @@ if (BUILD_PYTHON) if(USE_SYSTEM_PYBIND11) find_package(pybind11 CONFIG) else() + if(NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/deps/pybind11-2.13.1/CMakeLists.txt") + message(FATAL_ERROR "BUILD_PYTHON with bundled pybind11 requires deps/pybind11-2.13.1.") + endif() add_subdirectory(deps/pybind11-2.13.1) endif() pybind11_add_module(opencc_clib src/py_opencc.cpp) diff --git a/packaging/debian/README.md b/packaging/debian/README.md new file mode 100644 index 000000000..bb725d297 --- /dev/null +++ b/packaging/debian/README.md @@ -0,0 +1,59 @@ +# Debian Packaging Patch Mirror + +This directory tracks the Debian-specific patch queue for OpenCC so upstream +maintainers can review Debian packaging deltas before a release. + +Current baseline: + +- Debian source package: `opencc 1.3.1+ds1-3` +- Patch index: + `https://udd.debian.org/patches.cgi?src=opencc&version=1.3.1%2Bds1-3` + +Intent: + +- Keep Debian packaging deltas visible to upstream maintainers. +- Identify patches that can be replaced by upstream-supported build options. +- Make release-time Debian coordination easier. + +This directory is not authoritative Debian packaging. Debian maintainers should +continue to use the Debian Salsa repository and the Debian source package as the +source of truth. + +Source package handling: + +- `CMakeLists.txt` excludes `/packaging/` from CPack source archives. +- `package.json` uses an npm `files` whitelist, so this directory is not packed + into the npm package. +- GitHub's autogenerated "Source code" archives include all tracked files and + cannot be filtered by repository metadata. Use the CPack-generated source + archive for release assets when this directory must be excluded. + +CPack source package profiles: + +- The default `OPENCC_SOURCE_PACKAGE_PROFILE=full` keeps the existing source + package behavior. +- `OPENCC_SOURCE_PACKAGE_PROFILE=opencc` produces a C++-focused source archive + named `opencc--opencc-src.*`. It excludes Node.js, Python, Doxygen + documentation sources, Jieba plugin sources, benchmark-only dependencies, and + packaging metadata. Core C++ tests and bundled GoogleTest are kept so + maintainers can run `ctest` after configuring with `ENABLE_GTEST=ON`. +- `OPENCC_SOURCE_PACKAGE_PROFILE=opencc-jieba` produces a Jieba plugin-focused + source archive named `opencc-jieba--src.*`. It keeps the OpenCC C++ + core and the Jieba plugin sources, but excludes Node.js, Python, Doxygen + documentation sources, benchmark-only dependencies, and packaging metadata. + Core C++ tests, bundled GoogleTest, and Jieba integration tests are kept so + maintainers can run `ctest` after configuring with `ENABLE_GTEST=ON`. + +Example: + +```sh +cmake -S . -B build-opencc-src -DOPENCC_SOURCE_PACKAGE_PROFILE=opencc +cmake --build build-opencc-src --target package_source + +cmake -S . -B build-opencc-jieba-src -DOPENCC_SOURCE_PACKAGE_PROFILE=opencc-jieba +cmake --build build-opencc-jieba-src --target package_source +``` + +CPack source archives are generated from the filesystem, not from `git archive`. +Create release archives from a clean checkout so untracked local files cannot be +included accidentally. diff --git a/packaging/debian/patches/0003-no-remote-images-when-reading-docs-on-disk.patch b/packaging/debian/patches/0003-no-remote-images-when-reading-docs-on-disk.patch new file mode 100644 index 000000000..1445948e5 --- /dev/null +++ b/packaging/debian/patches/0003-no-remote-images-when-reading-docs-on-disk.patch @@ -0,0 +1,32 @@ +From: Gunnar Hjalmarsson +Date: Sun, 28 Jul 2024 19:42:55 -0400 +Subject: Don't fetch remote images when reading docs on disk + +This fixes a privacy breach previously reported as Lintian warnings + +Forwarded: not-needed +Reviewed-by: xiao sheng wen +Last-Update: 2026-04-25 +--- +diff --git a/README.md b/README.md +index 9934199..71ca706 100644 +--- a/README.md ++++ b/README.md +@@ -1,17 +1,7 @@ + # Open Chinese Convert 開放中文轉換 + +-[![CMake](https://github.com/BYVoid/OpenCC/actions/workflows/cmake.yml/badge.svg)](https://github.com/BYVoid/OpenCC/actions/workflows/cmake.yml) +-[![Bazel](https://github.com/BYVoid/OpenCC/actions/workflows/bazel.yml/badge.svg)](https://github.com/BYVoid/OpenCC/actions/workflows/bazel.yml) +-[![MSVC](https://github.com/BYVoid/OpenCC/actions/workflows/msvc.yml/badge.svg)](https://github.com/BYVoid/OpenCC/actions/workflows/msvc.yml) +-[![Node.js CI](https://github.com/BYVoid/OpenCC/actions/workflows/nodejs.yml/badge.svg)](https://github.com/BYVoid/OpenCC/actions/workflows/nodejs.yml) +-[![Python CI](https://github.com/BYVoid/OpenCC/actions/workflows/python.yml/badge.svg)](https://github.com/BYVoid/OpenCC/actions/workflows/python.yml) +-[![AppVeyor](https://img.shields.io/appveyor/ci/Carbo/OpenCC.svg)](https://ci.appveyor.com/project/Carbo/OpenCC) +- +-[![latest packaged version(s)](https://repology.org/badge/latest-versions/opencc.svg)](https://repology.org/project/opencc/versions) +- + ## Introduction 介紹 + +-![OpenCC](https://opencc.byvoid.com/img/opencc.png) + + Open Chinese Convert (OpenCC, 開放中文轉換) is an opensource project for conversions between Traditional Chinese, Simplified Chinese and Japanese Kanji (Shinjitai). It supports character-level and phrase-level conversion, character variant conversion and regional idioms among Mainland China, Taiwan and Hong Kong. This is not translation tool between Mandarin and Cantonese, etc. + diff --git a/packaging/debian/patches/0004-Use-system-googletest.patch b/packaging/debian/patches/0004-Use-system-googletest.patch new file mode 100644 index 000000000..f1728d0de --- /dev/null +++ b/packaging/debian/patches/0004-Use-system-googletest.patch @@ -0,0 +1,23 @@ +From: Shengjing Zhu +Date: Sun, 28 Jul 2024 19:44:27 -0400 +Subject: Use system googletest + +Forwarded: not-needed +Last-Update: 2024-07-28 +--- + CMakeLists.txt | 2 ++ + 1 file changed, 2 insertions(+) + +diff --git a/CMakeLists.txt b/CMakeLists.txt +index 0fdb13f..0cda6ea 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -235,6 +235,8 @@ add_subdirectory(test) + if (ENABLE_GTEST) + if(NOT USE_SYSTEM_GTEST) + add_subdirectory(deps/googletest-1.15.0) ++ else() ++ add_subdirectory(/usr/src/googletest/googletest ${CMAKE_BINARY_DIR}/googletest-build EXCLUDE_FROM_ALL) + endif() + enable_testing() + endif() diff --git a/packaging/debian/patches/0005-Disable-build-in-setup.py.patch b/packaging/debian/patches/0005-Disable-build-in-setup.py.patch new file mode 100644 index 000000000..fc9dbf0de --- /dev/null +++ b/packaging/debian/patches/0005-Disable-build-in-setup.py.patch @@ -0,0 +1,20 @@ +From: Shengjing Zhu +Date: Fri, 2 Aug 2024 17:11:08 +0800 +Subject: Disable build in setup.py + +--- + setup.py | 1 + + 1 file changed, 1 insertion(+) + +diff --git a/setup.py b/setup.py +index d6b5b90..5c46dbd 100644 +--- a/setup.py ++++ b/setup.py +@@ -63,6 +63,7 @@ def get_long_description(): + + + def build_libopencc(output_path): ++ return + print('building libopencc into %s' % _build_dir) + + is_windows = sys.platform == 'win32' diff --git a/packaging/debian/patches/0009-setup.py-Handle-python-binding-instead-of-cmake.patch b/packaging/debian/patches/0009-setup.py-Handle-python-binding-instead-of-cmake.patch new file mode 100644 index 000000000..458eaceb9 --- /dev/null +++ b/packaging/debian/patches/0009-setup.py-Handle-python-binding-instead-of-cmake.patch @@ -0,0 +1,55 @@ +From: Boyuan Yang +Date: Tue, 13 Jan 2026 18:04:57 -0500 +Subject: setup.py: Handle python binding instead of cmake + +--- + setup.py | 22 +++++++++++++++++----- + 1 file changed, 17 insertions(+), 5 deletions(-) + +diff --git a/setup.py b/setup.py +index 5c46dbd..ac443db 100644 +--- a/setup.py ++++ b/setup.py +@@ -9,6 +9,8 @@ import setuptools + import setuptools.command.build_ext + import wheel.bdist_wheel + ++import pybind11 ++ + _this_dir = os.path.dirname(os.path.abspath(__file__)) + _build_dir = os.path.join(_this_dir, 'build', 'python') + +@@ -112,10 +114,13 @@ class OpenCCExtension(setuptools.Extension, object): + + class BuildExtCommand(setuptools.command.build_ext.build_ext, object): + def build_extension(self, ext): +- if self.inplace: +- output_path = os.path.join(_this_dir, 'python', 'opencc', 'clib') +- else: +- output_path = os.path.abspath(os.path.join(self.build_lib, 'opencc', 'clib')) ++ project_root = os.path.abspath(_this_dir) ++ build_dir = os.environ.get('OPENCC_BUILD_DIR', 'obj-x86_64-linux-gnu') ++ lib_path = os.path.join(project_root, build_dir, 'src') ++ ext.include_dirs.append(pybind11.get_include()) ++ ext.include_dirs.append('src') ++ ext.library_dirs = [lib_path] ++ ext.runtime_library_dirs = [lib_path] + if isinstance(ext, OpenCCExtension): + build_libopencc(output_path) + else: +@@ -179,7 +184,14 @@ setuptools.setup( + + packages=packages, + package_dir={'opencc': 'python/opencc'}, +- ext_modules=[OpenCCExtension('opencc.clib.opencc_clib', 'python')], ++ ext_modules=[ ++ setuptools.Extension( ++ 'opencc.clib.opencc_clib', ++ sources=['src/py_opencc.cpp'], ++ libraries=['opencc'], ++ language='c++' ++ ) ++ ], + cmdclass={ + 'build_ext': BuildExtCommand, + 'bdist_wheel': BDistWheelCommand, diff --git a/packaging/debian/patches/series b/packaging/debian/patches/series new file mode 100644 index 000000000..f14e5402d --- /dev/null +++ b/packaging/debian/patches/series @@ -0,0 +1,5 @@ +0003-no-remote-images-when-reading-docs-on-disk.patch +0004-Use-system-googletest.patch +0005-Disable-build-in-setup.py.patch +0009-setup.py-Handle-python-binding-instead-of-cmake.patch +