Skip to content

Commit 0a41d81

Browse files
committed
compiler: avoid a call to env::current_dir
Both of these paths end up canonicalized.
1 parent 3a8af24 commit 0a41d81

File tree

1 file changed

+5
-8
lines changed
  • compiler/rustc_codegen_ssa/src/back

1 file changed

+5
-8
lines changed

compiler/rustc_codegen_ssa/src/back/rpath.rs

+5-8
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
use pathdiff::diff_paths;
22
use rustc_data_structures::fx::FxHashSet;
3-
use std::env;
43
use std::ffi::OsString;
5-
use std::fs;
64
use std::path::{Path, PathBuf};
75

86
pub struct RPathConfig<'a> {
@@ -82,12 +80,11 @@ fn get_rpath_relative_to_output(config: &mut RPathConfig<'_>, lib: &Path) -> OsS
8280
// Mac doesn't appear to support $ORIGIN
8381
let prefix = if config.is_like_osx { "@loader_path" } else { "$ORIGIN" };
8482

85-
let cwd = env::current_dir().unwrap();
86-
let mut lib = fs::canonicalize(&cwd.join(lib)).unwrap_or_else(|_| cwd.join(lib));
87-
lib.pop(); // strip filename
88-
let mut output = cwd.join(&config.out_filename);
89-
output.pop(); // strip filename
90-
let output = fs::canonicalize(&output).unwrap_or(output);
83+
// Strip filenames
84+
let lib = lib.parent().unwrap();
85+
let output = config.out_filename.parent().unwrap();
86+
let lib = lib.canonicalize().unwrap();
87+
let output = output.canonicalize().unwrap();
9188
let relative = path_relative_from(&lib, &output)
9289
.unwrap_or_else(|| panic!("couldn't create relative path from {output:?} to {lib:?}"));
9390

0 commit comments

Comments
 (0)