diff options
| author | Tamir Duberstein <tamird@gmail.com> | 2023-10-06 08:32:00 -0400 |
|---|---|---|
| committer | Tamir Duberstein <tamird@gmail.com> | 2023-10-06 09:54:11 -0400 |
| commit | 5aeb6a326f2fa941061b60c9286665847fe0401e (patch) | |
| tree | a717c37c08210300cc7f2c7c96ace55ca69159c1 /compiler/rustc_codegen_ssa | |
| parent | a081007265044a7baa0f23c286b6380be35c8bb0 (diff) | |
| download | rust-5aeb6a326f2fa941061b60c9286665847fe0401e.tar.gz rust-5aeb6a326f2fa941061b60c9286665847fe0401e.zip | |
rustc_codegen_ssa: use try_canonicalize in rpath
This is simpler and avoids unnecessary calls to `env::current_dir`.
Diffstat (limited to 'compiler/rustc_codegen_ssa')
| -rw-r--r-- | compiler/rustc_codegen_ssa/src/back/rpath.rs | 14 |
1 files changed, 6 insertions, 8 deletions
diff --git a/compiler/rustc_codegen_ssa/src/back/rpath.rs b/compiler/rustc_codegen_ssa/src/back/rpath.rs index ebf04e7a399..60346228625 100644 --- a/compiler/rustc_codegen_ssa/src/back/rpath.rs +++ b/compiler/rustc_codegen_ssa/src/back/rpath.rs @@ -1,8 +1,7 @@ use pathdiff::diff_paths; use rustc_data_structures::fx::FxHashSet; -use std::env; +use rustc_fs_util::try_canonicalize; use std::ffi::OsString; -use std::fs; use std::path::{Path, PathBuf}; pub struct RPathConfig<'a> { @@ -82,12 +81,11 @@ fn get_rpath_relative_to_output(config: &mut RPathConfig<'_>, lib: &Path) -> OsS // Mac doesn't appear to support $ORIGIN let prefix = if config.is_like_osx { "@loader_path" } else { "$ORIGIN" }; - let cwd = env::current_dir().unwrap(); - let mut lib = fs::canonicalize(&cwd.join(lib)).unwrap_or_else(|_| cwd.join(lib)); - lib.pop(); // strip filename - let mut output = cwd.join(&config.out_filename); - output.pop(); // strip filename - let output = fs::canonicalize(&output).unwrap_or(output); + // Strip filenames + let lib = lib.parent().unwrap(); + let output = config.out_filename.parent().unwrap(); + let lib = try_canonicalize(lib).unwrap(); + let output = try_canonicalize(output).unwrap(); let relative = path_relative_from(&lib, &output) .unwrap_or_else(|| panic!("couldn't create relative path from {output:?} to {lib:?}")); |
