Bläddra i källkod

build_product_gui: use importlib for zipapp entrypoint and show stderr on self-test failure

Prod2U Recovery 2 månader sedan
förälder
incheckning
ed109f82a8
1 ändrade filer med 4 tillägg och 4 borttagningar
  1. 4 4
      tools/build_product_gui.py

+ 4 - 4
tools/build_product_gui.py

@@ -141,7 +141,7 @@ def validate_executable(exe, metadata, assets):
     cmd = [str(exe), '--self-test'] if raw.startswith(b'MZ') else [sys.executable, str(exe), '--self-test']
     run = subprocess.run(cmd, capture_output=True, timeout=60, creationflags=getattr(subprocess, 'CREATE_NO_WINDOW', 0))
     if run.returncode:
-        raise ValueError('offline GUI self-test failed: ' + str(run.returncode))
+        raise ValueError(f'offline GUI self-test failed ({run.returncode}): {run.stderr.decode(errors="replace")}')
     return {
         'schema': 'prod2u-gui-validation-v1',
         'exe_sha256': sha(exe),
@@ -208,12 +208,12 @@ def main(fixed_product=None):
             shutil.copytree(ROOT / 'tools/_vendor', tools_dir / '_vendor', dirs_exist_ok=True)
             script_stem = Path(PRODUCTS[product]['script']).stem
             (work / '__main__.py').write_text(
-                "import sys\n"
+                "import sys, importlib\n"
                 "from pathlib import Path\n"
                 "sys.path.insert(0, str(Path(__file__).resolve().parent))\n"
-                f"from tools.{script_stem} import main\n"
+                f"mod = importlib.import_module('tools.{script_stem}')\n"
                 "if __name__ == '__main__':\n"
-                "    raise SystemExit(main())\n",
+                "    raise SystemExit(mod.main())\n",
                 encoding='utf-8'
             )
             for path, destination in assets: