Skip to content

Commit

Permalink
chore: add a test for the relinking fixes (#1160)
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfv authored Nov 5, 2024
1 parent a53129b commit 3463ba7
Showing 1 changed file with 54 additions and 1 deletion.
55 changes: 54 additions & 1 deletion src/macos/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,8 @@ mod tests {
};
use crate::{post_process::relink::Relinker, recipe::parser::GlobVec};

const EXPECTED_PATH: &str = "/Users/wolfv/Programs/rattler-build/output/bld/rattler-build_zlink_1705569778/host_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehol/lib";

#[test]
fn test_relink_builtin() -> Result<(), RelinkError> {
let prefix = Path::new(env!("CARGO_MANIFEST_DIR")).join("test-data/binary_files");
Expand All @@ -558,7 +560,7 @@ mod tests {

let object = Dylib::new(&binary_path).unwrap();
assert!(Dylib::test_file(&binary_path)?);
let expected_rpath = PathBuf::from("/Users/wolfv/Programs/rattler-build/output/bld/rattler-build_zlink_1705569778/host_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehol/lib");
let expected_rpath = PathBuf::from(EXPECTED_PATH);

assert_eq!(object.rpaths, vec![expected_rpath.clone()]);

Expand All @@ -579,6 +581,57 @@ mod tests {
Ok(())
}

#[test]
fn test_relink_install_name_tool() -> Result<(), RelinkError> {
let prefix = Path::new(env!("CARGO_MANIFEST_DIR")).join("test-data/binary_files");
let tmp_dir = tempdir_in(&prefix)?;
let binary_path = tmp_dir.path().join("zlink");
fs::copy(prefix.join("zlink-macos"), &binary_path)?;

let object = Dylib::new(&binary_path).unwrap();
assert!(Dylib::test_file(&binary_path)?);
let expected_rpath = PathBuf::from(EXPECTED_PATH);
// first change the rpath to just @loader_path
let changes = DylibChanges {
change_rpath: vec![(
Some(expected_rpath.clone()),
Some(PathBuf::from("@loader_path/")),
)],
change_id: None,
change_dylib: HashMap::default(),
};

super::relink(&binary_path, &changes)?;

assert_eq!(object.rpaths, vec![expected_rpath.clone()]);

let changes = DylibChanges {
change_rpath: vec![
(
Some("@loader_path/".into()),
Some("@loader_path/../../../".into()),
),
(None, Some("@loader_path/".into())),
],
change_id: None,
change_dylib: HashMap::default(),
};

let system_tools = SystemTools::default();
super::install_name_tool(&binary_path, &changes, &system_tools)?;

let rpaths = Dylib::new(&binary_path)?.rpaths;
assert_eq!(
rpaths,
vec![
PathBuf::from("@loader_path/"),
PathBuf::from("@loader_path/../../../")
]
);

Ok(())
}

#[test]
fn test_relink_add_path() -> Result<(), RelinkError> {
// check if install_name_tool is installed
Expand Down

0 comments on commit 3463ba7

Please sign in to comment.