Skip to content

Play your own Switch games on iPhone/iPad — one-click macOS app, no terminal. | 把 Switch 游戏装进 iPhone:图形界面一键构建,不用命令行。Bring your own game.

Windows: chain venv setup on Python install and support 1.2 engine modules (#772)

LNPd499ff144361
diff --git a/frontend-qt/nspb_qt/model.py b/frontend-qt/nspb_qt/model.py
index 8f88100b..650ff569 100644
--- a/frontend-qt/nspb_qt/model.py
+++ b/frontend-qt/nspb_qt/model.py
@@ -499,8 +499,8 @@ class Model(QObject):
# three placeholders, three args: a mismatch makes t() fall back to the raw
# "dependency %@: [%@] %@" line (the report's log had it six times)
name = d.title_key.replace('dep.', '').replace('.hint', '')
- self.log(self.t('dep.row.log', name, d.state.value,
- d.detail.replace('\n', ' | ')) + '\n')
+ detail_text = self.format_dep_detail(d.detail).replace('\n', ' | ')
+ self.log(self.t('dep.row.log', name, d.state.value, detail_text) + '\n')
if not pu.IS_WIN:
# On Windows `_windows_deps` already set python_path (the interpreter the app
# installed, which find_python without its candidates cannot see) and dotnet_path
@@ -906,9 +906,31 @@ class Model(QObject):
self.log(self.t('dep.install.fail', '-') + '\n')
self._clear_installing(dep)
self.depsChanged.emit()
+ self.check_deps()
threading.Thread(target=work, daemon=True).start()
+ def format_dep_detail(self, detail: str) -> str:
+ """Translate internal `dep.*` detail markers into localized text for the UI and log."""
+ if detail == 'dep.xcode.noSDK':
+ return self.t('dep.xcode.noSDK')
+ if detail.startswith('dep.python.old:'):
+ ver = detail.split(':', 1)[1]
+ return self.t('dep.python.old', ver, f'{pu.MIN_PYTHON[0]}.{pu.MIN_PYTHON[1]}')
+ if detail.startswith('dep.python.missing:'):
+ py = detail.split(':', 1)[1]
+ return self.t('dep.python.missing', py)
+ if detail.startswith('dep.python.notFound:'):
+ need = detail.split(':', 1)[1]
+ return self.t('dep.python.notFound', need, need)
+ if detail.startswith('dep.python.none:'):
+ found = detail.split(':', 1)[1]
+ return self.t('dep.python.none', found)
+ if detail.startswith('dep.metal.other:'):
+ _, got, tested = detail.split(':', 2)
+ return self.t('dep.metal.other', got, tested)
+ return detail
+
def _clear_installing(self, dep: Dep) -> None:
"""Drop `installing` on every row with this id, wherever it currently lives.
@@ -955,7 +977,12 @@ class Model(QObject):
log=lambda s: self.log(str(s) + '\n'),
progress=progress_logger(self.t('dep.phase.download')))
self.log(self.t('dep.python.done', str(path)) + '\n')
- ok = True
+ self.python_path = str(path)
+ ok = self._make_venv(str(path))
+ if not ok:
+ detail = 'venv / package install failed'
+ self.log(self.t('dep.install.fail', detail) + '\n')
+ self._record_install_failure(dep, detail)
elif what == 'llvm':
self.log(self.t('dep.llvm.downloading') + '\n')
path = wf.install_llvm(
@@ -1132,9 +1159,17 @@ class Model(QObject):
and no PyPI — the same "the app carries it" promise the Mac's bundled CPython makes.
Source runs have no such folder and fall back to PyPI.
"""
- base = getattr(sys, '_MEIPASS', None) or Path(sys.executable).parent
- w = Path(base) / 'wheels'
- return w if w.is_dir() and any(w.glob('*.whl')) else None
+ cands: list[Path] = []
+ meipass = getattr(sys, '_MEIPASS', None)
+ if meipass:
+ cands.append(Path(meipass))
+ cands.append(Path(meipass).parent)
+ cands.append(Path(sys.executable).parent)
+ for base in cands:
+ w = Path(base) / 'wheels'
+ if w.is_dir() and any(w.glob('*.whl')):
+ return w
+ return None
@staticmethod
def _pip_args(pkgs: list[str], wheels: Path | None) -> list[str]:
@@ -1184,21 +1219,24 @@ class Model(QObject):
if ver < (3, 14):
pkgs.insert(4, 'backports.zstd')
wheels = self.bundled_wheels()
- args = self._pip_args(pkgs, wheels)
- self.log(f'$ {vpy} -m pip {" ".join(args)}'
- + ('' if wheels else ' (from PyPI)') + '\n')
- try:
- p = subprocess.Popen([vpy, '-m', 'pip'] + args, stdout=subprocess.PIPE,
- stderr=subprocess.STDOUT, text=True, encoding='utf-8',
- errors='replace', env=pu.child_env(), **pu.no_window_kwargs())
- assert p.stdout is not None
- for line in p.stdout:
- self.log(line)
- p.wait()
- return p.returncode == 0
- except OSError as e:
- self.log(f'{e}\n')
- return False
+ for attempt_wheels in ([wheels, None] if wheels else [None]):
+ args = self._pip_args(pkgs, attempt_wheels)
+ self.log(f'$ {vpy} -m pip {" ".join(args)}'
+ + ('' if attempt_wheels else ' (from PyPI)') + '\n')
+ try:
+ p = subprocess.Popen([vpy, '-m', 'pip'] + args, stdout=subprocess.PIPE,
+ stderr=subprocess.STDOUT, text=True, encoding='utf-8',
+ errors='replace', env=pu.child_env(), **pu.no_window_kwargs())
+ assert p.stdout is not None
+ for line in p.stdout:
+ self.log(line)
+ p.wait()
+ if p.returncode == 0:
+ return True
+ except OSError as e:
+ self.log(f'{e}\n')
+ return False
+ return False
def install_all_missing(self) -> None:
"""Install every missing dependency, one at a time, in order — and re-scan between passes.
diff --git a/frontend-qt/nspb_qt/ui.py b/frontend-qt/nspb_qt/ui.py
index 2221629a..fc279133 100644
--- a/frontend-qt/nspb_qt/ui.py
+++ b/frontend-qt/nspb_qt/ui.py
@@ -1981,24 +1981,7 @@ class MainWindow(QMainWindow):
return f
def _format_dep_detail(self, d: Dep) -> str:
- if d.detail == 'dep.xcode.noSDK':
- return self.m.t('dep.xcode.noSDK')
- if d.detail.startswith('dep.python.old:'):
- ver = d.detail.split(':', 1)[1]
- return self.m.t('dep.python.old', ver, f'{pu.MIN_PYTHON[0]}.{pu.MIN_PYTHON[1]}')
- if d.detail.startswith('dep.python.missing:'):
- py = d.detail.split(':', 1)[1]
- return self.m.t('dep.python.missing', py)
- if d.detail.startswith('dep.python.notFound:'):
- need = d.detail.split(':', 1)[1]
- return self.m.t('dep.python.notFound', need, need)
- if d.detail.startswith('dep.python.none:'):
- found = d.detail.split(':', 1)[1]
- return self.m.t('dep.python.none', found)
- if d.detail.startswith('dep.metal.other:'):
- _, got, tested = d.detail.split(':', 2)
- return self.m.t('dep.metal.other', got, tested)
- return d.detail
+ return self.m.format_dep_detail(d.detail)
def _refresh_inputs(self) -> None:
t = self.m.t
diff --git a/frontend-qt/nspb_qt/win/build_app.py b/frontend-qt/nspb_qt/win/build_app.py
index a96d8df9..80933f1d 100644
--- a/frontend-qt/nspb_qt/win/build_app.py
+++ b/frontend-qt/nspb_qt/win/build_app.py
@@ -73,7 +73,40 @@ _IMPORT = re.compile(r'^\s*#\s*(?:import|include)\s*<(\w+)/', re.M)
#: Paths the pack step drops from the base app (a full IPA maps its RomFS back in as `romfs` or `romfs.img`).
PACK_SKIPS = ('Payload/DmIOS.app/msl', 'Payload/DmIOS.app/aoc',
- 'Payload/DmIOS.app/romfs', 'Payload/DmIOS.app/romfs.img')
+ 'Payload/DmIOS.app/romfs', 'Payload/DmIOS.app/romfs.img',
+ 'Payload/DmIOS.app/romfs.id', 'Payload/DmIOS.app/html',
+ 'Payload/DmIOS.app/jit')
+
+
+def _shader_lib_module(repo: Path):
+ """Load `dm/tools/shader_lib.py` when present (engine >= 1.2 packs `b-<chain>/` into `b-<chain>.img`)."""
+ tools = Path(repo) / 'dm' / 'tools'
+ if not (tools / 'shader_lib.py').is_file():
+ return None
+ if str(tools) not in sys.path:
+ sys.path.insert(0, str(tools))
+ import shader_lib
+ return shader_lib
+
+
+def shader_lib_has(repo: Path, lib: Path) -> bool:
+ """Whether `lib` (`b-<chain>` folder or `b-<chain>.img` image) holds compiled `*_b.metallib` files."""
+ slib = _shader_lib_module(repo)
+ if slib is not None:
+ return bool(slib.has_library(lib))
+ return bool(list(Path(lib).glob('*_b.metallib')))
+
+
+def shader_lib_stamp_lines(repo: Path, lib: Path) -> list[str]:
+ """Lines of `inputs.tsv` from `b-<chain>` (folder or `.img`), or `[]` when absent."""
+ slib = _shader_lib_module(repo)
+ if slib is not None:
+ try:
+ return (slib.view(lib) / 'inputs.tsv').read_text(encoding='utf-8').splitlines()
+ except OSError:
+ return []
+ stamp = Path(lib) / 'inputs.tsv'
+ return stamp.read_text(encoding='utf-8').splitlines() if stamp.exists() else []
def romfs_has(repo, romfs, marker: str) -> bool:
@@ -562,7 +595,7 @@ def main(argv: list[str] | None = None) -> int:
v = m.group(1)
gfx = env.get('GFXAPI') or ''
if gfx not in ('nvn', 'vulkan', 'gl'):
- if list((msl_ios / f'b-{v}').glob('*_b.metallib')):
+ if shader_lib_has(repo, msl_ios / f'b-{v}'):
gfx = 'nvn'
elif (msl_ios / 'vk/vk_shaders.metallib').exists():
gfx = 'vulkan'
@@ -580,16 +613,15 @@ def main(argv: list[str] | None = None) -> int:
msldir = 'gl'
else:
msldir = f'b-{v}'
- if not list((msl_ios / msldir).glob('*_b.metallib')):
+ if not shader_lib_has(repo, msl_ios / msldir):
die(f'no iOS shader libraries at {msl_ios}/{msldir} (the shader step must run first)')
# The stamp `dmsh_build.py` writes names the game and the digest of its profile's
# shader inputs. `build_ipa.sh` compares both and refuses libraries from another
# profile state; without the comparison a stale library set would be packed silently.
inputs = py(repo / 'dm/gfx/tools/dmsh_chain.py', '--inputs',
env=dict(env, DM_GAME=game))
- stamp = msl_ios / msldir / 'inputs.tsv'
if inputs:
- lines = stamp.read_text(encoding='utf-8').splitlines() if stamp.exists() else []
+ lines = shader_lib_stamp_lines(repo, msl_ios / msldir)
if f'game\t{game}' not in lines or f'inputs\t{inputs}' not in lines:
die(f'the iOS shader libraries at {msl_ios}/{msldir} are not a full build from '
f'this profile\'s current tables (inputs {inputs}): build them again')
@@ -663,18 +695,17 @@ def main(argv: list[str] | None = None) -> int:
es = gen / 'embed.S'
es_tmp = gen / 'embed.S.tmp'
jit_img = romfs.parent / 'jit' / 'jit.img'
- embed_extra = [jit_img] if jit_img.is_file() else []
- flags = py(repo / 'dm/ios/tools/gen_embed.py', patched, es_tmp, *mods, *embed_extra)
+ jit_args = ['--jit', jit_img] if jit_img.is_file() else []
+ flags = py(repo / 'dm/ios/tools/gen_embed.py', *jit_args, patched, es_tmp, *mods)
bin_meta = []
for m_name in mods:
bp = patched / f'{m_name}.patched.bin'
if bp.is_file():
st = bp.stat()
bin_meta.append(f'{m_name}:{st.st_size}:{st.st_mtime_ns}')
- for ep in embed_extra:
- if ep.is_file():
- st = ep.stat()
- bin_meta.append(f'{ep.name}:{st.st_size}:{st.st_mtime_ns}')
+ if jit_img.is_file():
+ st = jit_img.stat()
+ bin_meta.append(f'{jit_img.name}:{st.st_size}:{st.st_mtime_ns}')
# the assembler treats '\' as an escape in .incbin paths
es_body = re.sub(r'\.incbin "([^"]*)"',
lambda mm: '.incbin "' + mm.group(1).replace('\\', '/') + '"',
@@ -774,6 +805,10 @@ def main(argv: list[str] | None = None) -> int:
# --- pack
maps = [f'Payload/DmIOS.app={app}', f'Payload/DmIOS.app/msl/{msldir}={msl_ios / msldir}']
+ if (romfs.parent / 'html').is_dir():
+ maps.append(f'Payload/DmIOS.app/html={romfs.parent / "html"}')
+ if (romfs.parent / 'jit').is_dir():
+ maps.append(f'Payload/DmIOS.app/jit={romfs.parent / "jit"}')
if aoc and aoc.is_dir() and any(aoc.iterdir()):
maps.append(f'Payload/DmIOS.app/aoc={aoc}')
t('add-on content: ' + ' '.join(sorted(p.name for p in aoc.iterdir())))
diff --git a/frontend-qt/nspb_qt/win/driver.py b/frontend-qt/nspb_qt/win/driver.py
index 510b5d01..89ca490b 100644
--- a/frontend-qt/nspb_qt/win/driver.py
+++ b/frontend-qt/nspb_qt/win/driver.py
@@ -82,6 +82,10 @@ def load_upstream(repo: Path) -> ModuleType:
"""
if 'pwd' not in sys.modules:
_install_pwd_stub()
+ if 'fcntl' not in sys.modules:
+ _install_fcntl_stub()
+ if not hasattr(os, 'getuid'):
+ os.getuid = lambda: 0 # type: ignore[attr-defined]
path = repo / 'scripts' / 'build_ipa_from_nsp.py'
if not path.is_file():
raise SystemExit(f'no engine: {path} is missing. Run `python3 tools/engine.py sync` in the checkout first.')
@@ -93,6 +97,9 @@ def load_upstream(repo: Path) -> ModuleType:
started = time.time()
spec.loader.exec_module(mod)
del started
+ if hasattr(mod, 'tree_tar'):
+ mod.tree_tar._lock = lambda folder, say=None: True
+ mod.tree_tar._unlock = lambda folder: None
return mod
@@ -119,6 +126,26 @@ def _install_pwd_stub() -> None:
sys.modules['pwd'] = pwd
+def _install_fcntl_stub() -> None:
+ import types
+
+ fcntl = types.ModuleType('fcntl')
+ fcntl.LOCK_SH = 1
+ fcntl.LOCK_EX = 2
+ fcntl.LOCK_NB = 4
+ fcntl.LOCK_UN = 8
+ fcntl.F_GETFD = 1
+ fcntl.F_SETFD = 2
+ fcntl.F_GETFL = 3
+ fcntl.F_SETFL = 4
+ fcntl.FD_CLOEXEC = 1
+ fcntl.flock = lambda fd, op: None
+ fcntl.lockf = lambda fd, cmd, len=0, start=0, whence=0: None
+ fcntl.fcntl = lambda fd, cmd, arg=0: 0
+ fcntl.ioctl = lambda fd, req, arg=0, mutate_flag=True: 0
+ sys.modules['fcntl'] = fcntl
+
+
def _option_value(argv: list[str], name: str) -> str | None:
for i, a in enumerate(argv):
if a == name and i + 1 < len(argv):
diff --git a/frontend-qt/nspb_qt/win/shim.py b/frontend-qt/nspb_qt/win/shim.py
index d6e45305..ddb83412 100644
--- a/frontend-qt/nspb_qt/win/shim.py
+++ b/frontend-qt/nspb_qt/win/shim.py
@@ -430,10 +430,20 @@ if os.name == 'nt' and not os.environ.get('NSPB_SHIM_OFF'):
if os.environ.get('DM_ALLOW_SYSTEM_SPIRV_CROSS') == '1':
bad = [b for b in bad
if not (b.startswith('spirv-cross: ') and not b.endswith(' / actual missing'))]
+ if os.environ.get('DM_ALLOW_OTHER_METAL') == '1':
+ bad = [b for b in bad if not b.startswith('metal_macosx: ')]
return bad
mod.check_tools = _win_check_tools
+ def _patch_tree_tar_module(mod):
+ if getattr(mod, '_nspb_patched', False):
+ return
+ mod._nspb_patched = True
+ # Windows cannot os.open(directory, O_RDONLY) for flock(); a single build runs per work dir.
+ mod._lock = lambda folder, say=None: True
+ mod._unlock = lambda folder: None
+
import importlib.machinery as _machinery
_exec_module = _machinery.SourceFileLoader.exec_module
@@ -446,6 +456,8 @@ if os.name == 'nt' and not os.environ.get('NSPB_SHIM_OFF'):
_patch_sdk_patches_module(module)
elif name == 'tool_lock' or name.endswith('.tool_lock'):
_patch_tool_lock_module(module)
+ elif name == 'tree_tar' or name.endswith('.tree_tar'):
+ _patch_tree_tar_module(module)
_machinery.SourceFileLoader.exec_module = _win_exec_module
@@ -640,6 +652,30 @@ if os.name == 'nt' and not os.environ.get('NSPB_SHIM_OFF'):
_pwd.getpwuid = getpwuid
_pwd.getpwnam = lambda name: getpwuid(0)
sys.modules['pwd'] = _pwd
+
+ if not hasattr(os, 'getuid'):
+ os.getuid = lambda: 0
+
+ # ---- fcntl
+ # dm/tools/tree_tar.py (imported at top level by scripts/build_ipa_from_nsp.py) imports fcntl
+ # for advisory directory locking. Register a Windows stand-in so the import succeeds.
+ if 'fcntl' not in sys.modules:
+ import types as _types
+ _fcntl = _types.ModuleType('fcntl')
+ _fcntl.LOCK_SH = 1
+ _fcntl.LOCK_EX = 2
+ _fcntl.LOCK_NB = 4
+ _fcntl.LOCK_UN = 8
+ _fcntl.F_GETFD = 1
+ _fcntl.F_SETFD = 2
+ _fcntl.F_GETFL = 3
+ _fcntl.F_SETFL = 4
+ _fcntl.FD_CLOEXEC = 1
+ _fcntl.flock = lambda fd, op: None
+ _fcntl.lockf = lambda fd, cmd, len=0, start=0, whence=0: None
+ _fcntl.fcntl = lambda fd, cmd, arg=0: 0
+ _fcntl.ioctl = lambda fd, req, arg=0, mutate_flag=True: 0
+ sys.modules['fcntl'] = _fcntl
'''
diff --git a/frontend-qt/tests/test_win.py b/frontend-qt/tests/test_win.py
index 83c57ada..1480d424 100644
--- a/frontend-qt/tests/test_win.py
+++ b/frontend-qt/tests/test_win.py
@@ -2023,6 +2023,38 @@ class VenvWheelsTest(unittest.TestCase):
self.assertEqual(out, 'dependency python: [missing] C:/x | found', 'the report log showed raw %@ placeholders')
self.assertTrue(t('dep.row.log', Lang('zh'), 'python', 'missing', 'd'), 'Chinese side is filled too')
+ def test_bundled_wheels_finds_wheels_beside_exe_when_meipass_is_internal(self) -> None:
+ """PyInstaller 6 onedir sets sys._MEIPASS to `<app>/_internal` while `wheels/` sits at `<app>/wheels`."""
+ import ast
+ src = (QT / 'nspb_qt' / 'model.py').read_text(encoding='utf-8')
+ tree = ast.parse(src)
+ fn = next(n for n in ast.walk(tree) if isinstance(n, ast.FunctionDef)
+ and n.name == 'bundled_wheels')
+ for n in ast.walk(fn):
+ ast.fix_missing_locations(n)
+ ns: dict = {'sys': sys, 'Path': Path}
+ exec(compile(ast.fix_missing_locations(ast.Module(body=[fn], type_ignores=[])),
+ '<model>', 'exec'), ns)
+ bundled_wheels = ns['bundled_wheels']
+ with tempfile.TemporaryDirectory() as td:
+ app_dir = Path(td) / 'NS Port Builder'
+ internal = app_dir / '_internal'
+ wheels = app_dir / 'wheels'
+ internal.mkdir(parents=True)
+ wheels.mkdir(parents=True)
+ (wheels / 'lz4-4.0.0-cp312-win_amd64.whl').write_bytes(b'PK')
+ with mock.patch.object(sys, '_MEIPASS', str(internal), create=True), \
+ mock.patch.object(sys, 'executable', str(app_dir / 'NS Port Builder.exe')):
+ self.assertEqual(bundled_wheels(), wheels)
+
+ def test_win_python_install_chains_make_venv_immediately(self) -> None:
+ """Installing Python on a fresh PC must immediately build the venv and install packages in the same pass."""
+ src = (QT / 'nspb_qt' / 'model.py').read_text(encoding='utf-8')
+ branch = src[src.index("elif what == 'python':"):src.index("elif what == 'llvm':")]
+ self.assertIn('install_python(', branch)
+ self.assertIn('self._make_venv(str(path))', branch,
+ 'the Python installer must chain _make_venv immediately so packages are not skipped')
+
class MetalPickFlowShapeTest(unittest.TestCase):
"""The model wiring (source-shape, since model.py needs PySide6): the metal row asks for a
@@ -2524,6 +2556,72 @@ class WindowsBuildFixesTest(unittest.TestCase):
self.assertEqual((out1 / f'main.{ext}').read_bytes(),
(out2 / f'main.{ext}').read_bytes())
+ def test_fcntl_and_tree_tar_shim_work_without_posix_fcntl(self) -> None:
+ """Engine 1.2's tree_tar.py imports fcntl at top level and opens parent directories."""
+ from nspb_qt.win import driver
+ repo = QT.parent / 'engine'
+ if not (repo / 'dm/tools/tree_tar.py').is_file():
+ self.skipTest('engine/ is missing')
+ with tempfile.TemporaryDirectory() as td:
+ sd = Path(td) / 'shim'
+ sd.mkdir()
+ sc = shim._SITECUSTOMIZE_SRC.replace("if os.name == 'nt'", "if True")
+ (sd / 'sitecustomize.py').write_text(sc, encoding='utf-8')
+ code = (
+ "import builtins, os, sys\n"
+ "real_import = builtins.__import__\n"
+ "def block_fcntl(name, *a, **k):\n"
+ " if name == 'fcntl' and 'fcntl' not in sys.modules:\n"
+ " raise ModuleNotFoundError(\"No module named 'fcntl'\")\n"
+ " return real_import(name, *a, **k)\n"
+ "builtins.__import__ = block_fcntl\n"
+ "sys.modules.pop('fcntl', None)\n"
+ "import sitecustomize\n"
+ f"sys.path.insert(0, {str(repo / 'dm/tools')!r})\n"
+ "import tree_tar\n"
+ f"assert tree_tar._lock({str(Path(td) / 'dd')!r}) is True\n"
+ f"tree_tar._unlock({str(Path(td) / 'dd')!r})\n"
+ )
+ r = subprocess.run([sys.executable, '-S', '-c', code],
+ env={**os.environ, 'PYTHONPATH': str(sd)},
+ capture_output=True, text=True)
+ self.assertEqual(r.returncode, 0, r.stderr)
+
+ # Also verify driver.load_upstream installs the fcntl stub when missing
+ saved_fcntl = sys.modules.pop('fcntl', None)
+ try:
+ mod = driver.load_upstream(repo)
+ self.assertIn('fcntl', sys.modules)
+ self.assertTrue(hasattr(mod, 'tree_tar'))
+ with tempfile.TemporaryDirectory() as td2:
+ self.assertTrue(mod.tree_tar._lock(Path(td2) / 'dd'))
+ finally:
+ if saved_fcntl is not None:
+ sys.modules['fcntl'] = saved_fcntl
+
+ def test_build_app_reads_packed_shader_lib_img(self) -> None:
+ """Engine 1.2 packs `b-<chain>/` into `b-<chain>.img` and deletes the folder; build_app must read `.img`."""
+ from nspb_qt.win import build_app
+ repo = QT.parent / 'engine'
+ slib_path = repo / 'dm/tools/shader_lib.py'
+ if not slib_path.is_file():
+ self.skipTest('engine/ is missing')
+ with tempfile.TemporaryDirectory() as td:
+ msl_ios = Path(td) / 'ios'
+ lib_dir = msl_ios / 'b-123456789abc'
+ lib_dir.mkdir(parents=True)
+ (lib_dir / '0001_b.metallib').write_bytes(b'MTLB_TEST')
+ (lib_dir / 'inputs.tsv').write_text('game\t0100E65002BB8000\ninputs\tabcdef01\n', encoding='utf-8')
+ r = subprocess.run([sys.executable, str(slib_path), 'pack', str(lib_dir)],
+ capture_output=True, text=True)
+ self.assertEqual(r.returncode, 0, r.stderr)
+ self.assertFalse(lib_dir.exists(), 'shader_lib.pack removes the folder')
+ self.assertTrue((msl_ios / 'b-123456789abc.img').is_file())
+ self.assertTrue(build_app.shader_lib_has(repo, lib_dir))
+ lines = build_app.shader_lib_stamp_lines(repo, lib_dir)
+ self.assertIn('game\t0100E65002BB8000', lines)
+ self.assertIn('inputs\tabcdef01', lines)
+
if __name__ == '__main__':
unittest.main(verbosity=2)