Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:bug: Preserve mobile kernels and assets during release cleanup

Danielb096c60e43be
diff --git a/docs/RELEASE-VERIFICATION.zh-CN.md b/docs/RELEASE-VERIFICATION.zh-CN.md
index 912c820048..cf083c9a9e 100644
--- a/docs/RELEASE-VERIFICATION.zh-CN.md
+++ b/docs/RELEASE-VERIFICATION.zh-CN.md
@@ -234,7 +234,7 @@ python -X utf8 scripts/clean-release.py
python -X utf8 scripts/clean-release.py --execute
```
-脚本清理发布脚本留下的系统临时构建目录、本地及 WSL 的 `app/build`、Linux 内核目录、鸿蒙生成的内核及头文件,以及 Android、鸿蒙工程中的构建输出和复制进去的内核、资源包。桌面 `siyuan` 始终保留;受 Git 管理的文件(包括鸿蒙公共头文件)、源码、签名配置、依赖和工具缓存、开发前端 `app/stage/build` 均保留。清理后再次打包需要重新生成内核和移动端资源包。
+脚本清理发布脚本留下的系统临时构建目录、本地及 WSL 的 `app/build`、Linux 内核目录,以及 Android、鸿蒙工程中的构建输出。保留 Android 工程中的 `app/libs/kernel.aar`、`app/src/main/assets/app.zip`,保留鸿蒙工程中的 `entry/libs/` 内核库及头文件、`entry/src/main/cpp/include/` 公共头文件和 `entry/src/main/resources/rawfile/app.zip`,同时保留本地及 WSL 的 `kernel/harmony/` 内核库及头文件。桌面 `siyuan`、受 Git 管理的文件、源码、签名配置、依赖和工具缓存、开发前端 `app/stage/build` 均保留。系统临时构建目录中的副本仍随临时目录清理,不影响移动端工程中已复制的文件。
自定义过构建参数时,清理时传入相同的 `--android-dir`、`--harmony-dir`、`--wsl-distro`、`--wsl-user`、`--wsl-repo`;使用自定义收集目录时,必须同时传入 `--output` 保护该目录,使用自定义记录目录时传入相同的 `--records-dir`。默认的 `release-records` 发布记录始终保留。`--skip-wsl` 可只清理 Windows 本地。脚本拒绝越界路径、与保留目录重叠的目标以及自身或上级为链接的清理入口;构建目录内部的符号链接和目录联接只删除链接本身,不清理其指向的目录。不会清理其他电脑上的 macOS 或 iOS 构建产物。
diff --git a/scripts/clean-release.py b/scripts/clean-release.py
index 0e778924c9..b9ccb3b922 100644
--- a/scripts/clean-release.py
+++ b/scripts/clean-release.py
@@ -17,20 +17,16 @@ SPEC = importlib.util.spec_from_file_location("build_release", ROOT / "scripts/b
BUILD = importlib.util.module_from_spec(SPEC)
SPEC.loader.exec_module(BUILD)
-# 只列出发布构建写入的位置,不使用 git clean,也不清理开发前端或工具缓存。
+# 只清理构建输出,保留移动端内核、资源包及头文件,不使用 git clean。
MAIN_OUTPUTS = (
"app/build", "app/kernel-linux", "app/kernel-linux-arm64",
- "kernel/harmony/libkernel.so", "kernel/harmony/libkernel.h",
)
ANDROID_OUTPUTS = (
"build", "app/build", "app/build-release", "app/.cxx",
- "app/libs/kernel.aar", "app/src/main/assets/app.zip",
)
HARMONY_OUTPUTS = (
"build", "entry/build", "entry/.cxx",
- "entry/src/main/resources/rawfile/app.zip",
-) + tuple(f"entry/libs/{abi}/{name}" for abi in ("arm64-v8a", "x86_64")
- for name in ("libkernel.so", "libkernel.h", "lan_sync_bridge.h"))
+)
class CleanupError(Exception):
diff --git a/scripts/test_clean_release.py b/scripts/test_clean_release.py
index 86e7135b67..d842e6dcd5 100644
--- a/scripts/test_clean_release.py
+++ b/scripts/test_clean_release.py
@@ -1,4 +1,5 @@
import contextlib
+import argparse
import importlib.util
import io
import os
@@ -111,6 +112,41 @@ class CleanupTests(unittest.TestCase):
self.assertTrue((self.build / "release.app").exists())
self.assertFalse(untracked.exists())
+ def test_mobile_inputs_survive_cleanup_while_build_outputs_are_removed(self):
+ main = self.root / "main"
+ android = self.root / "android"
+ harmony = self.root / "harmony"
+ temporary = self.root / "temporary"
+ temporary.mkdir()
+ preserved = {
+ main: ["kernel/kernel.aar", "kernel/harmony/libkernel.so", "kernel/harmony/libkernel.h"],
+ android: ["app/libs/kernel.aar", "app/src/main/assets/app.zip"],
+ harmony: ["entry/src/main/resources/rawfile/app.zip", "entry/src/main/cpp/include/libkernel.h",
+ "entry/src/main/cpp/include/lan_sync_bridge.h"] +
+ [f"entry/libs/{abi}/{name}" for abi in ("arm64-v8a", "x86_64")
+ for name in ("libkernel.so", "libkernel.h", "lan_sync_bridge.h")],
+ }
+ outputs = {main: ["app/build", "app/kernel-linux", "app/kernel-linux-arm64"],
+ android: ["build", "app/build", "app/build-release", "app/.cxx"],
+ harmony: ["build", "entry/build", "entry/.cxx"]}
+ for repo, marker in ((main, "kernel/go.mod"), (android, "build.gradle"), (harmony, "AppScope/app.json5")):
+ for relative in [marker] + preserved[repo] + [path + "/output.bin" for path in outputs[repo]]:
+ path = repo / relative
+ path.parent.mkdir(parents=True, exist_ok=True)
+ path.write_bytes(b"preserved content")
+ args = argparse.Namespace(android_dir=android, harmony_dir=harmony, skip_wsl=True)
+ with patch.object(CLEAN, "ROOT", main), patch.object(CLEAN.tempfile, "gettempdir", return_value=str(temporary)), \
+ patch.object(CLEAN.subprocess, "run", return_value=subprocess.CompletedProcess([], 0, stdout=b"")), \
+ contextlib.redirect_stdout(io.StringIO()):
+ targets = CLEAN.collect_targets(args)
+ CLEAN.clean(targets, [self.output], execute=True)
+ for repo, relatives in preserved.items():
+ for relative in relatives:
+ self.assertEqual((repo / relative).read_bytes(), b"preserved content")
+ for repo, relatives in outputs.items():
+ for relative in relatives:
+ self.assertFalse((repo / relative).exists())
+
if __name__ == "__main__":
unittest.main()