2
2
3
3
use std:: env;
4
4
use std:: ffi:: OsStr ;
5
- use std:: fmt:: Write ;
6
5
use std:: path:: PathBuf ;
7
6
use std:: process:: { self , Command } ;
8
7
@@ -24,6 +23,7 @@ pub fn setup(
24
23
let only_setup = matches ! ( subcommand, MiriCommand :: Setup ) ;
25
24
let ask_user = !only_setup;
26
25
let print_sysroot = only_setup && has_arg_flag ( "--print-sysroot" ) ; // whether we just print the sysroot path
26
+ let show_setup = only_setup && !print_sysroot;
27
27
if !only_setup {
28
28
if let Some ( sysroot) = std:: env:: var_os ( "MIRI_SYSROOT" ) {
29
29
// Skip setup step if MIRI_SYSROOT is explicitly set, *unless* we are `cargo miri setup`.
@@ -115,18 +115,16 @@ pub fn setup(
115
115
// `config.toml`.
116
116
command. env ( "RUSTC_WRAPPER" , "" ) ;
117
117
118
- if only_setup && !print_sysroot {
118
+ if show_setup {
119
119
// Forward output. Even make it verbose, if requested.
120
+ command. stdout ( process:: Stdio :: inherit ( ) ) ;
121
+ command. stderr ( process:: Stdio :: inherit ( ) ) ;
120
122
for _ in 0 ..verbose {
121
123
command. arg ( "-v" ) ;
122
124
}
123
125
if quiet {
124
126
command. arg ( "--quiet" ) ;
125
127
}
126
- } else {
127
- // Suppress output.
128
- command. stdout ( process:: Stdio :: null ( ) ) ;
129
- command. stderr ( process:: Stdio :: null ( ) ) ;
130
128
}
131
129
132
130
command
@@ -137,22 +135,25 @@ pub fn setup(
137
135
// not apply `RUSTFLAGS` to the sysroot either.
138
136
let rustflags = & [ "-Cdebug-assertions=off" , "-Coverflow-checks=on" ] ;
139
137
138
+ let mut after_build_output = String :: new ( ) ; // what should be printed when the build is done.
140
139
let notify = || {
141
- let mut msg = String :: new ( ) ;
142
- write ! ( msg, "Preparing a sysroot for Miri (target: {target})" ) . unwrap ( ) ;
143
- if verbose > 0 {
144
- write ! ( msg, " in {}" , sysroot_dir. display( ) ) . unwrap ( ) ;
145
- }
146
- write ! ( msg, "..." ) . unwrap ( ) ;
147
-
148
- if print_sysroot || quiet {
149
- // Be silent.
150
- } else if only_setup {
151
- // We want to be explicit.
152
- eprintln ! ( "{msg}" ) ;
153
- } else {
154
- // We want to be quiet, but still let the user know that something is happening.
155
- eprint ! ( "{msg} " ) ;
140
+ if !quiet {
141
+ eprint ! ( "Preparing a sysroot for Miri (target: {target})" ) ;
142
+ if verbose > 0 {
143
+ eprint ! ( " in {}" , sysroot_dir. display( ) ) ;
144
+ }
145
+ if show_setup {
146
+ // Cargo will print things, so we need to finish this line.
147
+ eprintln ! ( "..." ) ;
148
+ after_build_output = format ! (
149
+ "A sysroot for Miri is now available in `{}`.\n " ,
150
+ sysroot_dir. display( )
151
+ ) ;
152
+ } else {
153
+ // Keep all output on a single line.
154
+ eprint ! ( "... " ) ;
155
+ after_build_output = format ! ( "done\n " ) ;
156
+ }
156
157
}
157
158
} ;
158
159
@@ -167,31 +168,17 @@ pub fn setup(
167
168
. build_from_source ( & rust_src) ;
168
169
match status {
169
170
Ok ( SysrootStatus :: AlreadyCached ) =>
170
- if only_setup && ! ( print_sysroot || quiet ) {
171
+ if !quiet && show_setup {
171
172
eprintln ! (
172
173
"A sysroot for Miri is already available in `{}`." ,
173
174
sysroot_dir. display( )
174
175
) ;
175
176
} ,
176
177
Ok ( SysrootStatus :: SysrootBuilt ) => {
177
- if print_sysroot || quiet {
178
- // Be silent.
179
- } else if only_setup {
180
- eprintln ! ( "A sysroot for Miri is now available in `{}`." , sysroot_dir. display( ) ) ;
181
- } else {
182
- eprintln ! ( "done" ) ;
183
- }
178
+ // Print what `notify` prepared.
179
+ eprint ! ( "{after_build_output}" ) ;
184
180
}
185
- Err ( err) =>
186
- if print_sysroot {
187
- show_error ! ( "failed to build sysroot" )
188
- } else if only_setup {
189
- show_error ! ( "failed to build sysroot: {err:?}" )
190
- } else {
191
- show_error ! (
192
- "failed to build sysroot; run `cargo miri setup` to see the error details"
193
- )
194
- } ,
181
+ Err ( err) => show_error ! ( "failed to build sysroot: {err:?}" ) ,
195
182
}
196
183
197
184
if print_sysroot {
0 commit comments