Skip to content

Commit 655819d

Browse files
DRAFT: Use tools from same directory as cargo in preference to PATH
1 parent 8494149 commit 655819d

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/cargo/util/config/mod.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1492,11 +1492,19 @@ impl Config {
14921492
}
14931493
}
14941494

1495+
fn default_tool_path(&self, tool: &str) -> PathBuf {
1496+
std::env::current_exe()
1497+
.ok()
1498+
.and_then(|exe| exe.parent().map(|exe_dir| exe_dir.join(tool)))
1499+
.filter(|tool_path| tool_path.exists())
1500+
.unwrap_or_else(|| PathBuf::from(tool))
1501+
}
1502+
14951503
/// Looks for a path for `tool` in an environment variable or config path, defaulting to `tool`
14961504
/// as a path.
14971505
fn get_tool(&self, tool: &str, from_config: &Option<ConfigRelativePath>) -> PathBuf {
14981506
self.maybe_get_tool(tool, from_config)
1499-
.unwrap_or_else(|| PathBuf::from(tool))
1507+
.unwrap_or_else(|| self.default_tool_path(tool))
15001508
}
15011509

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

0 commit comments

Comments
 (0)