Files
msime-windows/scripts/format.sh
T
Jia Sui 72c1d7ddb0 fix(engine): darts-clone 登记为 vendored 副本,脱离格式门禁
0976c307 随octagram 读取端入库的 darts-clone 0.32h 不在 format.sh 的排除名单里,
而它整份文件都不符合仓里的 .clang-format,本分支一旦推上去 CI 的
Check formatting 就会报 1826 处违规。

按精确路径排除 darts.h,不按目录:同目录的 octagram_gram.{h,cpp} 是我们自己的
代码,必须继续受门禁管,目录级排除会连带把它们一起豁免掉。

与上游 v0.32h(87b71afd)比对后确认这份副本并非原样入库,而是带 6 处本地改动
——open() 删掉 256 单元头部校验与两段式读、save() 删掉 offset 参数、
commonLongestPrefixSearch 整体删除、DoubleArrayBuilder 三个常量改为
static const std::size_t、一处注释拼写。这些此前没有任何地方记录,是它掉出
名单却一直没被发现的原因;逐条写进 UPSTREAM.md,升级 darts-clone 时才能重放。
前两条与 mmap 装载自洽(octagram_gram 走 set_array,不经过 open/save)。

两份 AGENTS.md 里硬编码的「那三个上游副本」清单同步为四个。
2026-10-02 22:00:36 +08:00

76 lines
3.4 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
# Formatting has to be reproducible across contributor machines and CI, so the
# formatter version is pinned here and installed from PyPI instead of being
# taken from whatever the host toolchain happens to ship. Apple, Debian and
# LLVM upstream all disagree about clang-format defaults between releases.
#
# Ported from MSIME-Linux, which has run this in CI since before the
# consolidation. Each component keeps its own .clang-format; --style=file picks
# up the nearest one, so server/, windows/, ui/, log/ and engine/ stay
# independent -- engine/voice/.clang-format widens the column limit for that
# subtree alone, and the nearest-file rule is what keeps it that way.
clang_format_version=18.1.8
project_root=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)
venv_root=${METASEQUOIA_CLANG_FORMAT_VENV:-"${TMPDIR:-/tmp}/metasequoia-clang-format-$clang_format_version"}
clang_format="$venv_root/bin/clang-format"
if [[ ! -x "$clang_format" ]]; then
python3 -m venv "$venv_root"
"$venv_root/bin/pip" install --quiet "clang-format==$clang_format_version"
fi
mode=${1:---write}
case "$mode" in
--check) clang_format_arguments=(--dry-run --Werror) ;;
--write) clang_format_arguments=(-i) ;;
*)
echo "Usage: ${BASH_SOURCE[0]} [--check|--write]" >&2
exit 2
;;
esac
cd "$project_root"
# --others --exclude-standard so a newly written file that has not been staged
# yet is still formatted. Without it the script reports a clean tree while
# skipping exactly the file being worked on.
#
# vendor/ and experiments/ are excluded: the first is third-party, the second is
# a scratch project that is not part of the shipped product.
#
# engine/ is covered here rather than by a script of its own. It used to be a
# separate repository with its own formatting gate; now that it is a directory
# of this one, a Windows-specific fix to it has to be held to the same standard
# as the code that calls it, and one entry point is what makes that automatic.
# The exclusions below are the ones that gate carried:
#
# - googlepinyinime-rev keeps its AOSP formatting, and ngram/kenlm and utfcpp
# are upstream copies, so none of them is ours to reformat; same for
# */third_party/ (miniaudio).
# - The four generated headers are emitted from JSON by
# contracts/{assets,dictionary,punctuation,webview}/generate.py, and CI
# re-runs each generator with --check. Reformatting the checked-in copy
# would only make it disagree with what the generator produces.
# - ngram/octagram/darts.h is darts-clone itself, listed by exact path rather
# than by directory the way the other copies are: its siblings in that
# directory are ours (octagram_gram.{h,cpp}) and stay under the gate.
git ls-files --cached --others --exclude-standard \
'server/*.cpp' 'server/*.h' \
'windows/*.cpp' 'windows/*.h' \
'ui/*.cpp' 'ui/*.h' \
'log/*.cpp' 'log/*.h' \
'engine/*.cpp' 'engine/*.h' 'engine/*.hpp' \
| grep -v '/vendor/' \
| grep -vE '^engine/(googlepinyinime-rev|ngram/kenlm|utfcpp)/' \
| grep -v '/third_party/' \
| grep -vxF \
-e engine/contracts/assets/assets.h \
-e engine/contracts/dictionary/format.h \
-e engine/contracts/punctuation/policy.h \
-e engine/contracts/webview/schema.h \
-e engine/ngram/octagram/darts.h \
| sort -u \
| xargs "$clang_format" "${clang_format_arguments[@]}" --style=file