]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
Simplify workspace setup 1352/head
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Thu, 16 Feb 2023 12:38:56 +0000 (13:38 +0100)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Thu, 16 Feb 2023 14:49:04 +0000 (15:49 +0100)
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
mkosi/types.py

index 6087521450282f3616986d45c6fd879174a897c2..1ec973e07005b0b492b0c2addba38406006b55f8 100644 (file)
@@ -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):
 
index f544784fb8174a2a1f88ee91b7e5c1579d919699..e36cae82b46c22524655f80456980b0ccd0a1b68 100644 (file)
@@ -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]]