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
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])
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"
# 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):
import subprocess
-import tempfile
from pathlib import Path
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]]