mirror of
https://github.com/dexoron/dcr.git
synced 2026-10-21 18:39:42 +00:00
fix: keep native host artifact paths and cross-platform path assertions
This commit is contained in:
@@ -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]
|
||||
|
||||
@@ -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"));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user