diff --git a/pyodide-build/pyodide_build/buildall.py b/pyodide-build/pyodide_build/buildall.py index a7fe28497..02b542f8c 100755 --- a/pyodide-build/pyodide_build/buildall.py +++ b/pyodide-build/pyodide_build/buildall.py @@ -119,59 +119,42 @@ class Package(BasePackage): def build(self, outputdir: Path, args) -> None: - with open(self.pkgdir / "build.log.tmp", "w") as f: - p = subprocess.run( - [ - sys.executable, - "-m", - "pyodide_build", - "buildpkg", - str(self.pkgdir / "meta.yaml"), - "--cflags", - args.cflags, - "--cxxflags", - args.cxxflags, - "--ldflags", - args.ldflags, - "--target-install-dir", - args.target_install_dir, - "--host-install-dir", - args.host_install_dir, - # Either this package has been updated and this doesn't - # matter, or this package is dependent on a package that has - # been updated and should be rebuilt even though its own - # files haven't been updated. - "--force-rebuild", - ], - check=False, - stdout=f, - stderr=subprocess.STDOUT, + p = subprocess.run( + [ + sys.executable, + "-m", + "pyodide_build", + "buildpkg", + str(self.pkgdir / "meta.yaml"), + "--cflags", + args.cflags, + "--cxxflags", + args.cxxflags, + "--ldflags", + args.ldflags, + "--target-install-dir", + args.target_install_dir, + "--host-install-dir", + args.host_install_dir, + # Either this package has been updated and this doesn't + # matter, or this package is dependent on a package that has + # been updated and should be rebuilt even though its own + # files haven't been updated. + "--force-rebuild", + ], + check=False, + stdout=subprocess.DEVNULL, + stderr=subprocess.DEVNULL, + ) + + log_dir = Path(args.log_dir).resolve() if args.log_dir else None + if log_dir and (self.pkgdir / "build.log").exists(): + log_dir.mkdir(exist_ok=True, parents=True) + shutil.copy( + self.pkgdir / "build.log", + log_dir / f"{self.name}.log", ) - # Don't overwrite build log if we didn't build the file. - # If the file didn't need to be rebuilt, the log will have exactly two lines. - rebuilt = True - with open(self.pkgdir / "build.log.tmp") as f: - try: - next(f) - next(f) - next(f) - except StopIteration: - rebuilt = False - - if rebuilt: - shutil.move(self.pkgdir / "build.log.tmp", self.pkgdir / "build.log") - log_dir = Path(args.log_dir).resolve() if args.log_dir else None - - if log_dir and (self.pkgdir / "build.log").exists(): - log_dir.mkdir(exist_ok=True, parents=True) - shutil.copy( - self.pkgdir / "build.log", - log_dir / f"{self.name}.log", - ) - else: - (self.pkgdir / "build.log.tmp").unlink() - if p.returncode != 0: print(f"Error building {self.name}. Printing build logs.") diff --git a/pyodide-build/pyodide_build/buildpkg.py b/pyodide-build/pyodide_build/buildpkg.py index 6e08126fc..e264a64c9 100755 --- a/pyodide-build/pyodide_build/buildpkg.py +++ b/pyodide-build/pyodide_build/buildpkg.py @@ -678,6 +678,16 @@ def build_package( f"directory at the path {srcpath}, but that path does not exist." ) + import os + import subprocess + import sys + + tee = subprocess.Popen(["tee", pkg_root / "build.log"], stdin=subprocess.PIPE) + # Cause tee's stdin to get a copy of our stdin/stdout (as well as that + # of any child processes we spawn) + os.dup2(tee.stdin.fileno(), sys.stdout.fileno()) # type: ignore[union-attr] + os.dup2(tee.stdin.fileno(), sys.stderr.fileno()) # type: ignore[union-attr] + with chdir(pkg_root), get_bash_runner() as bash_runner: bash_runner.env["PKG_VERSION"] = version if not continue_: