use super::path_util::{default_bin_rel, default_lib_rel, join_dir};
use crate::utils::build::default_target_triple;
fn host_triple() -> String {
default_target_triple()
}
pub fn bin_path(profile: &str, name: &str, target_dir: Option<&str>) -> String {
match target_dir {
Some(dir) => join_dir(dir, name),
None => default_bin_rel(profile, name, Some(&host_triple())),
}
}
pub fn lib_path(profile: &str, name: &str, target_dir: Option<&str>) -> String {
let file = format!("lib{name}.a");
match target_dir {
Some(dir) => join_dir(dir, &file),
None => default_lib_rel(profile, &file, Some(&host_triple())),
}
}
pub fn elf_path(profile: &str, name: &str, target_dir: Option<&str>) -> String {
bin_path(profile, name, target_dir)
}
pub fn efi_path(profile: &str, name: &str, target_dir: Option<&str>) -> String {
let file = format!("{name}.efi");
match target_dir {
Some(dir) => join_dir(dir, &file),
None => default_lib_rel(profile, &file, Some(&host_triple())),
}
}
pub fn shared_lib_path(profile: &str, name: &str, target_dir: Option<&str>) -> String {
let file = format!("lib{name}.so");
match target_dir {
Some(dir) => join_dir(dir, &file),
None => default_lib_rel(profile, &file, Some(&host_triple())),
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn bin_path_default() {
let expected = default_bin_rel("debug", "hello", Some(&host_triple()));
assert_eq!(bin_path("debug", "hello", None), expected);
}
#[test]
fn lib_path_default() {
let expected = default_lib_rel("debug", "libmylib.a", Some(&host_triple()));
assert_eq!(lib_path("debug", "mylib", None), expected);
}
#[test]
fn shared_lib_path_default() {
let expected = default_lib_rel("debug", "libmylib.so", Some(&host_triple()));
assert_eq!(shared_lib_path("debug", "mylib", None), expected);
}
}