Skip to content

Commit d079551

Browse files
committed
Refactor: Don't even send out the build script stdout without -vv.
JobQueue::drain_the_queue() could thus stop checking for `extra_verbose()`.
1 parent 0b80061 commit d079551

File tree

2 files changed

+32
-39
lines changed

2 files changed

+32
-39
lines changed

src/cargo/core/compiler/custom_build.rs

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,7 @@ fn build_work<'a, 'cfg>(cx: &mut Context<'a, 'cfg>, unit: &Unit<'a>) -> CargoRes
254254
let build_scripts = super::load_build_deps(cx, unit);
255255
let kind = unit.kind;
256256
let json_messages = bcx.build_config.json_messages();
257+
let extra_verbose = bcx.config.extra_verbose();
257258

258259
// Check to see if the build script has already run, and if it has keep
259260
// track of whether it has told us about some explicit dependencies
@@ -320,17 +321,12 @@ fn build_work<'a, 'cfg>(cx: &mut Context<'a, 'cfg>, unit: &Unit<'a>) -> CargoRes
320321
state.build_plan(invocation_name, cmd.clone(), Arc::new(Vec::new()));
321322
} else {
322323
state.running(&cmd);
323-
let output = cmd.exec_with_streaming(
324-
&mut |out_line| {
325-
state.stdout(out_line);
326-
Ok(())
327-
},
328-
&mut |err_line| {
329-
state.stderr(err_line);
330-
Ok(())
331-
},
332-
true,
333-
).map_err(|e| {
324+
let output = if extra_verbose {
325+
state.capture_output(cmd, true)
326+
} else {
327+
cmd.exec_with_output()
328+
};
329+
let output = output.map_err(|e| {
334330
format_err!(
335331
"failed to run custom build command for `{}`\n{}",
336332
pkg_name,

src/cargo/core/compiler/job_queue.rs

Lines changed: 25 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use std::io;
55
use std::mem;
66
use std::sync::mpsc::{channel, Receiver, Sender};
77
use std::sync::Arc;
8+
use std::process::Output;
89

910
use crossbeam_utils;
1011
use crossbeam_utils::thread::Scope;
@@ -107,12 +108,22 @@ impl<'a> JobState<'a> {
107108
.send(Message::BuildPlanMsg(module_name, cmd, filenames));
108109
}
109110

110-
pub fn stdout(&self, out: &str) {
111-
let _ = self.tx.send(Message::Stdout(out.to_string()));
112-
}
113-
114-
pub fn stderr(&self, err: &str) {
115-
let _ = self.tx.send(Message::Stderr(err.to_string()));
111+
pub fn capture_output(
112+
&self,
113+
cmd: ProcessBuilder,
114+
print_output: bool,
115+
) -> CargoResult<Output> {
116+
cmd.exec_with_streaming(
117+
&mut |out| {
118+
let _ = self.tx.send(Message::Stdout(out.to_string()));
119+
Ok(())
120+
},
121+
&mut |err| {
122+
let _ = self.tx.send(Message::Stderr(err.to_string()));
123+
Ok(())
124+
},
125+
print_output,
126+
)
116127
}
117128
}
118129

@@ -226,7 +237,6 @@ impl<'a> JobQueue<'a> {
226237
// currently a pretty big task. This is issue #5695.
227238
let mut error = None;
228239
let mut progress = Progress::with_style("Building", ProgressStyle::Ratio, cx.bcx.config);
229-
let mut progress_maybe_changed = true; // avoid flickering due to build script
230240
if !cx.bcx.config.cli_unstable().compile_progress {
231241
progress.disable();
232242
}
@@ -274,22 +284,13 @@ impl<'a> JobQueue<'a> {
274284
// to the jobserver itself.
275285
tokens.truncate(self.active.len() - 1);
276286

277-
if progress_maybe_changed {
278-
let count = total - self.queue.len();
279-
let active_names = self.active.iter()
280-
.map(Key::name_for_progress)
281-
.collect::<Vec<_>>();
282-
drop(progress.tick_now(count, total, &format!(": {}", active_names.join(", "))));
283-
}
287+
let count = total - self.queue.len();
288+
let active_names = self.active.iter()
289+
.map(Key::name_for_progress)
290+
.collect::<Vec<_>>();
291+
drop(progress.tick_now(count, total, &format!(": {}", active_names.join(", "))));
284292
let event = self.rx.recv().unwrap();
285-
286-
progress_maybe_changed = match event {
287-
Message::Stdout(_) | Message::Stderr(_) => cx.bcx.config.extra_verbose(),
288-
_ => true,
289-
};
290-
if progress_maybe_changed {
291-
progress.clear();
292-
}
293+
progress.clear();
293294

294295
match event {
295296
Message::Run(cmd) => {
@@ -302,14 +303,10 @@ impl<'a> JobQueue<'a> {
302303
plan.update(&module_name, &cmd, &filenames)?;
303304
}
304305
Message::Stdout(out) => {
305-
if cx.bcx.config.extra_verbose() {
306-
println!("{}", out);
307-
}
306+
println!("{}", out);
308307
}
309308
Message::Stderr(err) => {
310-
if cx.bcx.config.extra_verbose() {
311-
writeln!(cx.bcx.config.shell().err(), "{}", err)?;
312-
}
309+
writeln!(cx.bcx.config.shell().err(), "{}", err)?;
313310
}
314311
Message::FixDiagnostic(msg) => {
315312
print.print(&msg)?;

0 commit comments

Comments
 (0)