mirror of
https://github.com/dexoron/dcr.git
synced 2026-10-21 11:48:36 +00:00
feat: add .dcr/ build facts and canonical artifact paths for IDE integrations
This commit is contained in:
@@ -15,58 +15,45 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
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) => format!("{}/{}", dir.trim_end_matches('/'), name),
|
||||
None => {
|
||||
let arch = std::env::consts::ARCH;
|
||||
let target = format!("{arch}-unknown-linux-gnu");
|
||||
format!("./target/{target}/{profile}/{name}")
|
||||
}
|
||||
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) => format!("{}/lib{}.a", dir.trim_end_matches('/'), name),
|
||||
None => {
|
||||
let arch = std::env::consts::ARCH;
|
||||
let target = format!("{arch}-unknown-linux-gnu");
|
||||
format!("./target/{target}/{profile}/lib{name}.a")
|
||||
}
|
||||
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 {
|
||||
match target_dir {
|
||||
Some(dir) => format!("{}/{}", dir.trim_end_matches('/'), name),
|
||||
None => {
|
||||
let arch = std::env::consts::ARCH;
|
||||
let target = format!("{arch}-unknown-linux-gnu");
|
||||
format!("./target/{target}/{profile}/{name}")
|
||||
}
|
||||
}
|
||||
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) => format!("{}/{}.efi", dir.trim_end_matches('/'), name),
|
||||
None => {
|
||||
let arch = std::env::consts::ARCH;
|
||||
let target = format!("{arch}-unknown-linux-gnu");
|
||||
format!("./target/{target}/{profile}/{name}.efi")
|
||||
}
|
||||
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) => format!("{}/lib{}.so", dir.trim_end_matches('/'), name),
|
||||
None => {
|
||||
let arch = std::env::consts::ARCH;
|
||||
let target = format!("{arch}-unknown-linux-gnu");
|
||||
format!("./target/{target}/{profile}/lib{name}.so")
|
||||
}
|
||||
Some(dir) => join_dir(dir, &file),
|
||||
None => default_lib_rel(profile, &file, Some(&host_triple())),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,44 +63,49 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn bin_path_default() {
|
||||
let arch = std::env::consts::ARCH;
|
||||
let expected = format!("./target/{arch}-unknown-linux-gnu/debug/hello");
|
||||
let expected = default_bin_rel("debug", "hello", Some(&host_triple()));
|
||||
assert_eq!(bin_path("debug", "hello", None), expected);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn bin_path_release() {
|
||||
let arch = std::env::consts::ARCH;
|
||||
let expected = format!("./target/{arch}-unknown-linux-gnu/release/hello");
|
||||
let expected = default_bin_rel("release", "hello", Some(&host_triple()));
|
||||
assert_eq!(bin_path("release", "hello", None), expected);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn bin_path_custom_target() {
|
||||
assert_eq!(bin_path("debug", "hello", Some("out")), "out/hello");
|
||||
assert_eq!(
|
||||
bin_path("debug", "hello", Some("out")),
|
||||
join_dir("out", "hello")
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn bin_path_custom_target_trailing_slash() {
|
||||
assert_eq!(bin_path("debug", "hello", Some("out/")), "out/hello");
|
||||
assert_eq!(
|
||||
bin_path("debug", "hello", Some("out/")),
|
||||
join_dir("out/", "hello")
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn lib_path_default() {
|
||||
let arch = std::env::consts::ARCH;
|
||||
let expected = format!("./target/{arch}-unknown-linux-gnu/debug/libmylib.a");
|
||||
let expected = default_lib_rel("debug", "libmylib.a", Some(&host_triple()));
|
||||
assert_eq!(lib_path("debug", "mylib", None), expected);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn lib_path_custom_target() {
|
||||
assert_eq!(lib_path("debug", "mylib", Some("out")), "out/libmylib.a");
|
||||
assert_eq!(
|
||||
lib_path("debug", "mylib", Some("out")),
|
||||
join_dir("out", "libmylib.a")
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn shared_lib_path_default() {
|
||||
let arch = std::env::consts::ARCH;
|
||||
let expected = format!("./target/{arch}-unknown-linux-gnu/debug/libmylib.so");
|
||||
let expected = default_lib_rel("debug", "libmylib.so", Some(&host_triple()));
|
||||
assert_eq!(shared_lib_path("debug", "mylib", None), expected);
|
||||
}
|
||||
|
||||
@@ -121,7 +113,7 @@ mod tests {
|
||||
fn shared_lib_path_custom_target() {
|
||||
assert_eq!(
|
||||
shared_lib_path("release", "mylib", Some("dist")),
|
||||
"dist/libmylib.so"
|
||||
join_dir("dist", "libmylib.so")
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user