ohos-devloop 0.1.2__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- ohos_devloop/__init__.py +2 -0
- ohos_devloop/_version.py +24 -0
- ohos_devloop/agents/skills/collab-delegate/SKILL.md +79 -0
- ohos_devloop/agents/skills/loop-iterate/SKILL.md +54 -0
- ohos_devloop/agents/skills/openharmony-ci/SKILL.md +71 -0
- ohos_devloop/agents/skills/openharmony-ci/agents/openai.yaml +4 -0
- ohos_devloop/agents/skills/openharmony-ci/scripts/openharmony_ci.py +520 -0
- ohos_devloop/agents/skills/pool-status/SKILL.md +47 -0
- ohos_devloop/config/e2e-cases.yaml +31 -0
- ohos_devloop/config/e2e-hap.yaml +54 -0
- ohos_devloop/config/inventory-template.yaml +35 -0
- ohos_devloop/config/inventory.yaml +68 -0
- ohos_devloop/config/report-templates/analysis-report.md +48 -0
- ohos_devloop/config/report-templates/impl-report.md +47 -0
- ohos_devloop/config/task-template.md +21 -0
- ohos_devloop/config/tdd-board.yaml +31 -0
- ohos_devloop/config/tdd-coverage.yaml +47 -0
- ohos_devloop/config/tdd-emulator.yaml +36 -0
- ohos_devloop/config/tdd-host.yaml +26 -0
- ohos_devloop/config/tdd-suites.yaml +34 -0
- ohos_devloop/config/templates/agents-user.md +11 -0
- ohos_devloop/config/templates/quickstart.md +82 -0
- ohos_devloop/config/verify.yaml +45 -0
- ohos_devloop/examples/anchor-e2e.yaml +55 -0
- ohos_devloop/examples/assert-smoke.yaml +33 -0
- ohos_devloop/examples/diffcov-fixture/cov.json +6688 -0
- ohos_devloop/examples/diffcov-fixture/diff.txt +24 -0
- ohos_devloop/examples/diffcov-smoke.yaml +32 -0
- ohos_devloop/examples/e2e-emu-smoke.yaml +45 -0
- ohos_devloop/examples/layout-fixture.norm.json +1 -0
- ohos_devloop/examples/smoke.yaml +27 -0
- ohos_devloop/ohos_cli.py +131 -0
- ohos_devloop/scripts/agent-run-v3.sh +149 -0
- ohos_devloop/scripts/apply.py +1448 -0
- ohos_devloop/scripts/check_env.py +284 -0
- ohos_devloop/scripts/collab.py +303 -0
- ohos_devloop/scripts/diffcov.py +211 -0
- ohos_devloop/scripts/flash.py +511 -0
- ohos_devloop/scripts/mount_ws.py +192 -0
- ohos_devloop/scripts/release.py +2645 -0
- ohos_devloop/scripts/release_audit.py +260 -0
- ohos_devloop/scripts/release_metadata.py +397 -0
- ohos_devloop/scripts/release_smoke.py +287 -0
- ohos_devloop/scripts/report_draft.py +234 -0
- ohos_devloop/scripts/server_init.py +310 -0
- ohos_devloop/scripts/sgrep.py +82 -0
- ohos_devloop/scripts/sign_hap.py +256 -0
- ohos_devloop/scripts/telemetry.py +260 -0
- ohos_devloop/scripts/ui_probe.py +396 -0
- ohos_devloop/scripts/verify_frame_diff.py +138 -0
- ohos_devloop/scripts/ws_init.py +131 -0
- ohos_devloop/scripts/wsroot.py +192 -0
- ohos_devloop-0.1.2.dist-info/METADATA +177 -0
- ohos_devloop-0.1.2.dist-info/RECORD +58 -0
- ohos_devloop-0.1.2.dist-info/WHEEL +5 -0
- ohos_devloop-0.1.2.dist-info/entry_points.txt +2 -0
- ohos_devloop-0.1.2.dist-info/licenses/LICENSE +202 -0
- ohos_devloop-0.1.2.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,310 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
# -*- coding: utf-8 -*-
|
|
3
|
+
"""服务器侧部署与验收(ROADMAP M6 第一优先)。
|
|
4
|
+
|
|
5
|
+
把「改了 agent-run-v3.sh 须手工 scp 重部署」从文档纪律变成一条命令,
|
|
6
|
+
并给新服务器 onboarding 提供体检 → 部署 → 验收的完整链路。
|
|
7
|
+
|
|
8
|
+
用法:
|
|
9
|
+
ohos-devloop server init # 体检 → 部署 worker → smoke 验收
|
|
10
|
+
ohos-devloop server check # 只体检不改动(全部远端只读探测)
|
|
11
|
+
ohos-devloop server init --server build-1 # 指定 inventory servers 条目(缺省首条)
|
|
12
|
+
ohos-devloop server init --no-smoke # 跳过 smoke 验收(频繁重部署时)
|
|
13
|
+
ohos-devloop server init --force # md5 相同也重推 agent-run-v3.sh
|
|
14
|
+
|
|
15
|
+
native 形态先行;docker 形态(内部镜像仓库就绪后)后续叠加。
|
|
16
|
+
边界:大仓工作区 provisioning 不在本命令内——领工作区/钉基线走 flash.py
|
|
17
|
+
extract → sync-repo → pool claim(依赖本机固件 manifest,见 RUNBOOK「刷机准备」)。
|
|
18
|
+
协议背景见 RUNBOOK「远端 code-worker 任务契约」。
|
|
19
|
+
"""
|
|
20
|
+
import argparse
|
|
21
|
+
import datetime
|
|
22
|
+
import hashlib
|
|
23
|
+
import os
|
|
24
|
+
import shlex
|
|
25
|
+
import subprocess
|
|
26
|
+
import sys
|
|
27
|
+
import tempfile
|
|
28
|
+
from pathlib import Path
|
|
29
|
+
|
|
30
|
+
import yaml
|
|
31
|
+
|
|
32
|
+
from collab import sh # 同目录;list 参数起子进程(Git Bash 引号/路径转换免疫)
|
|
33
|
+
import wsroot # 工作区解析(M6):inventory 归工作区;worker/smoke 是包资产
|
|
34
|
+
|
|
35
|
+
# 版本单点(D-08/G-2):正本在 ohos_cli.version(metadata → git 兜底(仅源码仓裸跑)→ unknown)。
|
|
36
|
+
# 机制 (a):插入包根后裸 import——sys.path[0]=脚本目录的裸跑形态也可解析(ws_init.py 同款样板)。
|
|
37
|
+
sys.path.insert(0, str(Path(__file__).resolve().parent.parent))
|
|
38
|
+
import ohos_cli # noqa: E402
|
|
39
|
+
tool_version = ohos_cli.version
|
|
40
|
+
|
|
41
|
+
BASE = wsroot.PKG # 工具正本仓(包资产)
|
|
42
|
+
WORKER = BASE / "scripts" / "agent-run-v3.sh"
|
|
43
|
+
SMOKE = BASE / "examples" / "smoke.yaml"
|
|
44
|
+
|
|
45
|
+
PASS = WARN = FAIL = 0
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def report(tag: str, item: str, msg: str) -> None:
|
|
49
|
+
global PASS, WARN, FAIL
|
|
50
|
+
if tag == "PASS":
|
|
51
|
+
PASS += 1
|
|
52
|
+
elif tag == "WARN":
|
|
53
|
+
WARN += 1
|
|
54
|
+
else:
|
|
55
|
+
FAIL += 1
|
|
56
|
+
print(f"[{tag}] {item} — {msg}")
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def die(msg: str) -> None:
|
|
60
|
+
print(f"ERROR: {msg}", file=sys.stderr)
|
|
61
|
+
sys.exit(2)
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def resolve(name: str) -> tuple[str, str, str, dict]:
|
|
65
|
+
"""(--server 名或首条目, user@host, port, 条目)。COLLAB_SERVER/COLLAB_PORT 环境变量
|
|
66
|
+
仍可覆盖 ssh 目标(与 collab.py 一致);smoke 验收始终按 inventory 条目名走。"""
|
|
67
|
+
inv = yaml.safe_load(wsroot.inventory_path().read_text(encoding="utf-8"))
|
|
68
|
+
servers = inv.get("servers") or {}
|
|
69
|
+
if name and name not in servers:
|
|
70
|
+
die(f"inventory 无 servers 条目: {name}(现有: {', '.join(servers) or '无'})")
|
|
71
|
+
entry_name = name or next(iter(servers), "")
|
|
72
|
+
if not entry_name:
|
|
73
|
+
die("config/inventory.yaml 无 servers 条目")
|
|
74
|
+
s = servers[entry_name]
|
|
75
|
+
tgt = os.environ.get("COLLAB_SERVER") or f"{s.get('user')}@{s.get('host')}"
|
|
76
|
+
port = os.environ.get("COLLAB_PORT") or str(s.get("port", 22))
|
|
77
|
+
return entry_name, tgt, port, s
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
def ssh(tgt: str, port: str, cmd: str, timeout: int = 60) -> tuple[int, str]:
|
|
81
|
+
rc, out, err = sh(["ssh", "-o", "ConnectTimeout=15", "-p", port, tgt, cmd], timeout=timeout)
|
|
82
|
+
return rc, out + (f"\n[stderr] {err}" if err.strip() else "")
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
def scp(tgt: str, port: str, args: list[str]) -> bool:
|
|
86
|
+
rc, _, err = sh(["scp", "-o", "ConnectTimeout=15", "-P", port, *args], timeout=300)
|
|
87
|
+
if rc != 0:
|
|
88
|
+
print(err.strip()[:400], file=sys.stderr)
|
|
89
|
+
return rc == 0
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
def md5_local(p: Path) -> str:
|
|
93
|
+
h = hashlib.md5()
|
|
94
|
+
with p.open("rb") as f:
|
|
95
|
+
for chunk in iter(lambda: f.read(1 << 16), b""):
|
|
96
|
+
h.update(chunk)
|
|
97
|
+
return h.hexdigest()
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
# 一次 SSH 往返拿全部探测项(逐项 ssh 太慢;### 分节哨兵本地解析)
|
|
101
|
+
PROBE = r'''
|
|
102
|
+
echo "###OS"; uname -srm; (. /etc/os-release 2>/dev/null && echo "$PRETTY_NAME")
|
|
103
|
+
echo "###HOME"; echo "$HOME"
|
|
104
|
+
echo "###DISK"; df -BG ~ | tail -1
|
|
105
|
+
echo "###PY"; python3 -V 2>&1
|
|
106
|
+
echo "###GIT"; git --version 2>&1
|
|
107
|
+
echo "###REPO"; command -v repo 2>/dev/null || echo MISSING
|
|
108
|
+
echo "###OC_HARD"; [ -x /root/.local/bin/opencode ] && echo OK || echo MISSING
|
|
109
|
+
echo "###OC_PATH"; command -v opencode 2>/dev/null || echo MISSING
|
|
110
|
+
echo "###WS"; ls -d GLOBPLACEHOLDER 2>/dev/null | wc -l
|
|
111
|
+
'''
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
def parse_probe(out: str) -> dict[str, str]:
|
|
115
|
+
sections: dict[str, str] = {}
|
|
116
|
+
cur = None
|
|
117
|
+
for ln in out.splitlines():
|
|
118
|
+
if ln.startswith("###"):
|
|
119
|
+
cur = ln.strip()
|
|
120
|
+
sections[cur] = ""
|
|
121
|
+
elif cur:
|
|
122
|
+
sections[cur] += ln + "\n"
|
|
123
|
+
return sections
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
def preflight(sec: dict[str, str], entry: dict) -> None:
|
|
127
|
+
os_line = sec.get("###OS", "").strip().replace("\n", " / ")
|
|
128
|
+
report("PASS" if os_line else "WARN", "服务器", os_line or "探测失败")
|
|
129
|
+
|
|
130
|
+
home = sec.get("###HOME", "").strip().splitlines()[-1].strip() if sec.get("###HOME") else ""
|
|
131
|
+
# 磁盘:worker 本身不占盘,但大仓工作区是百 GB 级——只提示不拦截
|
|
132
|
+
disk_line = sec.get("###DISK", "").strip().splitlines()[-1].strip() if sec.get("###DISK") else ""
|
|
133
|
+
avail = 0
|
|
134
|
+
for tok in disk_line.split():
|
|
135
|
+
if tok.endswith("G") and tok[:-1].isdigit():
|
|
136
|
+
avail = int(tok[:-1]) # df 输出第 4 列 Available 是首个带 G 的字段
|
|
137
|
+
break
|
|
138
|
+
if avail:
|
|
139
|
+
tag = "PASS" if avail >= 200 else "WARN"
|
|
140
|
+
report(tag, "磁盘(HOME 所在盘)", f"可用 {avail}G" + ("" if avail >= 200 else "(大仓工作区百 GB 级,偏紧)"))
|
|
141
|
+
else:
|
|
142
|
+
report("WARN", "磁盘(HOME 所在盘)", f"解析失败: {disk_line[:80]}")
|
|
143
|
+
|
|
144
|
+
py = sec.get("###PY", "").strip()
|
|
145
|
+
report("PASS" if py.startswith("Python 3") else "FAIL", "python3",
|
|
146
|
+
py or "未找到(collab.py close 改写 status.json 依赖)")
|
|
147
|
+
|
|
148
|
+
git = sec.get("###GIT", "").strip()
|
|
149
|
+
report("PASS" if git.startswith("git version") else "FAIL", "git",
|
|
150
|
+
git or "未找到(worker 分支/commit 纪律依赖)")
|
|
151
|
+
|
|
152
|
+
repo = sec.get("###REPO", "").strip()
|
|
153
|
+
report("PASS" if repo and repo != "MISSING" else "WARN", "repo 工具",
|
|
154
|
+
(f"{repo}" if repo != "MISSING" else "未找到(仅 flash.py sync-repo 需要)"))
|
|
155
|
+
|
|
156
|
+
# opencode:agent-run-v3.sh 硬编码 OPENCODE=/root/.local/bin/opencode,优先对齐该路径
|
|
157
|
+
hard = sec.get("###OC_HARD", "").strip()
|
|
158
|
+
path_ = sec.get("###OC_PATH", "").strip()
|
|
159
|
+
if hard == "OK":
|
|
160
|
+
report("PASS", "opencode", f"/root/.local/bin/opencode 在位(worker 硬编码路径)")
|
|
161
|
+
elif path_ and path_ != "MISSING":
|
|
162
|
+
report("WARN", "opencode",
|
|
163
|
+
f"在 {path_},但 agent-run-v3.sh 硬编码 OPENCODE=/root/.local/bin/opencode——"
|
|
164
|
+
f"装到该路径(或改脚本后本命令重部署)")
|
|
165
|
+
else:
|
|
166
|
+
report("FAIL", "opencode", "未安装 → worker 主通道不可用(先在服务器安装 opencode)")
|
|
167
|
+
if home and home != "/root" and hard != "OK":
|
|
168
|
+
report("WARN", "HOME 路径", f"远端 HOME={home} 非 /root,worker 硬编码路径需人工确认")
|
|
169
|
+
|
|
170
|
+
ws = sec.get("###WS", "").strip()
|
|
171
|
+
n = int(ws) if ws.isdigit() else 0
|
|
172
|
+
if n:
|
|
173
|
+
report("PASS", "大仓工作区", f"{n} 个(匹配 inventory ohos_root_glob)")
|
|
174
|
+
else:
|
|
175
|
+
report("WARN", "大仓工作区",
|
|
176
|
+
"0 个——领工作区走 flash.py extract → sync-repo → pool claim(需本机固件 manifest 钉基线)")
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
def deploy(tgt: str, port: str, force: bool, version: str) -> bool:
|
|
180
|
+
rc, out = ssh(tgt, port, "mkdir -p ~/collab/bin ~/collab/tasks ~/collab/runs && echo OK")
|
|
181
|
+
if rc != 0 or "OK" not in out:
|
|
182
|
+
report("FAIL", "目录结构", f"建 ~/collab/{{bin,tasks,runs}} 失败\n{out[:300]}")
|
|
183
|
+
return False
|
|
184
|
+
report("PASS", "目录结构", "~/collab/{bin,tasks,runs} 就位")
|
|
185
|
+
|
|
186
|
+
local_md5 = md5_local(WORKER)
|
|
187
|
+
rc, out = ssh(tgt, port, "md5sum ~/collab/bin/agent-run-v3.sh 2>/dev/null | cut -d' ' -f1")
|
|
188
|
+
remote_md5 = out.strip().splitlines()[-1].strip() if out.strip() else ""
|
|
189
|
+
if remote_md5 == local_md5 and not force:
|
|
190
|
+
report("PASS", "agent-run-v3.sh", f"远端已是最新(md5 {local_md5[:8]},--force 可强推)")
|
|
191
|
+
else:
|
|
192
|
+
if not scp(tgt, port, [str(WORKER), f"{tgt}:~/collab/bin/agent-run-v3.sh"]):
|
|
193
|
+
report("FAIL", "agent-run-v3.sh", "scp 推送失败")
|
|
194
|
+
return False
|
|
195
|
+
# 铁律 3:scp/ssh 退出码不可信,以产物 md5 回验为准
|
|
196
|
+
rc, out = ssh(tgt, port, "md5sum ~/collab/bin/agent-run-v3.sh | cut -d' ' -f1")
|
|
197
|
+
got = out.strip().splitlines()[-1].strip() if out.strip() else ""
|
|
198
|
+
if got != local_md5:
|
|
199
|
+
report("FAIL", "agent-run-v3.sh", f"推送后 md5 不符(本地 {local_md5[:8]} vs 远端 {got[:8]})")
|
|
200
|
+
return False
|
|
201
|
+
report("PASS", "agent-run-v3.sh", f"已部署且 md5 回验通过({local_md5[:8]})")
|
|
202
|
+
|
|
203
|
+
# G-1 可执行位保底:Windows 内置 scp 落 0644 的干净机器形态兜底(铁律 3:EXEC_OK
|
|
204
|
+
# 哨兵串判定,不裸信 ssh 退出码;固定字符串命令、零用户输入插值,无注入面 T-3-04)
|
|
205
|
+
rc, out = ssh(tgt, port, "chmod +x ~/collab/bin/agent-run-v3.sh && test -x ~/collab/bin/agent-run-v3.sh && echo EXEC_OK")
|
|
206
|
+
if "EXEC_OK" in out:
|
|
207
|
+
report("PASS", "可执行位", "chmod +x 就位(Windows 内置 scp 落 0644 形态保底)")
|
|
208
|
+
else:
|
|
209
|
+
report("FAIL", "可执行位", f"chmod/test -x 失败:\n{out[:300]}")
|
|
210
|
+
return False
|
|
211
|
+
|
|
212
|
+
rc, out = ssh(tgt, port, "bash -n ~/collab/bin/agent-run-v3.sh && echo SYNTAX_OK")
|
|
213
|
+
if "SYNTAX_OK" in out:
|
|
214
|
+
report("PASS", "worker 语法预检", "bash -n 通过")
|
|
215
|
+
else:
|
|
216
|
+
report("FAIL", "worker 语法预检", f"远端 bash -n 报错:\n{out[:300]}")
|
|
217
|
+
return False
|
|
218
|
+
|
|
219
|
+
# D-11c 无参直跑:解释器真执行到 usage 参数校验出口(直跑同验 +x 与 shebang,依赖可
|
|
220
|
+
# 执行位就位;A4 放宽口径:usage 行 + rc!=0,非仅语法过。agent-run-v3.sh:17 的
|
|
221
|
+
# ${1:?} 出口在一切 mkdir/构建动作之前,无参调用零副作用)
|
|
222
|
+
rc, out = ssh(tgt, port, "~/collab/bin/agent-run-v3.sh")
|
|
223
|
+
if "usage: agent-run-v3.sh" in out and rc != 0:
|
|
224
|
+
report("PASS", "worker 无参调用", "走到 usage 参数校验出口(解释器真执行)")
|
|
225
|
+
else:
|
|
226
|
+
report("FAIL", "worker 无参调用", f"未达 usage 出口(rc={rc}):\n{out[:300]}")
|
|
227
|
+
return False
|
|
228
|
+
|
|
229
|
+
# VERSION 戳:包版本(ohos_cli.version 单点,安装态可对账)+ 部署时间 + worker md5(防静默漂移)
|
|
230
|
+
ts = datetime.datetime.now().astimezone().strftime("%F %T %z")
|
|
231
|
+
content = f"{version}\ndeployed {ts} agent-run-v3.md5 {local_md5}\n"
|
|
232
|
+
rc, out = ssh(tgt, port, f"printf %s {shlex.quote(content)} > ~/collab/bin/VERSION && cat ~/collab/bin/VERSION")
|
|
233
|
+
if rc == 0 and version in out:
|
|
234
|
+
report("PASS", "VERSION 戳", f"~/collab/bin/VERSION = {version}({ts})")
|
|
235
|
+
else:
|
|
236
|
+
report("WARN", "VERSION 戳", f"写入失败(不阻塞,但远端版本不可对账)\n{out[:200]}")
|
|
237
|
+
return True
|
|
238
|
+
|
|
239
|
+
|
|
240
|
+
def run_smoke(entry_name: str) -> bool:
|
|
241
|
+
"""部署验收 = examples/smoke.yaml 跑绿(loader→执行→results.json + ssh 只读回显)。
|
|
242
|
+
smoke 缺省指 build-1;目标服务器不同时渲染一次性 spec,不动 examples/ 正本。"""
|
|
243
|
+
spec = yaml.safe_load(SMOKE.read_text(encoding="utf-8"))
|
|
244
|
+
spec_path = SMOKE
|
|
245
|
+
if (spec.get("resources") or {}).get("server") != entry_name:
|
|
246
|
+
spec.setdefault("resources", {})["server"] = entry_name
|
|
247
|
+
fd, tmp = tempfile.mkstemp(suffix=".yaml", prefix=f"smoke-{entry_name}-")
|
|
248
|
+
os.close(fd)
|
|
249
|
+
spec_path = Path(tmp)
|
|
250
|
+
spec_path.write_text(yaml.dump(spec, allow_unicode=True, sort_keys=False), encoding="utf-8")
|
|
251
|
+
print(f"(smoke spec 已按目标服务器渲染: {spec_path})")
|
|
252
|
+
print(f"--- smoke 验收(约 3 分钟,实时输出): apply.py {spec_path.name} run ---")
|
|
253
|
+
# cwd 必须是工作区:安装态收紧后若沿用包根(site-packages)作 cwd,apply 的 require_ws
|
|
254
|
+
# 会报错——PACK-05 onboarding 断链点(RESEARCH 坑位 4 / W9)
|
|
255
|
+
p = subprocess.run([sys.executable, str(BASE / "scripts" / "apply.py"), str(spec_path), "run"],
|
|
256
|
+
cwd=str(wsroot.require_ws()))
|
|
257
|
+
ok = p.returncode == 0
|
|
258
|
+
report("PASS" if ok else "FAIL", "smoke 验收",
|
|
259
|
+
"跑绿(本机→服务器全链)" if ok else f"退出码 {p.returncode}——查 runs/<id>/results.json")
|
|
260
|
+
return ok
|
|
261
|
+
|
|
262
|
+
|
|
263
|
+
def main() -> int:
|
|
264
|
+
ap = argparse.ArgumentParser(description="服务器侧部署与验收(体检 → 部署 worker → smoke)")
|
|
265
|
+
ap.add_argument("--check", action="store_true", help="只体检不改动(远端只读探测)")
|
|
266
|
+
ap.add_argument("--server", default="", help="inventory servers 条目名(缺省首条)")
|
|
267
|
+
ap.add_argument("--no-smoke", action="store_true", help="跳过 smoke 验收")
|
|
268
|
+
ap.add_argument("--force", action="store_true", help="md5 相同也重推 agent-run-v3.sh")
|
|
269
|
+
args = ap.parse_args()
|
|
270
|
+
|
|
271
|
+
name, tgt, port, entry = resolve(args.server)
|
|
272
|
+
print(f"目标服务器: {name} → {tgt}:{port}")
|
|
273
|
+
if os.environ.get("COLLAB_SERVER") and not args.server:
|
|
274
|
+
print("(COLLAB_SERVER 环境变量覆盖了 ssh 目标;smoke 验收仍按 inventory 条目走)")
|
|
275
|
+
|
|
276
|
+
glob = str(entry.get("ohos_root_glob", "")).strip()
|
|
277
|
+
probe = PROBE.replace("GLOBPLACEHOLDER", glob or "/nonexistent")
|
|
278
|
+
rc, out = ssh(tgt, port, probe)
|
|
279
|
+
if rc != 0:
|
|
280
|
+
report("FAIL", "ssh 连通", f"连不上 {tgt}:{port}——检查免密配置 / inventory 条目")
|
|
281
|
+
return 1
|
|
282
|
+
report("PASS", "ssh 连通", f"{tgt}:{port}")
|
|
283
|
+
preflight(parse_probe(out), entry)
|
|
284
|
+
|
|
285
|
+
if args.check:
|
|
286
|
+
print(f"\n体检结束: PASS={PASS} WARN={WARN} FAIL={FAIL}(--check 只读,未做任何改动)")
|
|
287
|
+
return 1 if FAIL else 0
|
|
288
|
+
|
|
289
|
+
if not deploy(tgt, port, args.force, tool_version()):
|
|
290
|
+
print(f"\n部署失败: PASS={PASS} WARN={WARN} FAIL={FAIL}")
|
|
291
|
+
return 1
|
|
292
|
+
if not args.no_smoke:
|
|
293
|
+
run_smoke(name)
|
|
294
|
+
print(f"\n完成: PASS={PASS} WARN={WARN} FAIL={FAIL}")
|
|
295
|
+
return 1 if FAIL else 0
|
|
296
|
+
|
|
297
|
+
|
|
298
|
+
if __name__ == "__main__":
|
|
299
|
+
try:
|
|
300
|
+
# line_buffering:管道/CI 捕获下子进程(apply.py)输出不与父进程乱序
|
|
301
|
+
sys.stdout.reconfigure(encoding="utf-8", errors="replace", line_buffering=True)
|
|
302
|
+
sys.stderr.reconfigure(encoding="utf-8", errors="replace", line_buffering=True)
|
|
303
|
+
except Exception:
|
|
304
|
+
pass
|
|
305
|
+
try:
|
|
306
|
+
rc = main()
|
|
307
|
+
except wsroot.WorkspaceRequiredError as e: # 安装态无工作区:引导 init,rc==2(02-02 错误出口契约;smoke 经 require_ws 取 cwd)
|
|
308
|
+
print(f"ERROR: {e}", file=sys.stderr)
|
|
309
|
+
rc = 2
|
|
310
|
+
sys.exit(rc)
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""服务器端递归搜索(主 Agent 快速定位的备用工具;改码主通道 = 远端 code-worker)。
|
|
3
|
+
|
|
4
|
+
用法:
|
|
5
|
+
ohos-devloop sgrep <pattern> [路径] [-i] [-n N]
|
|
6
|
+
pattern ERE 正则(grep -E)
|
|
7
|
+
路径 缺省 = 活跃工作区 code 根;可给仓内相对路径(如 foundation/arkui)
|
|
8
|
+
-i 忽略大小写
|
|
9
|
+
-n N 每文件最多输出 N 行(缺省 20)
|
|
10
|
+
|
|
11
|
+
输出格式与本地 grep 一致(file:line: content),供 agent 直接消费。
|
|
12
|
+
只读操作,走服务器端 grep。2026-11-09 架构回切后:改码/深度分析交远端 code-worker,
|
|
13
|
+
本脚本用于主 Agent 轻量定点搜索(递归 grep 在服务器本地跑,快且无 SSHFS 开销)。
|
|
14
|
+
"""
|
|
15
|
+
import argparse
|
|
16
|
+
import os
|
|
17
|
+
import shlex
|
|
18
|
+
import subprocess
|
|
19
|
+
import sys
|
|
20
|
+
|
|
21
|
+
import yaml
|
|
22
|
+
|
|
23
|
+
import wsroot # 工作区根解析(BL-01 回归:包内 parent.parent 语义已变,不得再当仓库根)
|
|
24
|
+
|
|
25
|
+
def pool_file():
|
|
26
|
+
"""工作区池登记文件(读语义):无工作区(安装态)时 None——轻量工具不连带 require_ws。"""
|
|
27
|
+
ws = wsroot.ws_root()
|
|
28
|
+
return (ws / "workspace_pool.yaml") if ws else None
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def server() -> tuple[str, str]:
|
|
32
|
+
"""(user@host, port)。环境变量优先(SGREP_SERVER/SGREP_PORT),缺省读 inventory.yaml
|
|
33
|
+
首个 servers 条目(collab.py server() 同款 env→inventory 链;PUB-01 占位化后包内
|
|
34
|
+
不再携带坐标常量,user 取 inventory servers 条目的 user 字段)。"""
|
|
35
|
+
target = os.environ.get("SGREP_SERVER")
|
|
36
|
+
port = os.environ.get("SGREP_PORT")
|
|
37
|
+
if not target or not port:
|
|
38
|
+
inv = yaml.safe_load(wsroot.inventory_path().read_text(encoding="utf-8"))
|
|
39
|
+
s = next(iter((inv.get("servers") or {}).values()), {})
|
|
40
|
+
user = s.get("user") or "root"
|
|
41
|
+
target = target or f"{user}@{s.get('host')}"
|
|
42
|
+
port = port or str(s.get("port", 22))
|
|
43
|
+
return target, port
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def active_ws_root() -> str:
|
|
47
|
+
pool = pool_file()
|
|
48
|
+
if pool is None or not pool.is_file():
|
|
49
|
+
raise SystemExit("workspace_pool.yaml 里没有工作区登记(先 ohos-devloop init 生成工作区)")
|
|
50
|
+
for line in pool.read_text(encoding="utf-8").splitlines():
|
|
51
|
+
if "openharmony_master_default_" in line and "/code" in line:
|
|
52
|
+
return line.split()[-1]
|
|
53
|
+
raise SystemExit("workspace_pool.yaml 里没有工作区登记")
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def main() -> int:
|
|
57
|
+
ap = argparse.ArgumentParser(add_help=False)
|
|
58
|
+
ap.add_argument("pattern")
|
|
59
|
+
ap.add_argument("path", nargs="?", default="")
|
|
60
|
+
ap.add_argument("-i", action="store_true")
|
|
61
|
+
ap.add_argument("-n", type=int, default=20)
|
|
62
|
+
args = ap.parse_args()
|
|
63
|
+
|
|
64
|
+
root = active_ws_root()
|
|
65
|
+
target = f"{root}/{args.path.strip('/')}" if args.path else root
|
|
66
|
+
srv_target, srv_port = server() # env SGREP_SERVER/SGREP_PORT → inventory servers.build-1
|
|
67
|
+
# 远端参数一律 shlex.quote(CLAUDE.md 约定):pattern/path 含引号/空格/元字符时
|
|
68
|
+
# 不得逃出字面量——手写单引号会让 `it's` 类 pattern 在服务器上以 root 执行注入段(CR-01)
|
|
69
|
+
cmd = (f"cd {shlex.quote(root)} && grep -rE{'i' if args.i else ''} -m {args.n} "
|
|
70
|
+
f"--include='*.cpp' --include='*.h' --include='*.hpp' "
|
|
71
|
+
f"--include='*.ts' --include='*.ets' --include='*.js' "
|
|
72
|
+
f"--include='*.gn' --include='*.md' "
|
|
73
|
+
f"{shlex.quote(args.pattern)} {shlex.quote(target)} 2>/dev/null | head -400")
|
|
74
|
+
p = subprocess.run(["ssh", "-p", srv_port, srv_target, cmd], capture_output=True, text=True)
|
|
75
|
+
print(p.stdout, end="")
|
|
76
|
+
if not p.stdout:
|
|
77
|
+
print("(no match)", file=sys.stderr)
|
|
78
|
+
return 0
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
if __name__ == "__main__":
|
|
82
|
+
sys.exit(main())
|
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
# -*- coding: utf-8 -*-
|
|
3
|
+
"""无账号离线签名 OpenHarmony 测试应用 HAP(devecocli build 产出 unsigned.hap 后调用)。
|
|
4
|
+
|
|
5
|
+
用法:
|
|
6
|
+
python scripts/sign_hap.py <project-dir> [--mode debug|release]
|
|
7
|
+
debug(缺省): 产出 entry-default-signed.hap —— UDID 钉死的调试 profile,需目标设备在线
|
|
8
|
+
release: 产出 entry-release-signed.hap —— 跨设备通用(无 UDID),无需设备在线
|
|
9
|
+
|
|
10
|
+
材料(首次自动生成;目录解析 SIGN_DIR 环境变量 → inventory local.sign_dir,未配置报错引导):
|
|
11
|
+
template-cert.pem [debug] 模板内嵌真证书——p12 里 "application release" 条目的证书是自签占位,不可用
|
|
12
|
+
app-chain.cer [debug] 真证书 + Application CA + Root CA 链(hap-sign-tool 要求 2~3 张的链文件)
|
|
13
|
+
debug-<bundle>.json/p7b [debug] 调试 profile:bundle 名 + 板 UDID 钉死,每次运行按当前值重建(模板 validity 已过期,须续期)
|
|
14
|
+
release-<bundle>.json/p7b [release] 发布 profile:bundle 名绑定、无设备绑定(模板 validity 已过期,须续期)
|
|
15
|
+
hapsigner-dist/OpenHarmonyApplication.pem [release] 发布证书——SDK lib 不带,取自
|
|
16
|
+
https://gitcode.com/openharmony/developtools_hapsigner/tree/master/dist(其余 release 材料 SDK 与 dist 同 checksum)
|
|
17
|
+
|
|
18
|
+
坑位全录见 RUNBOOK「测试应用」签名小节。
|
|
19
|
+
"""
|
|
20
|
+
import argparse
|
|
21
|
+
import json
|
|
22
|
+
import os
|
|
23
|
+
import re
|
|
24
|
+
import shlex
|
|
25
|
+
import subprocess
|
|
26
|
+
import sys
|
|
27
|
+
import time
|
|
28
|
+
from pathlib import Path
|
|
29
|
+
|
|
30
|
+
import yaml
|
|
31
|
+
|
|
32
|
+
import wsroot # inventory 解析(PUB-01 占位化:真实目录经工作区/仓根覆写位注入)
|
|
33
|
+
|
|
34
|
+
STUDIO = Path(os.environ.get("DEVECO_CLI_STUDIO_PATH", "C:/Program Files/Huawei/DevEco Studio"))
|
|
35
|
+
JAVA = STUDIO / "jbr/bin/java.exe"
|
|
36
|
+
KEYTOOL = STUDIO / "jbr/bin/keytool.exe"
|
|
37
|
+
LIB = STUDIO / "sdk/default/openharmony/toolchains/lib"
|
|
38
|
+
KS = LIB / "OpenHarmony.p12"
|
|
39
|
+
KS_PASS = os.environ.get("KS_PASS", "123456")
|
|
40
|
+
# HDC env 可带参数(多设备时传 'hdc.exe -t <target>';apply.py hap_sign 步骤自动注入)
|
|
41
|
+
HDC = shlex.split(os.environ.get("HDC", "C:/Program Files/oh_toolchain/toolchains/hdc.exe"))
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def sign_dir() -> Path:
|
|
45
|
+
"""签名材料目录(flash.py _local_dir 同款 env→inventory 口径):SIGN_DIR 环境变量
|
|
46
|
+
优先 → inventory local.sign_dir;<...> 占位值或缺失 = 未配置 → 报错引导
|
|
47
|
+
(PUB-01 占位化:包内不再内嵌个人路径,绝不静默用编造路径)。"""
|
|
48
|
+
v = os.environ.get("SIGN_DIR", "").strip()
|
|
49
|
+
if not v:
|
|
50
|
+
inv = yaml.safe_load(wsroot.inventory_path().read_text(encoding="utf-8")) or {}
|
|
51
|
+
v = str((inv.get("local") or {}).get("sign_dir") or "").strip()
|
|
52
|
+
if not v or v.startswith("<"):
|
|
53
|
+
die("签名材料目录未配置:设环境变量 SIGN_DIR,或在 inventory(工作区或仓根 "
|
|
54
|
+
"config/inventory.yaml 覆写位)local 段填 sign_dir(<...> 占位值不算已配置)")
|
|
55
|
+
return Path(v)
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def release_app_cert() -> Path:
|
|
59
|
+
"""release 发布证书路径(SIGN_DIR/hapsigner-dist/OpenHarmonyApplication.pem)。"""
|
|
60
|
+
return sign_dir() / "hapsigner-dist" / "OpenHarmonyApplication.pem"
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def die(msg: str) -> None:
|
|
64
|
+
print(f"ERROR: {msg}", file=sys.stderr)
|
|
65
|
+
sys.exit(2)
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def run(args: list[str], what: str) -> str:
|
|
69
|
+
p = subprocess.run([str(a) for a in args], capture_output=True, text=True,
|
|
70
|
+
encoding="utf-8", errors="replace")
|
|
71
|
+
out = (p.stdout or "") + (p.stderr or "")
|
|
72
|
+
if p.returncode != 0:
|
|
73
|
+
die(f"{what} 失败 (rc={p.returncode}):\n{out.strip()[:1500]}")
|
|
74
|
+
return out
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def wlf(path: Path, text: str) -> None:
|
|
78
|
+
path.parent.mkdir(parents=True, exist_ok=True)
|
|
79
|
+
path.write_text(text, encoding="utf-8", newline="\n")
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
def load_unsigned(project: Path) -> Path:
|
|
83
|
+
unsigned = project / "entry/build/default/outputs/default/entry-default-unsigned.hap"
|
|
84
|
+
if not unsigned.is_file():
|
|
85
|
+
die(f"缺 {unsigned} —— 先执行: devecocli build")
|
|
86
|
+
return unsigned
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
def get_bundle(project: Path) -> str:
|
|
90
|
+
m = re.search(r'"bundleName"\s*:\s*"([^"]+)"',
|
|
91
|
+
(project / "AppScope/app.json5").read_text(encoding="utf-8"))
|
|
92
|
+
if not m:
|
|
93
|
+
die("无法从 AppScope/app.json5 解析 bundleName")
|
|
94
|
+
return m.group(1)
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
def renew_validity(profile: dict) -> dict:
|
|
98
|
+
"""模板 validity 已过期(release 模板 2023-07 / debug 模板 2024-01),必须续期。"""
|
|
99
|
+
now = int(time.time())
|
|
100
|
+
profile["validity"] = {"not-before": now - 86400, "not-after": now + 315360000}
|
|
101
|
+
return profile
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
# --------------------------------------------------------------------------- debug 路(UDID 钉死)
|
|
105
|
+
|
|
106
|
+
def sign_debug(project: Path) -> Path:
|
|
107
|
+
unsigned = load_unsigned(project)
|
|
108
|
+
bundle = get_bundle(project)
|
|
109
|
+
for f in (JAVA, KEYTOOL, KS, LIB / "UnsgnedDebugProfileTemplate.json", Path(HDC[0])):
|
|
110
|
+
if not f.is_file():
|
|
111
|
+
die(f"缺少签名依赖文件: {f}")
|
|
112
|
+
sdir = sign_dir()
|
|
113
|
+
sdir.mkdir(parents=True, exist_ok=True)
|
|
114
|
+
|
|
115
|
+
# 1) 真证书(模板内嵌;issuer=Application CA,与 p12 私钥配对)
|
|
116
|
+
template_cert = sdir / "template-cert.pem"
|
|
117
|
+
if not template_cert.exists():
|
|
118
|
+
t = json.loads((LIB / "UnsgnedDebugProfileTemplate.json").read_text(encoding="utf-8"))
|
|
119
|
+
wlf(template_cert, t["bundle-info"]["development-certificate"])
|
|
120
|
+
|
|
121
|
+
# 2) 签名链:真证书 + Application CA + Root CA(hap-sign-tool 强制链文件)
|
|
122
|
+
chain = sdir / "app-chain.cer"
|
|
123
|
+
if not chain.exists():
|
|
124
|
+
parts = [template_cert.read_text(encoding="utf-8")]
|
|
125
|
+
for alias in ("openharmony application ca", "openharmony application root ca"):
|
|
126
|
+
parts.append(run([KEYTOOL, "-exportcert", "-rfc", "-keystore", KS,
|
|
127
|
+
"-storetype", "PKCS12", "-storepass", KS_PASS, "-alias", alias],
|
|
128
|
+
f"keytool 导出 {alias}"))
|
|
129
|
+
wlf(chain, "\n".join(p.replace("\r\n", "\n").strip() + "\n" for p in parts))
|
|
130
|
+
|
|
131
|
+
# 3) 调试 profile:续期 validity + 钉当前板 UDID + 绑 bundle(每次重建,秒级)
|
|
132
|
+
udid_out = run([*HDC, "shell", "bm get --udid"], "hdc 取 UDID")
|
|
133
|
+
udid = udid_out.strip().splitlines()[-1].split(":")[-1].strip()
|
|
134
|
+
if not re.fullmatch(r"[0-9A-Fa-f]{64}", udid):
|
|
135
|
+
die(f"板 UDID 解析失败: {udid_out!r}(确认板子已连;HDC env 可带 -t 隔离多设备)")
|
|
136
|
+
body = template_cert.read_text(encoding="utf-8").replace("\r", "").replace("\n", "")
|
|
137
|
+
body = body.replace("-----BEGIN CERTIFICATE-----", "").replace("-----END CERTIFICATE-----", "").strip()
|
|
138
|
+
# 铁律:development-certificate 必须带 PEM 盔甲且主体单行,否则 sign-app 的
|
|
139
|
+
# Base64.getUrlDecoder 会被换行噎死(Illegal base64 character a)
|
|
140
|
+
cert = "-----BEGIN CERTIFICATE-----\n" + body + "\n-----END CERTIFICATE-----\n"
|
|
141
|
+
now = int(time.time())
|
|
142
|
+
profile = {
|
|
143
|
+
"version-name": "2.0.0", "version-code": 2,
|
|
144
|
+
"uuid": f"debug-{bundle}-{now}",
|
|
145
|
+
"validity": {"not-before": now - 86400, "not-after": now + 315360000},
|
|
146
|
+
"type": "debug",
|
|
147
|
+
"bundle-info": {"developer-id": "OpenHarmony", "development-certificate": cert,
|
|
148
|
+
"bundle-name": bundle, "apl": os.environ.get("SIGN_APL", "normal"), "app-feature": "hos_normal_app"},
|
|
149
|
+
"acls": {"allowed-acls": [""]},
|
|
150
|
+
"permissions": {"restricted-permissions": ["", "ohos.permission.CAPTURE_SCREEN"]},
|
|
151
|
+
"debug-info": {"device-ids": [udid], "device-id-type": "udid"},
|
|
152
|
+
"issuer": "pki_internal",
|
|
153
|
+
}
|
|
154
|
+
profile_json = sdir / f"debug-{bundle}.json"
|
|
155
|
+
profile_p7b = sdir / f"debug-{bundle}.p7b"
|
|
156
|
+
wlf(profile_json, json.dumps(profile, indent=2))
|
|
157
|
+
|
|
158
|
+
# 4) sign-profile(SDK 自带的 profile-debug 证书链)→ sign-app
|
|
159
|
+
out = run([JAVA, "-jar", LIB / "hap-sign-tool.jar", "sign-profile", "-mode", "localSign",
|
|
160
|
+
"-keyAlias", "openharmony application profile debug", "-keyPwd", KS_PASS,
|
|
161
|
+
"-profileCertFile", LIB / "OpenHarmonyProfileDebug.pem",
|
|
162
|
+
"-inFile", profile_json, "-signAlg", "SHA256withECDSA",
|
|
163
|
+
"-keystoreFile", KS, "-keystorePwd", KS_PASS, "-outFile", profile_p7b],
|
|
164
|
+
"sign-profile")
|
|
165
|
+
print(out.strip().splitlines()[-1])
|
|
166
|
+
signed = unsigned.parent / "entry-default-signed.hap"
|
|
167
|
+
out = run([JAVA, "-jar", LIB / "hap-sign-tool.jar", "sign-app", "-mode", "localSign",
|
|
168
|
+
"-keyAlias", "openharmony application release", "-keyPwd", KS_PASS,
|
|
169
|
+
"-appCertFile", chain, "-profileFile", profile_p7b,
|
|
170
|
+
"-inFile", unsigned, "-signAlg", "SHA256withECDSA",
|
|
171
|
+
"-keystoreFile", KS, "-keystorePwd", KS_PASS, "-outFile", signed],
|
|
172
|
+
"sign-app")
|
|
173
|
+
print(out.strip().splitlines()[-1])
|
|
174
|
+
if not signed.is_file():
|
|
175
|
+
die(f"签名产物未生成: {signed}")
|
|
176
|
+
print(f"signed: {signed} (bundle={bundle}, udid={udid[:16]}…)")
|
|
177
|
+
return signed
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
# --------------------------------------------------------------------------- release 路(跨设备,无需设备在线)
|
|
181
|
+
# 材料配方来自 developtools_hapsigner dist(2026-11-16 实测:verify-app 通过、
|
|
182
|
+
# rk3568 安装/启动/运行全通;x86_64_virt 模拟器装不上是镜像平台缺陷,与签名无关——
|
|
183
|
+
# 上游 issue: https://gitcode.com/openharmony/security_code_signature/issues/328)
|
|
184
|
+
|
|
185
|
+
def sign_release(project: Path) -> Path:
|
|
186
|
+
unsigned = load_unsigned(project)
|
|
187
|
+
bundle = get_bundle(project)
|
|
188
|
+
sdir = sign_dir()
|
|
189
|
+
app_cert = release_app_cert()
|
|
190
|
+
for f in (JAVA, KS, LIB / "UnsgnedReleasedProfileTemplate.json", app_cert):
|
|
191
|
+
if not f.is_file():
|
|
192
|
+
if f == app_cert:
|
|
193
|
+
die(f"缺少 release 发布证书 {f}\n"
|
|
194
|
+
f"获取:https://gitcode.com/openharmony/developtools_hapsigner/tree/master/dist\n"
|
|
195
|
+
f"下载 OpenHarmonyApplication.pem 放到该目录(其余 release 材料 SDK lib 与 dist 同 checksum)")
|
|
196
|
+
die(f"缺少签名依赖文件: {f}")
|
|
197
|
+
sdir.mkdir(parents=True, exist_ok=True)
|
|
198
|
+
|
|
199
|
+
# 1) 发布 profile:模板改 bundle-name + 续期 validity + 刷新 uuid(无设备绑定)
|
|
200
|
+
profile = json.loads((LIB / "UnsgnedReleasedProfileTemplate.json").read_text(encoding="utf-8"))
|
|
201
|
+
profile["bundle-info"]["bundle-name"] = bundle
|
|
202
|
+
renew_validity(profile)
|
|
203
|
+
profile["uuid"] = f"release-{bundle}-{int(time.time())}"
|
|
204
|
+
profile_json = sdir / f"release-{bundle}.json"
|
|
205
|
+
profile_p7b = sdir / f"release-{bundle}.p7b"
|
|
206
|
+
wlf(profile_json, json.dumps(profile, indent=2))
|
|
207
|
+
|
|
208
|
+
# 2) sign-profile(release 链)→ sign-app(OpenHarmonyApplication.pem 发布证书)
|
|
209
|
+
out = run([JAVA, "-jar", LIB / "hap-sign-tool.jar", "sign-profile", "-mode", "localSign",
|
|
210
|
+
"-keyAlias", "openharmony application profile release", "-keyPwd", KS_PASS,
|
|
211
|
+
"-profileCertFile", LIB / "OpenHarmonyProfileRelease.pem",
|
|
212
|
+
"-inFile", profile_json, "-signAlg", "SHA256withECDSA",
|
|
213
|
+
"-keystoreFile", KS, "-keystorePwd", KS_PASS, "-outFile", profile_p7b],
|
|
214
|
+
"sign-profile")
|
|
215
|
+
print(out.strip().splitlines()[-1])
|
|
216
|
+
signed = unsigned.parent / "entry-release-signed.hap"
|
|
217
|
+
out = run([JAVA, "-jar", LIB / "hap-sign-tool.jar", "sign-app", "-mode", "localSign",
|
|
218
|
+
"-keyAlias", "openharmony application release", "-keyPwd", KS_PASS,
|
|
219
|
+
"-appCertFile", app_cert, "-profileFile", profile_p7b,
|
|
220
|
+
"-inFile", unsigned, "-signAlg", "SHA256withECDSA",
|
|
221
|
+
"-keystoreFile", KS, "-keystorePwd", KS_PASS, "-outFile", signed],
|
|
222
|
+
"sign-app")
|
|
223
|
+
print(out.strip().splitlines()[-1])
|
|
224
|
+
if not signed.is_file():
|
|
225
|
+
die(f"签名产物未生成: {signed}")
|
|
226
|
+
|
|
227
|
+
# 3) verify-app 自检(release 材料出问题在这一步暴露,不占设备)
|
|
228
|
+
out = run([JAVA, "-jar", LIB / "hap-sign-tool.jar", "verify-app",
|
|
229
|
+
"-outCertChain", sdir / "verify-out.cer",
|
|
230
|
+
"-outProfile", sdir / "verify-out.p7b", "-inFile", signed],
|
|
231
|
+
"verify-app")
|
|
232
|
+
print(out.strip().splitlines()[-1])
|
|
233
|
+
print(f"signed: {signed} (bundle={bundle}, release, 无设备绑定)")
|
|
234
|
+
return signed
|
|
235
|
+
|
|
236
|
+
|
|
237
|
+
def main() -> int:
|
|
238
|
+
ap = argparse.ArgumentParser(description="OpenHarmony 测试应用离线签名(debug/release)")
|
|
239
|
+
ap.add_argument("project", help="应用工程根(含 AppScope/app.json5)")
|
|
240
|
+
ap.add_argument("--mode", choices=("debug", "release"), default="debug",
|
|
241
|
+
help="debug=UDID 钉死调试 profile(缺省);release=跨设备通用,无需设备在线")
|
|
242
|
+
args = ap.parse_args()
|
|
243
|
+
project = Path(args.project).resolve()
|
|
244
|
+
if not (project / "AppScope/app.json5").is_file():
|
|
245
|
+
die(f"不是应用工程根(缺 AppScope/app.json5): {project}")
|
|
246
|
+
sign_release(project) if args.mode == "release" else sign_debug(project)
|
|
247
|
+
print("next: devecocli run --skip-build")
|
|
248
|
+
return 0
|
|
249
|
+
|
|
250
|
+
|
|
251
|
+
if __name__ == "__main__":
|
|
252
|
+
try:
|
|
253
|
+
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
|
|
254
|
+
except Exception:
|
|
255
|
+
pass
|
|
256
|
+
sys.exit(main())
|