Skip to content

Commit

Permalink
compiler: avoid a call to env::current_dir
Browse files Browse the repository at this point in the history
Both of these paths end up canonicalized.
  • Loading branch information
tamird committed Oct 6, 2023
1 parent d59add5 commit 28da466
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions compiler/rustc_codegen_ssa/src/back/rpath.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use pathdiff::diff_paths;
use rustc_data_structures::fx::FxHashSet;
use std::env;
use std::ffi::OsString;
use std::fs;
use std::path::{Path, PathBuf};

pub struct RPathConfig<'a> {
Expand Down Expand Up @@ -82,12 +80,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 = lib.canonicalize().unwrap();
let output = output.canonicalize().unwrap();
let relative = path_relative_from(&lib, &output)
.unwrap_or_else(|| panic!("couldn't create relative path from {output:?} to {lib:?}"));

Expand Down

0 comments on commit 28da466

Please sign in to comment.