about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2024-02-26 10:45:11 +0000
committerbors <bors@rust-lang.org>2024-02-26 10:45:11 +0000
commit6903a5c7d67836e489f2330fda4a1c6153665780 (patch)
treed323de438562c03f76cc2c21632773e25d76e3ae
parent4585b461e5359674eaa5b7e0a92b709c919d7e56 (diff)
parent9f1d4aa4b9e4a1572c1210b3bd7c7490778b6112 (diff)
downloadrust-6903a5c7d67836e489f2330fda4a1c6153665780.tar.gz
rust-6903a5c7d67836e489f2330fda4a1c6153665780.zip
Auto merge of #16665 - MabezDev:prio-rustup-when-searching, r=Veykril
Prioritise rustup sysroots over system ones

`get_path_for_executable` will now first check `$CARGO_HOME` before falling back to searching `$PATH`.

`rustup` is the recommended way to manage rust toolchains, therefore should be picked before the system toolchain.

Closes #16661
-rw-r--r--crates/toolchain/src/lib.rs14
1 files changed, 7 insertions, 7 deletions
diff --git a/crates/toolchain/src/lib.rs b/crates/toolchain/src/lib.rs
index ae71b6700c0..793138588a3 100644
--- a/crates/toolchain/src/lib.rs
+++ b/crates/toolchain/src/lib.rs
@@ -63,21 +63,17 @@ fn get_path_for_executable(executable_name: &'static str) -> PathBuf {
     // The current implementation checks three places for an executable to use:
     // 1) Appropriate environment variable (erroring if this is set but not a usable executable)
     //      example: for cargo, this checks $CARGO environment variable; for rustc, $RUSTC; etc
-    // 2) `<executable_name>`
-    //      example: for cargo, this tries just `cargo`, which will succeed if `cargo` is on the $PATH
-    // 3) `$CARGO_HOME/bin/<executable_name>`
+    // 2) `$CARGO_HOME/bin/<executable_name>`
     //      where $CARGO_HOME defaults to ~/.cargo (see https://doc.rust-lang.org/cargo/guide/cargo-home.html)
     //      example: for cargo, this tries $CARGO_HOME/bin/cargo, or ~/.cargo/bin/cargo if $CARGO_HOME is unset.
     //      It seems that this is a reasonable place to try for cargo, rustc, and rustup
+    // 3) `<executable_name>`
+    //      example: for cargo, this tries just `cargo`, which will succeed if `cargo` is on the $PATH
     let env_var = executable_name.to_ascii_uppercase();
     if let Some(path) = env::var_os(env_var) {
         return path.into();
     }
 
-    if lookup_in_path(executable_name) {
-        return executable_name.into();
-    }
-
     if let Some(mut path) = get_cargo_home() {
         path.push("bin");
         path.push(executable_name);
@@ -86,6 +82,10 @@ fn get_path_for_executable(executable_name: &'static str) -> PathBuf {
         }
     }
 
+    if lookup_in_path(executable_name) {
+        return executable_name.into();
+    }
+
     executable_name.into()
 }