Skip to content

Commit 302867c

Browse files
committed
Clean up handling of child process
1 parent 0201e2b commit 302867c

File tree

1 file changed

+9
-19
lines changed

1 file changed

+9
-19
lines changed

src/bootstrap/bin/rustc.rs

+9-19
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
1818
use std::env;
1919
use std::path::PathBuf;
20-
use std::process::Command;
20+
use std::process::{Child, Command};
2121
use std::str::FromStr;
2222
use std::time::Instant;
2323

@@ -171,19 +171,8 @@ fn main() {
171171
let is_test = args.iter().any(|a| a == "--test");
172172
// If the user requested resource usage data, then
173173
// include that in addition to the timing output.
174-
let rusage_data = env::var_os("RUSTC_PRINT_STEP_RUSAGE").and_then(|_| {
175-
#[cfg(windows)]
176-
{
177-
use std::os::windows::io::AsRawHandle;
178-
let handle = child.as_raw_handle();
179-
format_rusage_data(handle)
180-
}
181-
#[cfg(not(windows))]
182-
{
183-
let _child = child;
184-
format_rusage_data()
185-
}
186-
});
174+
let rusage_data =
175+
env::var_os("RUSTC_PRINT_STEP_RUSAGE").and_then(|_| format_rusage_data(child));
187176
eprintln!(
188177
"[RUSTC-TIMING] {} test:{} {}.{:03}{}{}",
189178
crate_name,
@@ -221,15 +210,16 @@ fn main() {
221210
}
222211

223212
#[cfg(all(not(unix), not(windows)))]
224-
/// getrusage is not available on non-unix platforms. So for now, we do not
225-
/// bother trying to make a shim for it.
226-
fn format_rusage_data() -> Option<String> {
213+
// In the future we can add this for more platforms
214+
fn format_rusage_data(_child: Child) -> Option<String> {
227215
None
228216
}
229217

230218
#[cfg(windows)]
231-
fn format_rusage_data(handle: std::os::windows::raw::HANDLE) -> Option<String> {
219+
fn format_rusage_data(child: Child) -> Option<String> {
220+
use std::os::windows::io::AsRawHandle;
232221
use winapi::um::{processthreadsapi, psapi, timezoneapi};
222+
let handle = child.as_raw_handle();
233223
macro_rules! try_bool {
234224
($e:expr) => {
235225
if $e != 1 {
@@ -295,7 +285,7 @@ fn format_rusage_data(handle: std::os::windows::raw::HANDLE) -> Option<String> {
295285
/// fields. Note that we are focusing mainly on data that we believe to be
296286
/// supplied on Linux (the `rusage` struct has other fields in it but they are
297287
/// currently unsupported by Linux).
298-
fn format_rusage_data() -> Option<String> {
288+
fn format_rusage_data(_child: Child) -> Option<String> {
299289
let rusage: libc::rusage = unsafe {
300290
let mut recv = std::mem::zeroed();
301291
// -1 is RUSAGE_CHILDREN, which means to get the rusage for all children

0 commit comments

Comments
 (0)