@@ -9,11 +9,9 @@ use rustc_driver::Callbacks;
9
9
use rustc_hir:: def_id:: LocalDefId ;
10
10
use rustc_interface:: interface;
11
11
use rustc_middle:: mir:: BorrowCheckResult ;
12
- use rustc_middle:: ty :: query:: { ExternProviders , Providers } ;
12
+ use rustc_middle:: query:: { ExternProviders , Providers } ;
13
13
use rustc_middle:: ty:: TyCtxt ;
14
14
use rustc_session:: Session ;
15
- use std:: ffi:: OsStr ;
16
- use std:: path:: { Path , PathBuf } ;
17
15
18
16
struct UbrustcCallbacks ;
19
17
@@ -37,93 +35,14 @@ fn not_a_borrowchecker(cx: TyCtxt<'_>, _: LocalDefId) -> &'_ BorrowCheckResult<'
37
35
}
38
36
39
37
fn main ( ) {
40
- rustc_driver:: install_ice_hook ( ) ;
38
+ rustc_driver:: install_ice_hook ( "https://github.com/thomcc/ubrustc/issues/new" , |_| ( ) ) ;
41
39
rustc_driver:: init_rustc_env_logger ( ) ;
42
40
std:: process:: exit ( rustc_driver:: catch_with_exit_code ( move || {
43
- let orig_args: Vec < String > = std:: env:: args ( ) . collect ( ) ;
44
-
45
- let sysroot_arg = arg_value ( & orig_args, "--sysroot" ) ;
46
- let have_sysroot_arg = sysroot_arg. is_some ( ) ;
47
- let sysroot = sysroot_arg
48
- . map ( ToString :: to_string)
49
- . or_else ( || sysroot ( ) . map ( |p| p. display ( ) . to_string ( ) ) )
50
- . expect ( "Failed to find sysroot" ) ;
51
-
52
- let mut args: Vec < String > = orig_args. clone ( ) ;
53
-
54
- if !have_sysroot_arg {
55
- args. extend ( [ "--sysroot" . to_string ( ) , sysroot. to_string ( ) ] ) ;
56
- }
57
-
58
- let our_exe_filename = std:: env:: current_exe ( )
59
- . ok ( )
60
- . and_then ( |p| p. file_stem ( ) . map ( ToOwned :: to_owned) )
61
- . unwrap_or_else ( || "ubrustc" . into ( ) ) ;
62
-
63
- // This is probably wrong.
64
- let wrapper_mode = orig_args
65
- . get ( 1 )
66
- . map ( std:: path:: Path :: new)
67
- . and_then ( std:: path:: Path :: file_stem)
68
- . map_or ( false , |name| {
69
- name == our_exe_filename || name == "ubrustc" || name == "rustc"
70
- } ) ;
71
-
72
- if wrapper_mode {
73
- args. remove ( 1 ) ;
74
- }
41
+ let args: Vec < String > = std:: env:: args ( ) . collect ( ) ;
75
42
run_compiler ( args, & mut UbrustcCallbacks ) ;
76
43
} ) )
77
44
}
78
45
79
- fn arg_value < ' a , T : AsRef < str > > ( args : & ' a [ T ] , find_arg : & str ) -> Option < & ' a str > {
80
- let mut args = args. iter ( ) . map ( |s| s. as_ref ( ) ) ;
81
- while let Some ( arg) = args. next ( ) {
82
- let mut arg = arg. splitn ( 2 , '=' ) ;
83
- if arg. next ( ) != Some ( find_arg) {
84
- continue ;
85
- }
86
-
87
- if let Some ( a) = arg. next ( ) . or_else ( || args. next ( ) ) {
88
- return Some ( a) ;
89
- }
90
- }
91
- None
92
- }
93
-
94
- fn sysroot ( ) -> Option < PathBuf > {
95
- fn rustup_sysroot < H : ?Sized + AsRef < OsStr > , T : ?Sized + AsRef < Path > > (
96
- home : & H ,
97
- toolchain : & T ,
98
- ) -> PathBuf {
99
- let mut path = PathBuf :: from ( home) ;
100
- path. push ( "toolchains" ) ;
101
- path. push ( toolchain) ;
102
- path
103
- }
104
- fn runtime_rustup_sysroot ( ) -> Option < PathBuf > {
105
- let home = std:: env:: var_os ( "RUSTUP_HOME" ) ?;
106
- let toolchain = std:: env:: var_os ( "RUSTUP_TOOLCHAIN" ) ?;
107
- Some ( rustup_sysroot ( & home, & toolchain) )
108
- }
109
- fn compiletime_rustup_sysroot ( ) -> Option < PathBuf > {
110
- let home: & str = option_env ! ( "RUSTUP_HOME" ) ?;
111
- let toolchain: & str = option_env ! ( "RUSTUP_TOOLCHAIN" ) ?;
112
- Some ( rustup_sysroot ( & home, & toolchain) )
113
- }
114
- fn rustc_on_path_sysroot ( ) -> Option < PathBuf > {
115
- std:: process:: Command :: new ( "rustc" )
116
- . arg ( "--print=sysroot" )
117
- . output ( )
118
- . ok ( )
119
- . and_then ( |out| String :: from_utf8 ( out. stdout ) . ok ( ) )
120
- . map ( |s| PathBuf :: from ( s. trim ( ) ) )
121
- }
122
- runtime_rustup_sysroot ( )
123
- . or_else ( rustc_on_path_sysroot)
124
- . or_else ( compiletime_rustup_sysroot)
125
- }
126
-
127
46
fn run_compiler < CB : Callbacks + Send > ( mut args : Vec < String > , callbacks : & mut CB ) -> ! {
128
47
args. splice ( 1 ..1 , std:: iter:: once ( "--cfg=ubrustc" . to_string ( ) ) ) ;
129
48
std:: process:: exit ( rustc_driver:: catch_with_exit_code ( move || {
0 commit comments