forge
Explore
Log in

Don't you dare go Hollow

🐛 Tests find hw-child when cargo's build-dir puts test binaries outside target/

Browse files at this commit

401e0926d70fcd753180102f8fdb43ae9649dfe9Ahmet Kaan GümüşParent: f7fa0fe
.cargo/config.tomladded+5 -0
@@ -0,0 +1,5 @@
1+# The workspace's own target directory, for the processes cargo and nextest start (tests,
2+# `cargo run`). With a `build-dir` set elsewhere, a test binary does not run from under
3+# `target/`, so the hardware seat looks for `hw-child` in the target directory named here.
4+[env]
5+EDITH_TARGET_DIR = { value = "target", relative = true }
crates/engine/src/hwproc.rsmodified+9 -2
@@ -394,7 +394,11 @@ pub fn recv_reply(sock: &mut UnixStream, body: &mut Vec<u8>) -> std::io::Result<
394394
395395 /// Where the helper lives: told outright, or beside the running executable --
396396 /// which is `target/<profile>/` for the editor and one directory up from
397-/// `deps/` for a test binary.
397+/// `deps/` for a test binary -- or, when cargo started the process, in the
398+/// workspace's target directory under this build's profile. That last place is
399+/// what a test finds the child in when cargo's `build-dir` puts the test
400+/// binaries outside `target/` (the workspace's `.cargo/config.toml` names it as
401+/// `EDITH_TARGET_DIR`).
398402 fn locate_child() -> Option<PathBuf> {
399403 if let Some(pinned) = crate::envcfg::var_os("VE_HW_CHILD_BIN") {
400404 let pinned = PathBuf::from(pinned);
@@ -402,8 +406,11 @@ fn locate_child() -> Option<PathBuf> {
402406 }
403407 let exe = std::env::current_exe().ok()?;
404408 let dir = exe.parent()?.to_path_buf();
405- [dir.join(BIN), dir.parent()?.join(BIN)]
409+ let profile = if cfg!(debug_assertions) { "debug" } else { "release" };
410+ let target = crate::envcfg::var_os("EDITH_TARGET_DIR").map(|t| PathBuf::from(t).join(profile).join(BIN));
411+ [Some(dir.join(BIN)), dir.parent().map(|up| up.join(BIN)), target]
406412 .into_iter()
413+ .flatten()
407414 .find(|candidate| candidate.is_file())
408415 }
409416