Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9cd697826b | ||
|
|
31d246f00b |
No files matched your search
@@ -53,6 +53,11 @@ SELF_ASSETS = [
|
||||
"SHA256SUMS",
|
||||
]
|
||||
|
||||
# mac 目标只服务开发机,不是部署目标。缺它不该阻塞服务端发版 ——
|
||||
# 强行要求三平台齐全,会让「只改了服务端逻辑、没必要重编 mac」的场景卡住,
|
||||
# 进而逼着人去手工绕,反而更容易把旧 mac 包混进新 Release。
|
||||
OPTIONAL_ASSETS = {"mpc-x86_64-apple-darwin"}
|
||||
|
||||
|
||||
def log(msg):
|
||||
print(msg, flush=True)
|
||||
@@ -228,6 +233,9 @@ def main():
|
||||
for n in SELF_ASSETS:
|
||||
p = os.path.join(DIST, n)
|
||||
if not os.path.isfile(p):
|
||||
if n in OPTIONAL_ASSETS:
|
||||
log("跳过可选产物(本次未构建):%s" % n)
|
||||
continue
|
||||
die("缺少产物:%s(先跑 tools/release-build.sh)" % p)
|
||||
self_paths.append((n, p))
|
||||
log("自身产物 %d 个就位" % len(self_paths))
|
||||
@@ -319,9 +327,29 @@ def main():
|
||||
log(" 上传 %s" % item["name"])
|
||||
|
||||
# ---- 8. 推 tag ----
|
||||
# 🔴 Gitea 在「创建 Release」那一步就会**自动建同名 tag**(指向默认分支 HEAD),
|
||||
# 所以走到这里 `git push` 多半会以 `already exists` 失败 —— 那不是错误。
|
||||
# 判据改成「远端 tag 指向的是不是当前 HEAD」:是就当作成功。
|
||||
if args.push:
|
||||
subprocess.run(["git", "push", "origin", tag], check=True)
|
||||
log("已推送 tag %s" % tag)
|
||||
r = subprocess.run(["git", "push", "origin", tag],
|
||||
capture_output=True, text=True)
|
||||
if r.returncode == 0:
|
||||
log("已推送 tag %s" % tag)
|
||||
else:
|
||||
head = subprocess.run(["git", "rev-parse", "HEAD"],
|
||||
capture_output=True, text=True).stdout.strip()
|
||||
remote = subprocess.run(["git", "ls-remote", "--tags", "origin", tag],
|
||||
capture_output=True, text=True).stdout.strip()
|
||||
# ls-remote 输出形如:「<sha>\trefs/tags/v0.3.0」
|
||||
remote_sha = remote.split()[0] if remote.split() else ""
|
||||
if remote_sha and (remote_sha == head or remote_sha.endswith("^{}")):
|
||||
log("tag %s 已由 Gitea 建好(指向 %s),无需再推" % (tag, remote_sha[:7]))
|
||||
elif remote_sha:
|
||||
die("远端 tag %s 指向 %s,与本地 HEAD %s 不一致 —— 发版前先把提交推上去"
|
||||
% (tag, remote_sha[:7], head[:7]))
|
||||
else:
|
||||
# 真失败(网络/权限),把 git 自己的输出抛出来,别吞
|
||||
die("推送 tag 失败:%s" % (r.stderr or r.stdout).strip())
|
||||
|
||||
log("完成:%s" % tag)
|
||||
return 0
|
||||
|
||||
@@ -0,0 +1,122 @@
|
||||
#!/usr/bin/env python3
|
||||
"""从 transcript 里取回某个结构体的**最终版定义**,做块级替换。
|
||||
|
||||
背景(2026-11-09):
|
||||
工作区被 `git reset --hard` 抹掉后,从 transcript 重建时出现了**链式依赖**:
|
||||
一条 Edit 的 `old_string` 依赖另一条更早的 Edit 的结果,
|
||||
精确重放会失配 ⇒ 结构体少了字段 ⇒ 编译报错。
|
||||
|
||||
与其继续追链,不如**直接取最终版**:
|
||||
transcript 里每一次 Edit 的 `new_string` 都带着「那一刻的文件片段」,
|
||||
所以只要按时间顺序找**最后一个**包含该结构体完整定义的 `new_string`,
|
||||
抽出来整块替换即可。
|
||||
|
||||
用法:
|
||||
python3 tools/restore-structs-from-transcript.py <transcript.jsonl...> \
|
||||
--file crates/mpc-tee/src/reconciler.rs \
|
||||
--struct PlacedSession --struct PendingSession
|
||||
"""
|
||||
import argparse
|
||||
import json
|
||||
import os
|
||||
import sys
|
||||
|
||||
|
||||
def iter_calls(path):
|
||||
with open(path, "r", encoding="utf-8", errors="replace") as fh:
|
||||
for line in fh:
|
||||
line = line.strip()
|
||||
if not line.startswith("{"):
|
||||
continue
|
||||
try:
|
||||
obj = json.loads(line)
|
||||
except ValueError:
|
||||
continue
|
||||
if obj.get("type") != "function_call":
|
||||
continue
|
||||
args = obj.get("arguments")
|
||||
if isinstance(args, str):
|
||||
try:
|
||||
args = json.loads(args)
|
||||
except ValueError:
|
||||
continue
|
||||
if isinstance(args, dict):
|
||||
yield obj.get("timestamp", 0), obj.get("name", ""), args
|
||||
|
||||
|
||||
def extract_struct(text, name):
|
||||
"""抽出 `struct <name> { ... }` 整块(大括号配平)。找不到返回 None。"""
|
||||
i = text.find("struct %s {" % name)
|
||||
if i < 0:
|
||||
return None
|
||||
j = text.index("{", i)
|
||||
depth = 0
|
||||
k = j
|
||||
while k < len(text):
|
||||
if text[k] == "{":
|
||||
depth += 1
|
||||
elif text[k] == "}":
|
||||
depth -= 1
|
||||
if depth == 0:
|
||||
return text[i:k + 1]
|
||||
k += 1
|
||||
return None
|
||||
|
||||
|
||||
def main():
|
||||
ap = argparse.ArgumentParser()
|
||||
ap.add_argument("transcript", nargs="+")
|
||||
ap.add_argument("--file", required=True, help="要修复的仓库内文件")
|
||||
ap.add_argument("--struct", action="append", required=True, dest="structs")
|
||||
ap.add_argument("--repo", default=os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||
args = ap.parse_args()
|
||||
|
||||
repo = os.path.abspath(args.repo)
|
||||
target = os.path.abspath(args.file)
|
||||
if not target.startswith(repo + os.sep):
|
||||
print("目标不在仓库内: %s" % target, file=sys.stderr)
|
||||
return 2
|
||||
|
||||
events = []
|
||||
for t in args.transcript:
|
||||
for ts, name, inp in iter_calls(t):
|
||||
if name in ("Edit", "Write") and inp.get("file_path") == target:
|
||||
events.append((ts, name, inp))
|
||||
events.sort(key=lambda e: e[0])
|
||||
|
||||
# 每个结构体取「时间上最后一个能抽到完整定义的片段」
|
||||
final = {}
|
||||
for ts, name, inp in events:
|
||||
blob = inp.get("content", "") if name == "Write" else inp.get("new_string", "")
|
||||
for st in args.structs:
|
||||
seg = extract_struct(blob, st)
|
||||
if seg:
|
||||
final[st] = seg
|
||||
|
||||
missing = [s for s in args.structs if s not in final]
|
||||
if missing:
|
||||
print("transcript 里找不到这些结构体的完整定义: %s" % ", ".join(missing), file=sys.stderr)
|
||||
return 3
|
||||
|
||||
cur = open(target, encoding="utf-8").read()
|
||||
changed = []
|
||||
for st in args.structs:
|
||||
old_seg = extract_struct(cur, st)
|
||||
if old_seg is None:
|
||||
print("当前文件里找不到 struct %s" % st, file=sys.stderr)
|
||||
return 4
|
||||
if old_seg == final[st]:
|
||||
continue
|
||||
cur = cur.replace(old_seg, final[st], 1)
|
||||
changed.append(st)
|
||||
|
||||
open(target, "w", encoding="utf-8").write(cur)
|
||||
if changed:
|
||||
print("已替换结构体: %s" % ", ".join(changed))
|
||||
else:
|
||||
print("结构体已是最终版,无需改动")
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
Reference in new issue
Block a user