fix: keep native host artifact paths and cross-platform path assertions

This commit is contained in:
2026-08-05 01:00:01 +08:00
parent b9cbef43e9
commit 3f925f437f
2 changed files with 30 additions and 33 deletions

View File

@@ -350,33 +350,39 @@ mod tests {
let p = resolve_artifact_path("bin", "debug", "hello", None, None, None).unwrap(); let p = resolve_artifact_path("bin", "debug", "hello", None, None, None).unwrap();
if cfg!(target_os = "linux") { if cfg!(target_os = "linux") {
let arch = std::env::consts::ARCH; let arch = std::env::consts::ARCH;
assert_eq!(p, format!("./target/{arch}-unknown-linux-gnu/debug/hello")); let expected = Path::new("./target")
.join(format!("{arch}-unknown-linux-gnu"))
.join("debug")
.join("hello");
assert_eq!(p, expected.to_string_lossy());
} else if cfg!(windows) { } else if cfg!(windows) {
assert_eq!(p, "./target/debug/hello.exe"); let expected = Path::new("./target").join("debug").join("hello.exe");
assert_eq!(p, expected.to_string_lossy());
} else { } else {
assert_eq!(p, "./target/debug/hello"); let expected = Path::new("./target").join("debug").join("hello");
assert_eq!(p, expected.to_string_lossy());
} }
} }
#[test] #[test]
fn resolve_bin_custom_target_dir() { fn resolve_bin_custom_target_dir() {
let p = resolve_artifact_path("bin", "debug", "hello", Some("/out"), None, None).unwrap(); let p = resolve_artifact_path("bin", "debug", "hello", Some("/out"), None, None).unwrap();
if cfg!(windows) { let name = if cfg!(windows) { "hello.exe" } else { "hello" };
assert_eq!(p, "/out/hello.exe"); let expected = Path::new("/out").join(name);
} else { assert_eq!(p, expected.to_string_lossy());
assert_eq!(p, "/out/hello");
}
} }
#[test] #[test]
fn resolve_staticlib() { fn resolve_staticlib() {
let p = resolve_artifact_path("staticlib", "release", "mylib", Some("dist"), None, None) let p = resolve_artifact_path("staticlib", "release", "mylib", Some("dist"), None, None)
.unwrap(); .unwrap();
if cfg!(windows) { let name = if cfg!(windows) {
assert_eq!(p, "dist/mylib.lib"); "mylib.lib"
} else { } else {
assert_eq!(p, "dist/libmylib.a"); "libmylib.a"
} };
let expected = Path::new("dist").join(name);
assert_eq!(p, expected.to_string_lossy());
} }
#[test] #[test]

View File

@@ -134,7 +134,7 @@ pub fn resolve_artifact_target_dir(
.into_owned(); .into_owned();
} }
let base = if has_explicit_target || !build_target.trim().is_empty() { let base = if has_explicit_target {
let triple = { let triple = {
let n = normalize_target_os(build_target.trim()); let n = normalize_target_os(build_target.trim());
if n.is_empty() { if n.is_empty() {
@@ -644,27 +644,18 @@ mod tests {
fn resolve_artifact_target_dir_native_and_workspace() { fn resolve_artifact_target_dir_native_and_workspace() {
let root = Path::new("/proj"); let root = Path::new("/proj");
let ws = Path::new("/ws"); let ws = Path::new("/ws");
let native = resolve_artifact_target_dir(root, None, "debug", "", "", false); let host = default_target_triple();
if cfg!(target_os = "linux") let native = resolve_artifact_target_dir(root, None, "debug", &host, "", false);
|| cfg!(any( let expected_native = root.join(native_host_target_rel("debug"));
target_os = "freebsd", assert_eq!(native, expected_native.to_string_lossy());
target_os = "openbsd",
target_os = "netbsd", let explicit =
target_os = "dragonfly" resolve_artifact_target_dir(root, None, "debug", "x86_64-unknown-linux-gnu", "", true);
)) assert!(explicit.contains("x86_64-unknown-linux-gnu"));
{
assert!(native.contains(&default_target_triple())); let ws_dir = resolve_artifact_target_dir(root, Some(ws), "debug", &host, "", false);
assert!(native.ends_with("debug") || native.contains("/debug"));
} else {
assert!(
native.ends_with("debug")
|| native.ends_with("debug\\")
|| native.contains("target")
);
}
let ws_dir = resolve_artifact_target_dir(root, Some(ws), "debug", "", "", false);
assert!(ws_dir.starts_with("/ws") || ws_dir.contains("ws")); assert!(ws_dir.starts_with("/ws") || ws_dir.contains("ws"));
assert!(ws_dir.contains(&default_target_triple()) || cfg!(windows)); assert!(ws_dir.contains(&host) || cfg!(windows));
let out = resolve_artifact_target_dir(root, None, "debug", "", "dist", false); let out = resolve_artifact_target_dir(root, None, "debug", "", "dist", false);
assert!(out.contains("dist")); assert!(out.contains("dist"));
} }