|
| 1 | +From eb36791f873dd645b1cbfa693b9c246943647190 Mon Sep 17 00:00:00 2001 |
| 2 | +From: Moritz Sanft <58110325+msanft@users.noreply.github.com> |
| 3 | +Date: Tue, 3 Sep 2024 08:57:26 +0200 |
| 4 | +Subject: [PATCH 1/3] Use wrapped binaries instead of Python interpreter |
| 5 | + |
| 6 | +Rather than calling ukify and mkosi with sys.executable, which doesn't use the Python wrappers for PATH and PYTHONPATH, we call the wrapped binaries directly. |
| 7 | + |
| 8 | +Signed-off-by: Moritz Sanft <58110325+msanft@users.noreply.github.com> |
| 9 | +--- |
| 10 | + mkosi/__init__.py | 19 ++++--------------- |
| 11 | + mkosi/run.py | 8 ++++---- |
| 12 | + 2 files changed, 8 insertions(+), 19 deletions(-) |
| 13 | + |
| 14 | +diff --git a/mkosi/__init__.py b/mkosi/__init__.py |
| 15 | +index cc8482c4..ba44ad31 100644 |
| 16 | +--- a/mkosi/__init__.py |
| 17 | ++++ b/mkosi/__init__.py |
| 18 | +@@ -2059,16 +2059,7 @@ def join_initrds(initrds: Sequence[Path], output: Path) -> Path: |
| 19 | + |
| 20 | + |
| 21 | + def python_binary(config: Config, *, binary: Optional[PathString]) -> PathString: |
| 22 | +- tools = ( |
| 23 | +- not binary or |
| 24 | +- not (path := config.find_binary(binary)) or |
| 25 | +- not any(path.is_relative_to(d) for d in config.extra_search_paths) |
| 26 | +- ) |
| 27 | +- |
| 28 | +- # If there's no tools tree, prefer the interpreter from MKOSI_INTERPRETER. If there is a tools |
| 29 | +- # tree, just use the default python3 interpreter. |
| 30 | +- exe = Path(sys.executable) |
| 31 | +- return "python3" if (tools and config.tools_tree) or not exe.is_relative_to("/usr") else exe |
| 32 | ++ return "@PYTHON_PEFILE@" |
| 33 | + |
| 34 | + |
| 35 | + def extract_pe_section(context: Context, binary: Path, section: str, output: Path) -> Path: |
| 36 | +@@ -2135,11 +2126,10 @@ def build_uki( |
| 37 | + if not (arch := context.config.architecture.to_efi()): |
| 38 | + die(f"Architecture {context.config.architecture} does not support UEFI") |
| 39 | + |
| 40 | +- if not (ukify := context.config.find_binary("ukify", "/usr/lib/systemd/ukify")): |
| 41 | ++ if not (ukify := context.config.find_binary("ukify", "@UKIFY@")): |
| 42 | + die("Could not find ukify") |
| 43 | + |
| 44 | + cmd: list[PathString] = [ |
| 45 | +- python_binary(context.config, binary=ukify), |
| 46 | + ukify, |
| 47 | + *(["--cmdline", f"@{context.workspace / 'cmdline'}"] if cmdline else []), |
| 48 | + "--os-release", f"@{context.root / 'usr/lib/os-release'}", |
| 49 | +@@ -2213,7 +2203,6 @@ def build_uki( |
| 50 | + # new .ucode section support? |
| 51 | + if ( |
| 52 | + systemd_tool_version( |
| 53 | +- python_binary(context.config, binary=ukify), |
| 54 | + ukify, |
| 55 | + sandbox=context.sandbox, |
| 56 | + ) >= "256" and |
| 57 | +@@ -2303,7 +2292,7 @@ def want_uki(context: Context) -> bool: |
| 58 | + context.config.unified_kernel_images == ConfigFeature.enabled or ( |
| 59 | + context.config.unified_kernel_images == ConfigFeature.auto and |
| 60 | + systemd_stub_binary(context).exists() and |
| 61 | +- context.config.find_binary("ukify", "/usr/lib/systemd/ukify") is not None |
| 62 | ++ context.config.find_binary("ukify", "@UKIFY@") is not None |
| 63 | + ) |
| 64 | + ) |
| 65 | + |
| 66 | +@@ -2914,7 +2903,7 @@ def check_ukify( |
| 67 | + reason: str, |
| 68 | + hint: Optional[str] = None, |
| 69 | + ) -> None: |
| 70 | +- ukify = check_tool(config, "ukify", "/usr/lib/systemd/ukify", reason=reason, hint=hint) |
| 71 | ++ ukify = check_tool(config, "ukify", "@UKIFY@", reason=reason, hint=hint) |
| 72 | + |
| 73 | + v = systemd_tool_version(python_binary(config, binary=ukify), ukify, sandbox=config.sandbox) |
| 74 | + if v < version: |
| 75 | +diff --git a/mkosi/run.py b/mkosi/run.py |
| 76 | +index fd3bc98e..de47349a 100644 |
| 77 | +--- a/mkosi/run.py |
| 78 | ++++ b/mkosi/run.py |
| 79 | +@@ -450,7 +450,7 @@ def sandbox_cmd( |
| 80 | + ) -> Iterator[list[PathString]]: |
| 81 | + cmdline: list[PathString] = [ |
| 82 | + *setup, |
| 83 | +- sys.executable, "-SI", mkosi.sandbox.__file__, |
| 84 | ++ @MKOSI_SANDBOX@, |
| 85 | + "--proc", "/proc", |
| 86 | + # We mounted a subdirectory of TMPDIR to /var/tmp so we unset TMPDIR so that /tmp or /var/tmp are used instead. |
| 87 | + "--unsetenv", "TMPDIR", |
| 88 | +@@ -563,7 +563,7 @@ def apivfs_options(*, root: Path = Path("/buildroot")) -> list[PathString]: |
| 89 | + def apivfs_script_cmd(*, tools: bool, options: Sequence[PathString] = ()) -> list[PathString]: |
| 90 | + exe = Path(sys.executable) |
| 91 | + return [ |
| 92 | +- "python3" if tools or not exe.is_relative_to("/usr") else exe, "-SI", "/sandbox.py", |
| 93 | ++ @MKOSI_SANDBOX@, |
| 94 | + "--bind", "/", "/", |
| 95 | + "--same-dir", |
| 96 | + "--bind", "/var/tmp", "/buildroot/var/tmp", |
| 97 | +@@ -597,7 +597,7 @@ def chroot_cmd( |
| 98 | + options: Sequence[PathString] = (), |
| 99 | + ) -> Iterator[list[PathString]]: |
| 100 | + cmdline: list[PathString] = [ |
| 101 | +- sys.executable, "-SI", mkosi.sandbox.__file__, |
| 102 | ++ @MKOSI_SANDBOX@, |
| 103 | + "--bind", root, "/", |
| 104 | + # We mounted a subdirectory of TMPDIR to /var/tmp so we unset TMPDIR so that /tmp or /var/tmp are used instead. |
| 105 | + "--unsetenv", "TMPDIR", |
| 106 | +@@ -619,7 +619,7 @@ def chroot_cmd( |
| 107 | + def chroot_script_cmd(*, tools: bool, network: bool = False, work: bool = False) -> list[PathString]: |
| 108 | + exe = Path(sys.executable) |
| 109 | + return [ |
| 110 | +- "python3" if tools or not exe.is_relative_to("/usr") else exe, "-SI", "/sandbox.py", |
| 111 | ++ @MKOSI_SANDBOX@, |
| 112 | + "--bind", "/buildroot", "/", |
| 113 | + "--bind", "/var/tmp", "/var/tmp", |
| 114 | + *apivfs_options(root=Path("/")), |
| 115 | +-- |
| 116 | +2.45.2 |
0 commit comments