11use std:: env;
2+ use std:: path:: Path ;
23use std:: process:: { Command , Stdio } ;
34
45use home:: cargo_home;
@@ -10,34 +11,34 @@ use home::cargo_home;
1011 * The command `rustup component list` does not work with custom toolchains:
1112 * > error: toolchain 'magisk' does not support components
1213 *
13- * However, this command is used by several IDEs to determine available
14- * components that can be used , such as clippy, rustfmt etc.
15- * In this script , we simply redirect the output when using the nightly
14+ * However, this command is used by several IDEs to determine component
15+ * availability , such as clippy, rustfmt etc.
16+ * In this program , we use the output of the command with the nightly
1617 * channel if any `component` command failed.
1718*/
1819
1920fn main ( ) -> std:: io:: Result < ( ) > {
20- let rustup = cargo_home ( ) ?. join ( "bin" ) . join ( "rustup" ) ;
21+ let exe = env:: args ( ) . next ( ) . unwrap ( ) ;
22+ let exe = Path :: new ( & exe) . file_name ( ) . unwrap ( ) . to_str ( ) . unwrap ( ) ;
23+ let real_exe = cargo_home ( ) ?. join ( "bin" ) . join ( exe) ;
2124 let argv: Vec < String > = env:: args ( ) . skip ( 1 ) . collect ( ) ;
2225
23- if argv. iter ( ) . any ( |s| s == "component" ) {
24- let status = Command :: new ( & rustup )
26+ if exe . starts_with ( "rustup" ) && argv. iter ( ) . any ( |s| s == "component" ) {
27+ let status = Command :: new ( & real_exe )
2528 . args ( & argv)
2629 . stdout ( Stdio :: null ( ) )
2730 . stderr ( Stdio :: null ( ) )
2831 . status ( ) ?;
2932 if !status. success ( ) {
30- let mut cmd = Command :: new ( & rustup) ;
33+ let mut cmd = Command :: new ( & real_exe) ;
34+ // Hardcode to use the nightly channel
3135 cmd. arg ( "+nightly" ) ;
32- if argv[ 0 ] . starts_with ( '+' ) {
33- cmd. args ( argv. iter ( ) . skip ( 1 ) ) ;
34- } else {
35- cmd. args ( & argv) ;
36- }
36+ // Remove any explicit channel specification
37+ cmd. args ( argv. iter ( ) . filter ( |s| !s. starts_with ( '+' ) ) ) ;
3738 return cmd. status ( ) . map ( |_| ( ) ) ;
3839 }
3940 }
4041
4142 // Simply pass through
42- Command :: new ( & rustup ) . args ( argv. iter ( ) ) . status ( ) . map ( |_| ( ) )
43+ Command :: new ( & real_exe ) . args ( argv. iter ( ) ) . status ( ) . map ( |_| ( ) )
4344}
0 commit comments