From 9ffae14dbf7e919a353d845bfd5cf4a2b0e0a554 Mon Sep 17 00:00:00 2001 From: Hood Chatham Date: Sat, 19 Jun 2021 09:51:36 -0700 Subject: [PATCH] Store package build logs as circleci artifacts (#1646) --- .circleci/config.yml | 3 +++ .gitignore | 1 + packages/Makefile | 4 +++- pyodide-build/pyodide_build/buildall.py | 31 ++++++++++++++++++++++++- 4 files changed, 37 insertions(+), 2 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 598380093..60d300338 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -131,6 +131,9 @@ jobs: - store_artifacts: path: /root/repo/build/ + - store_artifacts: + path: /root/repo/packages/build-logs + test-core-firefox: <<: *defaults steps: diff --git a/.gitignore b/.gitignore index fb368a43c..0a1c3411a 100644 --- a/.gitignore +++ b/.gitignore @@ -25,4 +25,5 @@ geckodriver.log node_modules packages/.artifacts packages/*/build.log +packages/build-logs dist/ diff --git a/packages/Makefile b/packages/Makefile index b433a18c4..39a423bc0 100644 --- a/packages/Makefile +++ b/packages/Makefile @@ -8,8 +8,10 @@ else endif all: .artifacts/bin/pyodide-build + mkdir -p build-logs PYTHONPATH="$(PYODIDE_LIBRARIES)/lib/python:$(PYODIDE_ROOT)/pyodide-build/" pyodide-build buildall . ../build \ - --target=$(TARGETPYTHONROOT) $(ONLY_PACKAGES) --install-dir $(PYODIDE_LIBRARIES) --n-jobs $${PYODIDE_JOBS:-4} + --target=$(TARGETPYTHONROOT) $(ONLY_PACKAGES) --install-dir $(PYODIDE_LIBRARIES) --n-jobs $${PYODIDE_JOBS:-4} \ + --log-dir=build-logs .artifacts/bin/pyodide-build: ../pyodide-build/pyodide_build/** mkdir -p $(PYODIDE_LIBRARIES) diff --git a/pyodide-build/pyodide_build/buildall.py b/pyodide-build/pyodide_build/buildall.py index 4c7665d45..90b223a14 100755 --- a/pyodide-build/pyodide_build/buildall.py +++ b/pyodide-build/pyodide_build/buildall.py @@ -81,7 +81,7 @@ class Package(BasePackage): self.dependents = set() def build(self, outputdir: Path, args) -> None: - with open(self.pkgdir / "build.log", "w") as f: + with open(self.pkgdir / "build.log.tmp", "w") as f: p = subprocess.run( [ sys.executable, @@ -105,6 +105,27 @@ class Package(BasePackage): stderr=subprocess.STDOUT, ) + # 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", "r") 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") # type: ignore + else: + (self.pkgdir / "build.log.tmp").unlink() + + if args.log_dir: + shutil.copy( + self.pkgdir / "build.log", Path(args.log_dir) / f"{self.name}.log" + ) + try: p.check_returncode() except subprocess.CalledProcessError: @@ -337,6 +358,14 @@ def make_parser(parser): "needed if you want to build other packages that depend on this one." ), ) + parser.add_argument( + "--log-dir", + type=str, + dest="log_dir", + nargs="?", + default=None, + help=("Directory to place log files"), + ) parser.add_argument( "--only", type=str,