mirror of https://github.com/pyodide/pyodide.git
fix(build): lock around logging and archiving portions (#2262)
* fix: lock around logging and archiving portions Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com> * refactor: fewer locks Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
This commit is contained in:
parent
3002751887
commit
37c8a70479
|
@ -15,7 +15,7 @@ from pathlib import Path
|
|||
from queue import PriorityQueue, Queue
|
||||
from threading import Lock, Thread
|
||||
from time import perf_counter, sleep
|
||||
from typing import Any, Optional
|
||||
from typing import Any, ClassVar, Optional
|
||||
|
||||
from . import common
|
||||
from .buildpkg import needs_rebuild
|
||||
|
@ -79,6 +79,9 @@ class StdLibPackage(BasePackage):
|
|||
|
||||
@total_ordering
|
||||
class Package(BasePackage):
|
||||
# If the CWD matters, hold this lock
|
||||
cwd_lock: ClassVar[Lock] = Lock()
|
||||
|
||||
def __init__(self, pkgdir: Path):
|
||||
self.pkgdir = pkgdir
|
||||
|
||||
|
@ -120,6 +123,9 @@ class Package(BasePackage):
|
|||
return None
|
||||
|
||||
def build(self, outputdir: Path, args) -> None:
|
||||
with self.__class__.cwd_lock:
|
||||
log_dir = Path(args.log_dir).resolve() if args.log_dir else None
|
||||
|
||||
with open(self.pkgdir / "build.log.tmp", "w") as f:
|
||||
p = subprocess.run(
|
||||
[
|
||||
|
@ -162,9 +168,10 @@ class Package(BasePackage):
|
|||
|
||||
if rebuilt:
|
||||
shutil.move(self.pkgdir / "build.log.tmp", self.pkgdir / "build.log")
|
||||
if args.log_dir and (self.pkgdir / "build.log").exists():
|
||||
if log_dir and (self.pkgdir / "build.log").exists():
|
||||
shutil.copy(
|
||||
self.pkgdir / "build.log", Path(args.log_dir) / f"{self.name}.log"
|
||||
self.pkgdir / "build.log",
|
||||
log_dir / f"{self.name}.log",
|
||||
)
|
||||
else:
|
||||
(self.pkgdir / "build.log.tmp").unlink()
|
||||
|
@ -181,11 +188,12 @@ class Package(BasePackage):
|
|||
if self.library:
|
||||
return
|
||||
if self.shared_library:
|
||||
file_path = shutil.make_archive(
|
||||
f"{self.name}-{self.version}", "zip", self.pkgdir / "dist"
|
||||
)
|
||||
shutil.copy(file_path, outputdir)
|
||||
Path(file_path).unlink()
|
||||
with self.__class__.cwd_lock:
|
||||
file_path = shutil.make_archive(
|
||||
f"{self.name}-{self.version}", "zip", self.pkgdir / "dist"
|
||||
)
|
||||
shutil.copy(file_path, outputdir)
|
||||
Path(file_path).unlink()
|
||||
return
|
||||
shutil.copy(self.wheel_path(), outputdir)
|
||||
test_path = self.tests_path()
|
||||
|
@ -380,9 +388,8 @@ def build_from_graph(pkg_map: dict[str, BasePackage], outputdir: Path, args) ->
|
|||
built_queue: Queue = Queue()
|
||||
thread_lock = Lock()
|
||||
queue_idx = 1
|
||||
package_set: dict[
|
||||
str, None
|
||||
] = {} # using dict keys for insertion order preservation
|
||||
# Using dict keys for insertion order preservation
|
||||
package_set: dict[str, None] = {}
|
||||
|
||||
def builder(n):
|
||||
nonlocal queue_idx
|
||||
|
|
Loading…
Reference in New Issue