Skip to main content

ic_testkit/artifacts/
workspace.rs

1use std::path::{Path, PathBuf};
2
3/// Resolve the conventional workspace root from a crate manifest directory.
4///
5/// A manifest directly below `<workspace>/crates` resolves to `<workspace>`;
6/// other paths are returned unchanged.
7#[must_use]
8pub fn workspace_root_for(crate_manifest_dir: &str) -> PathBuf {
9    let manifest_dir = PathBuf::from(crate_manifest_dir);
10    if manifest_dir.parent().and_then(Path::file_name) == Some(std::ffi::OsStr::new("crates")) {
11        return manifest_dir
12            .parent()
13            .and_then(Path::parent)
14            .map(PathBuf::from)
15            .expect("workspace root");
16    }
17
18    manifest_dir
19}
20
21/// Return `<workspace>/target/<name>` for isolated host-side test artifacts.
22#[must_use]
23pub fn test_target_dir(workspace_root: &Path, name: &str) -> PathBuf {
24    workspace_root.join("target").join(name)
25}