Repository: pyodide/pyodide

Issue:
No logs when erroring on build package
I'm trying to build a package with Cyhton sources with the "in tree" approach.

When running 

```
pyodide build-recipes sisl --install
```

I get

```
The following packages are already built: boost-cpp, distutils, hashlib, libf2c, liblzma, lzma, micropip, numpy, openblas, openssl, packaging, pydecimal, pydoc_data, pyparsing,  
scipy, setuptools, sqlite3, ssl, test, and tqdm                                                                                                                                   
Building the following packages: sisl                                                                                                                                             
[1/1] (thread 1) building sisl ⠙                                                            
Building packages... ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 0/1   0% Time elapsed: 0:00:09Error building sisl. Printing build logs.                                                                                                                                         
ERROR: No build log found.                                                                                                                                                        
ERROR: cancelling buildall                                                                                                                                                        
[1/1] (thread 1) building sisl ⠹                                                            
Building packages... ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 0/1   0% Time elapsed: 0:00:09
```

Therefore, I have no clue what's wrong. When does an error without build logs happen? Can I get some more verbose output in some way? Thanks!

I'm running this on the Docker container, after succesfully building all packages, even an old version of the package I'm trying to build.


Discussion:

Resolving patch:
diff --git a/pyodide-build/pyodide_build/buildpkg.py b/pyodide-build/pyodide_build/buildpkg.py
--- a/pyodide-build/pyodide_build/buildpkg.py
+++ b/pyodide-build/pyodide_build/buildpkg.py
@@ -426,13 +426,7 @@ def compile(
         from .pypabuild import build
 
         outpath = srcpath / "dist"
-        try:
-            build(srcpath, outpath, build_env, backend_flags)
-        except BaseException:
-            build_log_path = Path("build.log")
-            if build_log_path.exists():
-                build_log_path.unlink()
-            raise
+        build(srcpath, outpath, build_env, backend_flags)
 
 
 def replace_so_abi_tags(wheel_dir: Path) -> None:
diff --git a/pyodide-build/pyodide_build/cli/build.py b/pyodide-build/pyodide_build/cli/build.py
--- a/pyodide-build/pyodide_build/cli/build.py
+++ b/pyodide-build/pyodide_build/cli/build.py
@@ -1,5 +1,6 @@
 import re
 import shutil
+import sys
 import tempfile
 from pathlib import Path
 from typing import Optional
@@ -113,9 +114,12 @@ def main(
         help="Build source, can be source folder, pypi version specification, or url to a source dist archive or wheel file. If this is blank, it will build the current directory.",
     ),
     output_directory: str = typer.Option(
-        "./dist",
+        "",
+        "--outdir",
+        "-o",
         help="which directory should the output be placed into?",
     ),
+    output_directory_compat: str = typer.Option("", "--output-directory", hidden=True),
     requirements_txt: str = typer.Option(
         "",
         "--requirements",
@@ -143,6 +147,16 @@ def main(
     ctx: typer.Context = typer.Context,
 ) -> None:
     """Use pypa/build to build a Python package from source, pypi or url."""
+    if output_directory_compat:
+        print(
+            "--output-directory is deprecated, use --outdir or -o instead",
+            file=sys.stderr,
+        )
+    if output_directory_compat and output_directory:
+        print("Cannot provide both --outdir and --output-directory", file=sys.stderr)
+        sys.exit(1)
+    output_directory = output_directory_compat or output_directory or "./dist"
+
     outpath = Path(output_directory).resolve()
     outpath.mkdir(exist_ok=True)
     extras: list[str] = []


Test patch:
diff --git a/pyodide-build/pyodide_build/tests/test_cli.py b/pyodide-build/pyodide_build/tests/test_cli.py
--- a/pyodide-build/pyodide_build/tests/test_cli.py
+++ b/pyodide-build/pyodide_build/tests/test_cli.py
@@ -411,9 +411,7 @@ def mocked_build(srcdir: Path, outdir: Path, env: Any, backend_flags: Any) -> st
     srcdir.mkdir()
     app = typer.Typer()
     app.command(**build.main.typer_kwargs)(build.main)  # type:ignore[attr-defined]
-    result = runner.invoke(
-        app, [str(srcdir), "--output-directory", str(outdir), "x", "y", "z"]
-    )
+    result = runner.invoke(app, [str(srcdir), "--outdir", str(outdir), "x", "y", "z"])
     print(result)
     print(result.stdout)
     assert result.exit_code == 0
diff --git a/src/tests/test_cmdline_runner.py b/src/tests/test_cmdline_runner.py
--- a/src/tests/test_cmdline_runner.py
+++ b/src/tests/test_cmdline_runner.py
@@ -145,6 +145,32 @@ def test_invalid_cmdline_option(selenium):
     )
 
 
+@only_node
+def test_extra_mounts(selenium, tmp_path, monkeypatch):
+    dir_a = tmp_path / "a"
+    dir_b = tmp_path / "b"
+    dir_a.mkdir()
+    dir_b.mkdir()
+
+    tmp_path_a = dir_a / "script.py"
+    tmp_path_b = dir_b / "script.py"
+    tmp_path_a.write_text("print('hello 1')")
+    tmp_path_b.write_text("print('hello 2')")
+    monkeypatch.setenv("_PYODIDE_EXTRA_MOUNTS", f"{dir_a}:{dir_b}")
+    result = subprocess.run(
+        [script_path, tmp_path_a], capture_output=True, encoding="utf8"
+    )
+    assert result.returncode == 0
+    assert result.stdout == "hello 1\n"
+    assert result.stderr == ""
+    result = subprocess.run(
+        [script_path, tmp_path_b], capture_output=True, encoding="utf8"
+    )
+    assert result.returncode == 0
+    assert result.stdout == "hello 2\n"
+    assert result.stderr == ""
+
+
 @contextmanager
 def venv_ctxmgr(path):
     check_emscripten()