use std::path::{Path, PathBuf};
use crate::utils::copy_file;
pub async fn stage_binary_as(binary_path: &Path, dir: &Path, name: &str) -> eyre::Result<PathBuf> {
let destination = dir.join(name);
copy_file(binary_path, &destination).await?;
Ok(destination)
}
#[must_use]
pub fn dist_dir(backend_path: &Path, platform: &str, profile: Option<&str>) -> PathBuf {
let mut dir = backend_path.join("dist").join(platform);
if let Some(profile) = profile {
dir = dir.join(profile);
}
dir
}
#[cfg(test)]
mod tests {
#[test]
fn staged_binary_ships_under_the_product_name() {
smol::block_on(async {
let dir = tempfile::tempdir().expect("tempdir");
let binary = dir.path().join("demo-gtk4-deadbeef");
std::fs::write(&binary, b"bin").expect("binary");
let staged = super::stage_binary_as(&binary, dir.path(), "demo-gtk4")
.await
.expect("binary must stage");
assert_eq!(staged, dir.path().join("demo-gtk4"));
assert_eq!(
std::fs::read(&staged).expect("staged binary must read"),
b"bin"
);
assert!(binary.exists(), "the tagged Cargo artifact is kept");
});
}
}