From 5d3d9c0d828afba6108232ce4301a6aa2c73b023 Mon Sep 17 00:00:00 2001 From: Daan De Meyer Date: Thu, 16 Feb 2023 13:38:56 +0100 Subject: [PATCH] Simplify workspace setup With the move to bubblewrap we don't run into issues anymore when the workspace is located in the source directory so let's simplify the workspace setup. --- mkosi/__init__.py | 27 +++------------------------ mkosi/types.py | 3 --- 2 files changed, 3 insertions(+), 27 deletions(-) diff --git a/mkosi/__init__.py b/mkosi/__init__.py index 608752145..1ec973e07 100644 --- a/mkosi/__init__.py +++ b/mkosi/__init__.py @@ -75,7 +75,7 @@ from mkosi.run import ( run_workspace_command, spawn, ) -from mkosi.types import PathString, TempDir +from mkosi.types import PathString complete_step = MkosiPrinter.complete_step color_error = MkosiPrinter.color_error @@ -148,27 +148,6 @@ def format_bytes(num_bytes: int) -> str: return f"{num_bytes}B" - -def setup_workspace(config: MkosiConfig) -> TempDir: - with complete_step("Setting up temporary workspace.", "Temporary workspace set up in {.name}") as output: - if config.workspace_dir is not None: - d = tempfile.TemporaryDirectory(dir=config.workspace_dir, prefix="") - else: - p = config.output.parent - - # The build sources might be mounted inside the workspace directory so if the workspace directory - # is located inside the build sources directory, we get an infinite mount loop which causes all - # sorts of issues, so let's make sure the workspace directory is located outside of the sources - # directory. - while str(p).startswith(str(config.build_sources)): - p = p.parent - - d = tempfile.TemporaryDirectory(dir=p, prefix=f".mkosi.{config.build_sources.name}.tmp") - output.append(d) - - return d - - def btrfs_subvol_create(path: Path, mode: int = 0o755) -> None: with set_umask(~mode & 0o7777): run(["btrfs", "subvol", "create", path]) @@ -3376,7 +3355,7 @@ def remove_artifacts(state: MkosiState, for_cache: bool = False) -> None: def build_stuff(uid: int, gid: int, config: MkosiConfig) -> None: - workspace = setup_workspace(config) + workspace = tempfile.TemporaryDirectory(dir=config.workspace_dir or Path.cwd(), prefix=".mkosi.tmp") workspace_dir = Path(workspace.name) cache = config.cache_path or workspace_dir / "cache" @@ -3399,7 +3378,7 @@ def build_stuff(uid: int, gid: int, config: MkosiConfig) -> None: # Make sure tmpfiles' aging doesn't interfere with our workspace # while we are working on it. - with flock(workspace_dir): + with flock(workspace_dir), workspace: # If caching is requested, then make sure we have cache trees around we can make use of if need_cache_trees(state): diff --git a/mkosi/types.py b/mkosi/types.py index f544784fb..e36cae82b 100644 --- a/mkosi/types.py +++ b/mkosi/types.py @@ -1,5 +1,4 @@ import subprocess -import tempfile from pathlib import Path from typing import IO, TYPE_CHECKING, Any, Union @@ -9,11 +8,9 @@ from typing import IO, TYPE_CHECKING, Any, Union if TYPE_CHECKING: CompletedProcess = subprocess.CompletedProcess[Any] Popen = subprocess.Popen[Any] - TempDir = tempfile.TemporaryDirectory[str] else: CompletedProcess = subprocess.CompletedProcess Popen = subprocess.Popen - TempDir = tempfile.TemporaryDirectory # Borrowed from https://github.com/python/typeshed/blob/3d14016085aed8bcf0cf67e9e5a70790ce1ad8ea/stdlib/3/subprocess.pyi#L24 _FILE = Union[None, int, IO[Any]] -- 2.47.2