Update rustup_wrapper

[skip ci]
This commit is contained in:
topjohnwu
2025-03-06 16:12:35 -08:00
parent c6c1a17ae6
commit 28d86a3454
5 changed files with 44 additions and 43 deletions
+14 -13
View File
@@ -1,4 +1,5 @@
use std::env;
use std::path::Path;
use std::process::{Command, Stdio};
use home::cargo_home;
@@ -10,34 +11,34 @@ use home::cargo_home;
* The command `rustup component list` does not work with custom toolchains:
* > error: toolchain 'magisk' does not support components
*
* However, this command is used by several IDEs to determine available
* components that can be used, such as clippy, rustfmt etc.
* In this script, we simply redirect the output when using the nightly
* However, this command is used by several IDEs to determine component
* availability, such as clippy, rustfmt etc.
* In this program, we use the output of the command with the nightly
* channel if any `component` command failed.
*/
fn main() -> std::io::Result<()> {
let rustup = cargo_home()?.join("bin").join("rustup");
let exe = env::args().next().unwrap();
let exe = Path::new(&exe).file_name().unwrap().to_str().unwrap();
let real_exe = cargo_home()?.join("bin").join(exe);
let argv: Vec<String> = env::args().skip(1).collect();
if argv.iter().any(|s| s == "component") {
let status = Command::new(&rustup)
if exe.starts_with("rustup") && argv.iter().any(|s| s == "component") {
let status = Command::new(&real_exe)
.args(&argv)
.stdout(Stdio::null())
.stderr(Stdio::null())
.status()?;
if !status.success() {
let mut cmd = Command::new(&rustup);
let mut cmd = Command::new(&real_exe);
// Hardcode to use the nightly channel
cmd.arg("+nightly");
if argv[0].starts_with('+') {
cmd.args(argv.iter().skip(1));
} else {
cmd.args(&argv);
}
// Remove any explicit channel specification
cmd.args(argv.iter().filter(|s| !s.starts_with('+')));
return cmd.status().map(|_| ());
}
}
// Simply pass through
Command::new(&rustup).args(argv.iter()).status().map(|_| ())
Command::new(&real_exe).args(argv.iter()).status().map(|_| ())
}