f2/testlib/env: build initial path via build_env

`build_env` is assumed to be a certain trivial environment, e.g. a
singleton search path.

An environment in general is either empty, contain one or more search
paths separated by a colon.

It seems that the intent was to set the `build_shell` first as a
prepended path in the managed environment then extend via the
`build_env` parts.

This fixes a usecase when the `BUILD_TEST_ENV` is non-trivial.

Change-Id: If5b8ab976d867a57ce0b8d29255f64695e30a8b2
Signed-off-by: Raito Bezarius <raito@lix.systems>
This commit is contained in:
Raito Bezarius
2026-01-06 10:13:01 +00:00
parent 9588b1ad1b
commit b730fab286
2 changed files with 13 additions and 2 deletions
+6 -2
View File
@@ -21,12 +21,16 @@ class _ManagedPath:
"""
build_shell: dataclasses.InitVar[str | None]
build_env: dataclasses.InitVar[str | None] = None
"""statically linked shell to use within builds which provides coreutils functionality"""
_path: list[str] = dataclasses.field(default_factory=list)
def __post_init__(self, build_shell: str | None):
def __post_init__(self, build_shell: str | None, build_env: str | None):
if build_shell:
self.prepend(build_shell)
if build_env:
for part in build_env.split(":"):
self.append(part)
def to_path(self) -> str:
"""
@@ -177,7 +181,7 @@ class ManagedEnv:
lix_bin = Path(environ.get("NIX_BIN_DIR", lix_base_folder / "outputs/out/bin"))
self._env = {}
self.path = _ManagedPath(build_env)
self.path = _ManagedPath(build_shell, build_env)
self._tmp_path = tmp_path
self.shell_dir = build_shell or "/bin"
self.build_env = build_env
@@ -225,6 +225,13 @@ def test_path_sandbox_entire_store_package():
assert re.fullmatch(r"^/nix/store/\w{32}-python3-3\.\d{1,2}\.\d{1,2}-[^/]+$", sb_paths[1])
def test_path_nontrivial_build_env():
path = _ManagedPath("/path/to/build_shell", "/path/to/busybox/bin:/path/to/acl/bin")
sb_paths = path.to_sandbox_paths()
assert len(sb_paths) == 3
assert sb_paths[0] == "/path/to/build_shell"
def test_path_which():
path = _ManagedPath("/path/to/build_shell")
with pytest.raises(ValueError, match="not in configured path"):