From 3463ba7cf6e6c54b26b63107dd8abc7829f8ec21 Mon Sep 17 00:00:00 2001 From: Wolf Vollprecht Date: Tue, 5 Nov 2024 16:39:24 +0100 Subject: [PATCH] chore: add a test for the relinking fixes (#1160) --- src/macos/link.rs | 55 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-) diff --git a/src/macos/link.rs b/src/macos/link.rs index 88b7dba8a..68db59453 100644 --- a/src/macos/link.rs +++ b/src/macos/link.rs @@ -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"); @@ -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()]); @@ -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