perf(rust): additionally check `rustup default` for faster result. (#3354)
* perf(rust): additionally check `rustup default` for faster result. After checking directory overrides we were directly falling back to the relatively slow call to `rustc --version`. Inserting a call to `rustup default` leads to a quicker response. * use `context.exec_cmd` instead of `create_command`
This commit is contained in:
parent
eaa3cc1875
commit
c63e9a71bd
|
@ -65,6 +65,7 @@ fn get_module_version(context: &Context, config: &RustConfig) -> Option<String>
|
||||||
// 1. `$RUSTUP_TOOLCHAIN`
|
// 1. `$RUSTUP_TOOLCHAIN`
|
||||||
// 2. `rustup override list`
|
// 2. `rustup override list`
|
||||||
// 3. `rust-toolchain` or `rust-toolchain.toml` in `.` or parent directories
|
// 3. `rust-toolchain` or `rust-toolchain.toml` in `.` or parent directories
|
||||||
|
// 4. `rustup default`
|
||||||
// as `rustup` does.
|
// as `rustup` does.
|
||||||
// https://github.com/rust-lang/rustup.rs/tree/eb694fcada7becc5d9d160bf7c623abe84f8971d#override-precedence
|
// https://github.com/rust-lang/rustup.rs/tree/eb694fcada7becc5d9d160bf7c623abe84f8971d#override-precedence
|
||||||
//
|
//
|
||||||
|
@ -74,8 +75,9 @@ fn get_module_version(context: &Context, config: &RustConfig) -> Option<String>
|
||||||
// - `rustup show active-toolchain`
|
// - `rustup show active-toolchain`
|
||||||
// - `rustup which`
|
// - `rustup which`
|
||||||
if let Some(toolchain) = env_rustup_toolchain(context)
|
if let Some(toolchain) = env_rustup_toolchain(context)
|
||||||
.or_else(|| execute_rustup_override_list(&context.current_dir))
|
.or_else(|| execute_rustup_override_list(context))
|
||||||
.or_else(|| find_rust_toolchain_file(context))
|
.or_else(|| find_rust_toolchain_file(context))
|
||||||
|
.or_else(|| execute_rustup_default(context))
|
||||||
{
|
{
|
||||||
match execute_rustup_run_rustc_version(&toolchain) {
|
match execute_rustup_run_rustc_version(&toolchain) {
|
||||||
RustupRunRustcVersionOutcome::RustcVersion(rustc_version) => {
|
RustupRunRustcVersionOutcome::RustcVersion(rustc_version) => {
|
||||||
|
@ -99,14 +101,22 @@ fn env_rustup_toolchain(context: &Context) -> Option<String> {
|
||||||
Some(val.trim().to_owned())
|
Some(val.trim().to_owned())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn execute_rustup_override_list(cwd: &Path) -> Option<String> {
|
fn execute_rustup_override_list(context: &Context) -> Option<String> {
|
||||||
let Output { stdout, .. } = create_command("rustup")
|
extract_toolchain_from_rustup_override_list(
|
||||||
.ok()?
|
&context.exec_cmd("rustup", &["override", "list"])?.stdout,
|
||||||
.args(&["override", "list"])
|
&context.current_dir,
|
||||||
.output()
|
)
|
||||||
.ok()?;
|
}
|
||||||
let stdout = String::from_utf8(stdout).ok()?;
|
|
||||||
extract_toolchain_from_rustup_override_list(&stdout, cwd)
|
fn execute_rustup_default(context: &Context) -> Option<String> {
|
||||||
|
// `rustup default` output is:
|
||||||
|
// stable-x86_64-apple-darwin (default)
|
||||||
|
context
|
||||||
|
.exec_cmd("rustup", &["default"])?
|
||||||
|
.stdout
|
||||||
|
.split_whitespace()
|
||||||
|
.next()
|
||||||
|
.map(str::to_owned)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn extract_toolchain_from_rustup_override_list(stdout: &str, cwd: &Path) -> Option<String> {
|
fn extract_toolchain_from_rustup_override_list(stdout: &str, cwd: &Path) -> Option<String> {
|
||||||
|
|
Loading…
Reference in New Issue