]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
Move sandbox tree logic into Config.sandbox()
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Tue, 27 Aug 2024 09:08:40 +0000 (11:08 +0200)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Tue, 27 Aug 2024 09:47:01 +0000 (11:47 +0200)
mkosi/config.py
mkosi/context.py

index 60f3ba452d0d6246e360517e610483321669996d..38769fb48c84ecd9f30d8a52947d1db6589c10af 100644 (file)
@@ -1763,7 +1763,7 @@ class Config:
         relaxed: bool = False,
         tools: bool = True,
         scripts: Optional[Path] = None,
-        usroverlaydirs: Sequence[PathString] = (),
+        sandbox_tree: Optional[Path] = None,
         options: Sequence[PathString] = (),
         setup: Sequence[PathString] = (),
     ) -> AbstractContextManager[list[PathString]]:
@@ -1782,6 +1782,15 @@ class Config:
             tools = False
             opt += flatten(("--ro-bind", d, d) for d in self.extra_search_paths if not relaxed)
 
+        if sandbox_tree:
+            opt += [
+                # This mount is writable so we can create extra directories or symlinks inside of it as needed.
+                # This isn't a problem as the sandbox tree directory is created by mkosi and thrown away when the
+                # build finishes.
+                *(["--bind", str(p), "/etc"] if (p := sandbox_tree / "etc").exists() else []),
+                *(["--bind", str(p), "/var/log"] if (p := sandbox_tree / "var/log").exists() else []),
+            ]
+
         return sandbox_cmd(
             network=network,
             devices=devices,
@@ -1789,7 +1798,7 @@ class Config:
             relaxed=relaxed,
             scripts=scripts,
             tools=self.tools() if tools else Path("/"),
-            usroverlaydirs=usroverlaydirs,
+            usroverlaydirs=[sandbox_tree / "usr"] if sandbox_tree and (sandbox_tree / "usr").exists() else [],
             options=opt,
             setup=setup,
         )
index 22ed6d1ae3f7a0c4e3e86ed0754a281e076b798f..5f2ae122289ed73e61e42d31b6add1cb5a099cda 100644 (file)
@@ -76,13 +76,6 @@ class Context:
             devices=devices,
             vartmp=vartmp,
             scripts=scripts,
-            usroverlaydirs=[self.sandbox_tree / "usr"] if (self.sandbox_tree / "usr").exists() else [],
-            options=[
-                *options,
-                # This mount is writable so we can create extra directories or symlinks inside of it as needed.
-                # This isn't a problem as the package manager directory is created by mkosi and thrown away when the
-                # build finishes.
-                "--bind", self.sandbox_tree / "etc", "/etc",
-                "--bind", self.sandbox_tree / "var/log", "/var/log",
-            ],
+            sandbox_tree=self.sandbox_tree,
+            options=options,
         )