Skip to content

Commit

Permalink
DRAFT: Use tools from same directory as cargo in preference to PATH
Browse files Browse the repository at this point in the history
  • Loading branch information
davidlattimore committed Aug 14, 2022
1 parent 8494149 commit 655819d
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/cargo/util/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1492,11 +1492,19 @@ impl Config {
}
}

fn default_tool_path(&self, tool: &str) -> PathBuf {
std::env::current_exe()
.ok()
.and_then(|exe| exe.parent().map(|exe_dir| exe_dir.join(tool)))
.filter(|tool_path| tool_path.exists())
.unwrap_or_else(|| PathBuf::from(tool))
}

/// Looks for a path for `tool` in an environment variable or config path, defaulting to `tool`
/// as a path.
fn get_tool(&self, tool: &str, from_config: &Option<ConfigRelativePath>) -> PathBuf {
self.maybe_get_tool(tool, from_config)
.unwrap_or_else(|| PathBuf::from(tool))
.unwrap_or_else(|| self.default_tool_path(tool))
}

pub fn jobserver_from_env(&self) -> Option<&jobserver::Client> {
Expand Down

0 comments on commit 655819d

Please sign in to comment.