Skip to content

Commit 91dd8df

Browse files
Stop printing rustc command line if non-verbose
We used to print a wall of text especially in larger projects like the compiler, now we print a much smaller message. It's not generally useful to know the full compiler command anyway.
1 parent af6e295 commit 91dd8df

File tree

5 files changed

+38
-23
lines changed

5 files changed

+38
-23
lines changed

src/cargo/util/config.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@ impl Config {
207207
} else {
208208
None
209209
},
210+
self.extra_verbose(),
210211
)
211212
}
212213

src/cargo/util/process_builder.rs

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ use std::env;
33
use std::ffi::{OsStr, OsString};
44
use std::fmt;
55
use std::path::Path;
6-
use std::process::{Command, Output, Stdio};
6+
use std::process::{Command, Output, Stdio, ExitStatus};
77

88
use jobserver::Client;
99
use shell_escape::escape;
1010

11-
use util::{process_error, CargoResult, CargoResultExt, read2};
11+
use util::{process_error, ProcessError, CargoResult, CargoResultExt, read2};
1212

1313
/// A builder object for an external process, similar to `std::process::Command`.
1414
#[derive(Clone, Debug)]
@@ -26,6 +26,10 @@ pub struct ProcessBuilder {
2626
///
2727
/// [jobserver_docs]: https://docs.rs/jobserver/0.1.6/jobserver/
2828
jobserver: Option<Client>,
29+
/// Should we give as much information as possible?
30+
///
31+
/// Currently this controls whether to print out the command line on failure.
32+
verbose_output: bool,
2933
}
3034

3135
impl fmt::Display for ProcessBuilder {
@@ -88,6 +92,11 @@ impl ProcessBuilder {
8892
self
8993
}
9094

95+
pub fn verbose(&mut self, verbose: bool) -> &mut ProcessBuilder {
96+
self.verbose_output = verbose;
97+
self
98+
}
99+
91100
/// Get the executable name.
92101
pub fn get_program(&self) -> &OsString {
93102
&self.program
@@ -128,6 +137,19 @@ impl ProcessBuilder {
128137
self
129138
}
130139

140+
fn unsuccessful(&self, exit: &ExitStatus, output: Option<&Output>) -> ProcessError {
141+
let msg = if self.verbose_output {
142+
format!("proces didn't exit successfully: {:?}", self.program)
143+
} else {
144+
format!("process didn't exit successfully: {}", self)
145+
};
146+
process_error(
147+
&msg,
148+
Some(exit),
149+
output,
150+
)
151+
}
152+
131153
/// Run the process, waiting for completion, and mapping non-success exit codes to an error.
132154
pub fn exec(&self) -> CargoResult<()> {
133155
let mut command = self.build_command();
@@ -142,11 +164,7 @@ impl ProcessBuilder {
142164
if exit.success() {
143165
Ok(())
144166
} else {
145-
Err(process_error(
146-
&format!("process didn't exit successfully: {}", self),
147-
Some(&exit),
148-
None,
149-
).into())
167+
Err(self.unsuccessful(&exit, None).into())
150168
}
151169
}
152170

@@ -191,11 +209,7 @@ impl ProcessBuilder {
191209
if output.status.success() {
192210
Ok(output)
193211
} else {
194-
Err(process_error(
195-
&format!("process didn't exit successfully: {}", self),
196-
Some(&output.status),
197-
Some(&output),
198-
).into())
212+
Err(self.unsuccessful(&output.status, Some(&output)).into())
199213
}
200214
}
201215

@@ -269,11 +283,7 @@ impl ProcessBuilder {
269283
{
270284
let to_print = if print_output { Some(&output) } else { None };
271285
if !output.status.success() {
272-
return Err(process_error(
273-
&format!("process didn't exit successfully: {}", self),
274-
Some(&output.status),
275-
to_print,
276-
).into());
286+
return Err(self.unsuccessful(&output.status, to_print).into());
277287
} else if let Some(e) = callback_error {
278288
let cx = process_error(
279289
&format!("failed to parse process output: {}", self),
@@ -322,5 +332,6 @@ pub fn process<T: AsRef<OsStr>>(cmd: T) -> ProcessBuilder {
322332
cwd: None,
323333
env: HashMap::new(),
324334
jobserver: None,
335+
verbose_output: false,
325336
}
326337
}

src/cargo/util/rustc.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ pub struct Rustc {
2323
pub verbose_version: String,
2424
/// The host triple (arch-platform-OS), this comes from verbose_version.
2525
pub host: String,
26+
/// Should termination print out command line.
27+
pub verbose: bool,
2628
cache: Mutex<Cache>,
2729
}
2830

@@ -37,6 +39,7 @@ impl Rustc {
3739
wrapper: Option<PathBuf>,
3840
rustup_rustc: &Path,
3941
cache_location: Option<PathBuf>,
42+
verbose: bool,
4043
) -> CargoResult<Rustc> {
4144
let _p = profile::start("Rustc::new");
4245

@@ -60,21 +63,24 @@ impl Rustc {
6063
wrapper,
6164
verbose_version,
6265
host,
66+
verbose,
6367
cache: Mutex::new(cache),
6468
})
6569
}
6670

6771
/// Get a process builder set up to use the found rustc version, with a wrapper if Some
6872
pub fn process(&self) -> ProcessBuilder {
69-
if let Some(ref wrapper) = self.wrapper {
73+
let mut process = if let Some(ref wrapper) = self.wrapper {
7074
let mut cmd = util::process(wrapper);
7175
{
7276
cmd.arg(&self.path);
7377
}
7478
cmd
7579
} else {
7680
util::process(&self.path)
77-
}
81+
};
82+
process.verbose(self.verbose);
83+
process
7884
}
7985

8086
pub fn cached_output(&self, cmd: &ProcessBuilder) -> CargoResult<(String, String)> {

tests/testsuite/shell_quoting.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,6 @@ fn features_are_quoted() {
3434
.with_status(101)
3535
.with_stderr_contains(
3636
r#"[RUNNING] `rustc [..] --cfg 'feature="default"' --cfg 'feature="some_feature"' [..]`"#
37-
).with_stderr_contains(
38-
r#"
39-
Caused by:
40-
process didn't exit successfully: [..] --cfg 'feature="default"' --cfg 'feature="some_feature"' [..]"#
4137
)
4238
);
4339
}

tests/testsuite/support/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1307,6 +1307,7 @@ pub static RUSTC: Rustc = Rustc::new(
13071307
None,
13081308
Path::new("should be path to rustup rustc, but we don't care in tests"),
13091309
None,
1310+
false,
13101311
).unwrap()
13111312
);
13121313

0 commit comments

Comments
 (0)