🐛 Tests find hw-child when cargo's build-dir puts test binaries outside target/
Browse files at this commit401e0926d70fcd753180102f8fdb43ae9649dfe9Parent: f7fa0fe2 changed files +14 -2
- .cargo/config.toml +5 -0
- crates/engine/src/hwproc.rs +9 -2
.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< | ||
| 394 | 394 | |
| 395 | 395 | /// Where the helper lives: told outright, or beside the running executable -- |
| 396 | 396 | /// 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`). | |
| 398 | 402 | fn locate_child() -> Option<PathBuf> { |
| 399 | 403 | if let Some(pinned) = crate::envcfg::var_os("VE_HW_CHILD_BIN") { |
| 400 | 404 | let pinned = PathBuf::from(pinned); |
| @@ -402,8 +406,11 @@ fn locate_child() -> Option<PathBuf> { | ||
| 402 | 406 | } |
| 403 | 407 | let exe = std::env::current_exe().ok()?; |
| 404 | 408 | 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] | |
| 406 | 412 | .into_iter() |
| 413 | + .flatten() | |
| 407 | 414 | .find(|candidate| candidate.is_file()) |
| 408 | 415 | } |
| 409 | 416 |