Fix setup on stock macOS bash, shader step false success, battery gate misreport (#4, #5, #7)

- Brace every $NAME that is directly followed by a non-ASCII character in the shell scripts: bash 3.2 in a UTF-8 locale read the first byte of the following character as part of the variable name and aborted under set -u (#4, #6).
- setup.sh and d2rm_pack.py: the shader translation step is complete only when every entry in the completion marker is ok and every library file exists; the script's exit status is no longer hidden by a pipe (#5).
- devbattery.sh / devlock.sh: a missing local timeout or ideviceinfo is reported as such and stops at once, instead of being reported as an offline device and polled for up to an hour (#7).
- smoke_mac.sh builds its package for iPhone only regardless of the project default.

Reported by @SakuraToErii. The setup.sh part of #4 was also submitted by @hubeiqiao in #6.

Co-authored-by: hubeiqiao <12777592+hubeiqiao@users.noreply.github.com>
This commit is contained in:
jhaizhou
2026-10-13 03:17:23 +08:00
co-authored by hubeiqiao
parent 824d2d3f0b
commit 66c3a2fb70
28 changed files with 121 additions and 68 deletions
+14 -3
View File
@@ -19,7 +19,7 @@
# Requires: Python 3.9+ with pillow numpy lz4 capstone unicorn; a C compiler (clang or gcc, for the small piece of C that decodes textures); the .NET SDK (to build the shader translation tool);
# spirv-cross; Apple's Metal shader compiler (on a Mac it comes with Xcode). This tool reports whatever is missing item by item at the start.
# What it does is the same as "./setup.sh + the generation part of dm/ios/run.sh build", except that at the end it does not invoke an Xcode build but puts the build outputs into the shell.
import hashlib, os, re, runpy, shutil, subprocess, sys, time, zipfile
import hashlib, json, os, re, runpy, shutil, subprocess, sys, time, zipfile
HERE = os.path.dirname(os.path.abspath(__file__)); DM = os.path.dirname(HERE); IOS = os.path.join(DM, 'ios'); GT = os.path.join(DM, 'gfx', 'tools')
ROOT = os.path.abspath(os.environ.get('DM_ROOT') or os.path.expanduser('~/dm-work'))
@@ -167,8 +167,19 @@ def main():
run(gt('dmsh_chain.py', '--update-lock'), what='登记翻译链'); run(gt('dmsh_chain.py', '--header'), what='写翻译链版本')
local = run(gt('dmsh_chain.py'), what='取翻译链版本').strip().splitlines()[-1]
ios_out = os.path.join(ROOT, 'build', 'ios', 'dmsh_b'); mac_cache = os.path.join(ROOT, 'build', 'cache', 'metal_shader_cache')
step('翻译全部着色器(首次约 8 分钟)', lambda: os.path.isfile(os.path.join(mac_cache, 'b-' + local, '_b_build.json')) and os.path.isdir(os.path.join(ios_out, 'b-' + local)) and any(f.endswith('_b.metallib') for f in os.listdir(os.path.join(ios_out, 'b-' + local))), # 完成标记写在 Mac 侧缓存目录里 | the completion marker is written in the Mac-side cache directory
lambda: run(gt('dmsh_build.py', packs, mac_cache), env={'IOSOUT': ios_out, 'J': os.environ.get('J', '6'), 'MAIN': os.path.join(game, 'ExeFS', 'main')}, log=os.path.join(stage, 'shaders.log'), what='翻译着色器'))
# 做没做全只认完成标记(写在 Mac 侧缓存目录里)的逐个结果:每个着色器都是 ok,并且库目录里每个都有库文件。只看「标记在、目录里至少有一个文件」不够——
# 翻译脚本即使全部失败也会写标记并正常退出,那样会把空的或缺了几千个的库当成做完,缺的着色器要到游戏里才报红
# Completeness is decided only by the per-shader results in the completion marker (written in the Mac-side cache directory): every shader is ok, and every one has its library file in the library directory. "The marker exists and the directory holds at least one file" is not enough --
# the translation script writes the marker and exits normally even when everything failed, which would accept an empty library or one missing thousands of shaders, and the missing shaders would only turn red in the game
def shaders_done(tell=False):
try: res = json.load(open(os.path.join(mac_cache, 'b-' + local, '_b_build.json'), encoding='utf-8'))
except (OSError, ValueError): return False
d = os.path.join(ios_out, 'b-' + local); have = set(os.listdir(d)) if os.path.isdir(d) else set()
bad = [r for r in res if r['st'] != 'ok']; miss = [r['key'] for r in res if r['st'] == 'ok' and r['key'] + '_b.metallib' not in have]
if tell and (bad or miss or not res): say('着色器 %d 个:没翻译成功 %d 个,库目录里缺 %d 个(完整输出见 %s)' % (len(res), len(bad), len(miss), os.path.join(stage, 'shaders.log')))
return bool(res) and not bad and not miss
step('翻译全部着色器(首次约 8 分钟)', shaders_done,
lambda: (run(gt('dmsh_build.py', packs, mac_cache), env={'IOSOUT': ios_out, 'J': os.environ.get('J', '6'), 'MAIN': os.path.join(game, 'ExeFS', 'main')}, log=os.path.join(stage, 'shaders.log'), what='翻译着色器'), shaders_done(tell=True)))
lib = os.path.join(stage, 'msl', 'b-' + chain); os.makedirs(os.path.dirname(lib)); shutil.copytree(os.path.join(ios_out, 'b-' + local), lib) # 目录名用壳认的那个版本 | the directory name uses the version the shell recognizes
if local != chain: # 每个着色器的说明里也记着链版本,壳逐个核对(对不上拒绝加载,真机实测撞到):一并改成壳认的那个 | each shader's description also records the chain version, and the shell checks them one by one (a mismatch is refused, hit in real-device testing): change them all to the one the shell recognizes
old, new, n = ('"chain": "%s"' % local).encode(), ('"chain": "%s"' % chain).encode(), 0
+2 -2
View File
@@ -19,7 +19,7 @@ PKG=$1; KEYS=$2; DM_ROOT=${DM_ROOT:-$HOME/dm-work}; OUT=$DM_ROOT/data/switch/3.3
die() { echo "✗ $*" >&2; exit 1; }
HT=${HACTOOL:-$(command -v hactool || true)}; [ -n "$HT" ] && [ -x "$HT" ] || die "没找到 hactool:装好后放进 PATH,或设 HACTOOL=<路径>(见本文件开头)"
[ -f "$PKG" ] || die "没有这个游戏包:$PKG"; [ -f "$KEYS" ] || die "没有这个密钥文件:$KEYS"
[ ! -e "$OUT" ] || die "已有 $OUT,不覆盖。要重做先自己把它移走"
[ ! -e "$OUT" ] || die "已有 ${OUT},不覆盖。要重做先自己把它移走"
ht() { "$HT" -k "$KEYS" --disablekeywarns --suppresskeys "$@"; }
T=$DM_ROOT/build/cache/dm/extract.$$; mkdir -p "$T/nca" || die "建不了中间目录 $T"; trap 'rm -rf "$T"' EXIT
say() { echo "[$(date +%T)] $*"; }
@@ -64,4 +64,4 @@ SUMS
[ -f "$OUT.part/RomFS/data/build_manifest.psv" ] || { echo " ✗ 资源里没有 data/build_manifest.psv"; ok=0; }
[ "$ok" = 1 ] || { rm -rf "$OUT.part"; die "版本不对:游戏包里的更新不是 3.3.94012"; }
mv "$OUT.part" "$OUT" || die "改名到 $OUT 没成"
say "好了:$OUT。接着在仓库根目录运行 ./setup.sh"
say "好了:${OUT}。接着在仓库根目录运行 ./setup.sh"
+1 -1
View File
@@ -96,7 +96,7 @@ SC=${SC:-$HERE/verify/savecmp.py}
MJ=$TR/meta.json; [ -f "$TR/meta.v2.json" ] && MJ=$TR/meta.v2.json # 补记墙钟区间的版本 | The version with the wall-clock interval recorded afterwards
MJ=${META:-$MJ} # 可显式指定 | Can be specified explicitly
AT="--a-meta=$MJ"; grep -q wall_start "$MJ" || AT=${A_TIME:+--a-time=$A_TIME}
echo "③ 正对照:真值 vs 宿主($SC --b-time=$FT $AT)"; $PY "$SC" "$TR/save_after" "$T/user" --b-time=$FT $AT; G=$?
echo "③ 正对照:真值 vs 宿主($SC --b-time=$FT ${AT})"; $PY "$SC" "$TR/save_after" "$T/user" --b-time=$FT $AT; G=$?
echo "③ 负对照:真值 vs 起始存档"; $PY "$SC" "$TR/save_after" "$REF/0000000000000001" --b-time=$FT $AT; N=$?
echo "结论:逐拍退出码 ${K6}、正对照退出码 ${G}(0 = 绿),负对照退出码 ${N}(须非 0)"
[ $K6 = 0 ] && [ $G = 0 ] && [ $N != 0 ]