1
- //! Run `x.py` from any subdirectory of a rust compiler checkout.
1
+ //! Run bootstrap from any subdirectory of a rust compiler checkout.
2
2
//!
3
3
//! We prefer `exec`, to avoid adding an extra process in the process tree.
4
4
//! However, since `exec` isn't available on Windows, we indirect through
5
5
//! `exec_or_status`, which will call `exec` on unix and `status` on Windows.
6
6
//!
7
- //! We use `python`, `python3`, or `python2` as the python interpreter to run
8
- //! `x.py`, in that order of preference.
7
+ //! We use `powershell.exe x.ps1` on Windows, and `sh -c x` on Unix, those are
8
+ //! the ones that call `x.py`. We use `sh -c` on Unix, because it is a standard.
9
+ //! We also don't use `pwsh` on Windows, because it is not installed by default;
9
10
10
11
use std:: {
11
- env:: { self , consts :: EXE_EXTENSION } ,
12
- io ,
12
+ env, io ,
13
+ path :: Path ,
13
14
process:: { self , Command , ExitStatus } ,
14
15
} ;
15
16
16
- const PYTHON : & str = "python" ;
17
- const PYTHON2 : & str = "python2" ;
18
- const PYTHON3 : & str = "python3" ;
19
-
20
- fn python ( ) -> & ' static str {
21
- let val = match env:: var_os ( "PATH" ) {
22
- Some ( val) => val,
23
- None => return PYTHON ,
24
- } ;
25
-
26
- let mut python2 = false ;
27
- let mut python3 = false ;
28
-
29
- for dir in env:: split_paths ( & val) {
30
- // `python` should always take precedence over python2 / python3 if it exists
31
- if dir. join ( PYTHON ) . with_extension ( EXE_EXTENSION ) . exists ( ) {
32
- return PYTHON ;
33
- }
17
+ #[ cfg( windows) ]
18
+ fn x_command ( dir : & Path ) -> Command {
19
+ let mut cmd = Command :: new ( "powershell.exe" ) ;
20
+ cmd. args ( [
21
+ "-NoLogo" ,
22
+ "-NoProfile" ,
23
+ "-NonInteractive" ,
24
+ "-ExecutionPolicy" ,
25
+ "RemoteSigned" ,
26
+ "-Command" ,
27
+ "./x.ps1" ,
28
+ ] )
29
+ . current_dir ( dir) ;
30
+ cmd
31
+ }
34
32
35
- python2 |= dir. join ( PYTHON2 ) . with_extension ( EXE_EXTENSION ) . exists ( ) ;
36
- python3 |= dir. join ( PYTHON3 ) . with_extension ( EXE_EXTENSION ) . exists ( ) ;
37
- }
33
+ #[ cfg( unix) ]
34
+ fn x_command ( dir : & Path ) -> Command {
35
+ Command :: new ( dir. join ( "x" ) )
36
+ }
38
37
39
- // try 3 before 2
40
- if python3 {
41
- PYTHON3
42
- } else if python2 {
43
- PYTHON2
44
- } else {
45
- // Python was not found on path, so exit
46
- eprintln ! ( "Unable to find python in your PATH. Please check it is installed." ) ;
47
- process:: exit ( 1 ) ;
48
- }
38
+ #[ cfg( not( any( windows, unix) ) ) ]
39
+ fn x_command ( _dir : & Path ) -> Command {
40
+ compile_error ! ( "Unsupported platform" ) ;
49
41
}
50
42
51
43
#[ cfg( unix) ]
@@ -72,15 +64,15 @@ fn main() {
72
64
let candidate = dir. join ( "x.py" ) ;
73
65
74
66
if candidate. exists ( ) {
75
- let mut python = Command :: new ( python ( ) ) ;
67
+ let mut cmd = x_command ( dir ) ;
76
68
77
- python . arg ( & candidate ) . args ( env:: args ( ) . skip ( 1 ) ) . current_dir ( dir) ;
69
+ cmd . args ( env:: args ( ) . skip ( 1 ) ) . current_dir ( dir) ;
78
70
79
- let result = exec_or_status ( & mut python ) ;
71
+ let result = exec_or_status ( & mut cmd ) ;
80
72
81
73
match result {
82
74
Err ( error) => {
83
- eprintln ! ( "Failed to invoke `{}`: {}" , candidate . display ( ) , error) ;
75
+ eprintln ! ( "Failed to invoke `{:? }`: {}" , cmd , error) ;
84
76
}
85
77
Ok ( status) => {
86
78
process:: exit ( status. code ( ) . unwrap_or ( 1 ) ) ;
0 commit comments