From 3f925f437f56181225094c2e87c9f5d1e940ba42 Mon Sep 17 00:00:00 2001 From: Dexoron Date: Wed, 5 Aug 2026 01:00:01 +0800 Subject: [PATCH] fix: keep native host artifact paths and cross-platform path assertions --- src/core/build/builder/artifact.rs | 30 ++++++++++++++++----------- src/utils/build.rs | 33 +++++++++++------------------- 2 files changed, 30 insertions(+), 33 deletions(-) diff --git a/src/core/build/builder/artifact.rs b/src/core/build/builder/artifact.rs index 8b2244b..f99f668 100644 --- a/src/core/build/builder/artifact.rs +++ b/src/core/build/builder/artifact.rs @@ -350,33 +350,39 @@ mod tests { let p = resolve_artifact_path("bin", "debug", "hello", None, None, None).unwrap(); if cfg!(target_os = "linux") { 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) { - 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 { - assert_eq!(p, "./target/debug/hello"); + let expected = Path::new("./target").join("debug").join("hello"); + assert_eq!(p, expected.to_string_lossy()); } } #[test] fn resolve_bin_custom_target_dir() { let p = resolve_artifact_path("bin", "debug", "hello", Some("/out"), None, None).unwrap(); - if cfg!(windows) { - assert_eq!(p, "/out/hello.exe"); - } else { - assert_eq!(p, "/out/hello"); - } + let name = if cfg!(windows) { "hello.exe" } else { "hello" }; + let expected = Path::new("/out").join(name); + assert_eq!(p, expected.to_string_lossy()); } #[test] fn resolve_staticlib() { let p = resolve_artifact_path("staticlib", "release", "mylib", Some("dist"), None, None) .unwrap(); - if cfg!(windows) { - assert_eq!(p, "dist/mylib.lib"); + let name = if cfg!(windows) { + "mylib.lib" } else { - assert_eq!(p, "dist/libmylib.a"); - } + "libmylib.a" + }; + let expected = Path::new("dist").join(name); + assert_eq!(p, expected.to_string_lossy()); } #[test] diff --git a/src/utils/build.rs b/src/utils/build.rs index 86b2c1e..2094ebf 100644 --- a/src/utils/build.rs +++ b/src/utils/build.rs @@ -134,7 +134,7 @@ pub fn resolve_artifact_target_dir( .into_owned(); } - let base = if has_explicit_target || !build_target.trim().is_empty() { + let base = if has_explicit_target { let triple = { let n = normalize_target_os(build_target.trim()); if n.is_empty() { @@ -644,27 +644,18 @@ mod tests { fn resolve_artifact_target_dir_native_and_workspace() { let root = Path::new("/proj"); let ws = Path::new("/ws"); - let native = resolve_artifact_target_dir(root, None, "debug", "", "", false); - if cfg!(target_os = "linux") - || cfg!(any( - target_os = "freebsd", - target_os = "openbsd", - target_os = "netbsd", - target_os = "dragonfly" - )) - { - assert!(native.contains(&default_target_triple())); - 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); + let host = default_target_triple(); + let native = resolve_artifact_target_dir(root, None, "debug", &host, "", false); + let expected_native = root.join(native_host_target_rel("debug")); + assert_eq!(native, expected_native.to_string_lossy()); + + let explicit = + resolve_artifact_target_dir(root, None, "debug", "x86_64-unknown-linux-gnu", "", true); + assert!(explicit.contains("x86_64-unknown-linux-gnu")); + + let ws_dir = resolve_artifact_target_dir(root, Some(ws), "debug", &host, "", false); 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); assert!(out.contains("dist")); }