Skip to content

Commit 7496f47

Browse files
committed
Add -o/--cargo-output option to show cargo output
1 parent 870078f commit 7496f47

File tree

2 files changed

+21
-15
lines changed

2 files changed

+21
-15
lines changed

src/main.rs

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ struct Args {
5353
pkg_path: Option<String>,
5454
gen_pkg_only: bool,
5555
build_only: bool,
56+
cargo_output: bool,
5657
clear_cache: bool,
5758
debug: bool,
5859
dep: Vec<String>,
@@ -139,6 +140,11 @@ fn parse_args() -> Args {
139140
/*
140141
Options that impact the script being executed.
141142
*/
143+
.arg(Arg::with_name("cargo-output")
144+
.help("Show output from cargo when building.")
145+
.short("o")
146+
.long("cargo-output")
147+
)
142148
.arg(Arg::with_name("count")
143149
.help("Invoke the loop closure with two arguments: line, and line number.")
144150
.long("count")
@@ -279,6 +285,7 @@ fn parse_args() -> Args {
279285
pkg_path: m.value_of("pkg_path").map(Into::into),
280286
gen_pkg_only: m.is_present("gen_pkg_only"),
281287
build_only: m.is_present("build_only"),
288+
cargo_output: m.is_present("cargo-output"),
282289
clear_cache: m.is_present("clear_cache"),
283290
debug: m.is_present("debug"),
284291
dep: owned_vec_string(m.values_of("dep")),
@@ -637,13 +644,14 @@ fn gen_pkg_and_compile(input: &Input, action: &InputAction) -> MainResult<()> {
637644
&meta,
638645
)?;
639646

640-
macro_rules! get_status {
641-
($cmd:expr) => {
642-
util::suppress_child_output(&mut $cmd)?.status()
643-
};
644-
}
647+
let exit_status = if action.cargo_output {
648+
cmd.spawn()?.wait()
649+
} else {
650+
util::suppress_child_output(&mut cmd)?.status()
651+
};
645652

646-
let compile_err = get_status!(cmd)
653+
let compile_err =
654+
exit_status
647655
.map_err(Into::<MainError>::into)
648656
.and_then(|st| match st.code() {
649657
Some(0) => Ok(()),
@@ -691,6 +699,9 @@ struct InputAction {
691699
/// Compile the input into a fresh executable?
692700
compile: bool,
693701

702+
/// Always show cargo output?
703+
cargo_output: bool,
704+
694705
/**
695706
Force Cargo to do a recompile, even if it thinks it doesn't have to.
696707
@@ -853,6 +864,7 @@ fn decide_action_for(
853864

854865
let mut action = InputAction {
855866
compile: force,
867+
cargo_output: args.cargo_output,
856868
force_compile: force,
857869
emit_metadata: true,
858870
execute: !build_only,

src/util.rs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,13 @@ mod suppress_child_output {
7979
let (done_sig, done_gate) = crossbeam_channel::bounded(0);
8080

8181
let _ = thread::spawn(move || {
82-
let show_stderr;
82+
let child_failed;
8383
select! {
8484
recv(done_gate) -> success => {
85-
show_stderr = !success.unwrap_or(true);
85+
child_failed = !success.unwrap_or(true);
8686
},
8787
}
88-
if show_stderr {
88+
if child_failed {
8989
let mut stderr = stderr;
9090
io::copy(&mut stderr, &mut io::stderr()).expect("could not copy child stderr");
9191
}
@@ -94,14 +94,12 @@ mod suppress_child_output {
9494
Ok(ChildToken {
9595
child,
9696
done_sig: Some(done_sig),
97-
// stderr_join: stderr_join,
9897
})
9998
}
10099

101100
pub struct ChildToken {
102101
child: process::Child,
103102
done_sig: Option<crossbeam_channel::Sender<bool>>,
104-
// stderr_join: Option<thread::JoinHandle<()>>,
105103
}
106104

107105
impl ChildToken {
@@ -118,10 +116,6 @@ mod suppress_child_output {
118116
if let Some(done_sig) = self.done_sig.take() {
119117
done_sig.send(st.success()).unwrap();
120118
}
121-
// if let Some(stderr_join) = self.stderr_join.take() {
122-
// stderr_join.join()
123-
// .expect("child stderr thread failed");
124-
// }
125119
Ok(st)
126120
}
127121
}

0 commit comments

Comments
 (0)