Skip to content

Commit a0dcbd2

Browse files
authored
Use eprintln! and println! instead of writeln! with stderr (#86)
1 parent b116805 commit a0dcbd2

File tree

5 files changed

+33
-50
lines changed

5 files changed

+33
-50
lines changed

src/extensions.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
use std::io;
2-
use std::io::Write;
31
use std::process::{Command, ExitStatus};
42

53
use errors::*;
@@ -29,7 +27,7 @@ impl CommandExt for Command {
2927
/// Runs the command to completion
3028
fn run_and_get_status(&mut self, verbose: bool) -> Result<ExitStatus> {
3129
if verbose {
32-
writeln!(io::stderr(), "+ {:?}", self).ok();
30+
eprintln!("+ {:?}", self);
3331
}
3432

3533
self.status()
@@ -39,7 +37,7 @@ impl CommandExt for Command {
3937
/// Runs the command to completion and returns its stdout
4038
fn run_and_get_stdout(&mut self, verbose: bool) -> Result<String> {
4139
if verbose {
42-
writeln!(io::stderr(), "+ {:?}", self).ok();
40+
eprintln!("+ {:?}", self);
4341
}
4442

4543
let out = self

src/flock.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
//! other Cargo stuff
33
44
use std::fs::{File, OpenOptions};
5-
use std::io::Write;
65
use std::path::{Display, Path, PathBuf};
76
use std::{fs, io};
87

@@ -181,13 +180,11 @@ fn acquire(
181180
}
182181

183182
if !quiet {
184-
writeln!(
185-
io::stderr(),
183+
eprintln!(
186184
"{:>12} waiting for file lock on {}",
187185
"Blocking",
188186
msg
189187
)
190-
.ok();
191188
}
192189

193190
block()

src/lib.rs

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,9 @@ extern crate toml;
1616
extern crate walkdir;
1717

1818
use std::hash::{Hash, Hasher};
19-
use std::io::Write;
2019
use std::path::{Path, PathBuf};
2120
use std::process::ExitStatus;
22-
use std::{env, io, process};
21+
use std::{env, process};
2322

2423
use rustc_version::Channel;
2524

@@ -96,21 +95,18 @@ pub fn main_common(command_name: &str) {
9695

9796
match run(command_name) {
9897
Err(e) => {
99-
let stderr = io::stderr();
100-
let mut stderr = stderr.lock();
101-
102-
writeln!(stderr, "error: {}", e).ok();
98+
eprintln!("error: {}", e);
10399

104100
for e in e.iter().skip(1) {
105-
writeln!(stderr, "caused by: {}", e).ok();
101+
eprintln!("caused by: {}", e);
106102
}
107103

108104
if show_backtrace() {
109105
if let Some(backtrace) = e.backtrace() {
110-
writeln!(stderr, "{:?}", backtrace).ok();
106+
eprintln!("{:?}", backtrace);
111107
}
112108
} else {
113-
writeln!(stderr, "note: run with `RUST_BACKTRACE=1` for a backtrace").ok();
109+
eprintln!("note: run with `RUST_BACKTRACE=1` for a backtrace");
114110
}
115111

116112
process::exit(1)
@@ -135,12 +131,10 @@ fn run(command_name: &str) -> Result<Option<ExitStatus>> {
135131
Ok(None)
136132
}
137133
Command::Version => {
138-
writeln!(
139-
io::stdout(),
134+
println!(
140135
concat!("cargo-xbuild ", env!("CARGO_PKG_VERSION"), "{}"),
141136
include_str!(concat!(env!("OUT_DIR"), "/commit-info.txt"))
142-
)
143-
.unwrap();
137+
);
144138
Ok(None)
145139
}
146140
}

src/sysroot.rs

Lines changed: 13 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ use std::collections::hash_map::DefaultHasher;
22
use std::env;
33
use std::fs;
44
use std::hash::{Hash, Hasher};
5-
use std::io;
6-
use std::io::Write;
75
use std::path::Path;
86
use std::process::Command;
97

@@ -64,7 +62,10 @@ fn build_crate(
6462
dst: &Path,
6563
verbose: bool,
6664
) -> Result<()> {
67-
let td = Builder::new().prefix("cargo-xbuild").tempdir().chain_err(|| "couldn't create a temporary directory")?;
65+
let td = Builder::new()
66+
.prefix("cargo-xbuild")
67+
.tempdir()
68+
.chain_err(|| "couldn't create a temporary directory")?;
6869
let td_path;
6970
let td = if env::var_os("XBUILD_KEEP_TEMP").is_some() {
7071
td_path = td.into_path();
@@ -85,10 +86,13 @@ fn build_crate(
8586
}
8687

8788
util::write(&td.join("Cargo.toml"), &stoml)?;
88-
fs::copy(lockfile, &td.join("Cargo.lock")).chain_err(||
89-
format!("failed to copy Cargo.lock from `{}` to `{}`",
90-
lockfile.display(), &td.join("Cargo.lock").display())
91-
)?;
89+
fs::copy(lockfile, &td.join("Cargo.lock")).chain_err(|| {
90+
format!(
91+
"failed to copy Cargo.lock from `{}` to `{}`",
92+
lockfile.display(),
93+
&td.join("Cargo.lock").display()
94+
)
95+
})?;
9296
util::mkdir(&td.join("src"))?;
9397
util::write(&td.join("src/lib.rs"), "")?;
9498

@@ -261,7 +265,6 @@ pub fn update(
261265
verbose: bool,
262266
) -> Result<()> {
263267
let ctoml = cargo::toml(root)?;
264-
let mut stderr = io::stderr();
265268

266269
let hash = hash(cmode, rustflags, &ctoml, meta, config)?;
267270

@@ -298,14 +301,7 @@ pub fn update(
298301
&dst,
299302
) {
300303
Ok(()) => {}
301-
Err(e) => {
302-
writeln!(
303-
stderr,
304-
"Unable to copy the directory 'lib' from sysroot: {}",
305-
e
306-
)
307-
.ok();
308-
}
304+
Err(e) => eprintln!("Unable to copy the directory 'lib' from sysroot: {}", e),
309305
};
310306

311307
let bin_dst = lock.parent().join("bin");
@@ -320,14 +316,7 @@ pub fn update(
320316
&bin_dst,
321317
) {
322318
Ok(()) => {}
323-
Err(e) => {
324-
writeln!(
325-
stderr,
326-
"Unable to copy the directory 'bin' from sysroot: {}",
327-
e
328-
)
329-
.ok();
330-
}
319+
Err(e) => eprintln!("Unable to copy the directory 'bin' from sysroot: {}", e),
331320
};
332321

333322
util::write(&hfile, hash)?;

src/xargo.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
use std::io::{self, Write};
1+
use std::env;
22
use std::mem;
33
use std::path::Path;
44
use std::path::{Display, PathBuf};
55
use std::process::{Command, ExitStatus};
6-
use std::env;
76

87
use rustc_version::VersionMeta;
98

@@ -31,8 +30,8 @@ pub fn run(
3130

3231
let flags = rustflags.for_xargo(home)?;
3332
if verbose {
34-
writeln!(io::stderr(), "+ RUSTFLAGS={:?}", flags).ok();
35-
writeln!(io::stderr(), "+ RUSTDOCFLAGS={:?}", flags).ok();
33+
eprintln!("+ RUSTFLAGS={:?}", flags);
34+
eprintln!("+ RUSTDOCFLAGS={:?}", flags);
3635
}
3736
cmd.env("RUSTFLAGS", &flags);
3837
cmd.env("RUSTDOCFLAGS", &flags);
@@ -70,7 +69,13 @@ impl Home {
7069
let fs = self.path(triple);
7170

7271
fs.open_rw(".sentinel", &format!("{}'s sysroot", triple))
73-
.chain_err(|| format!("couldn't lock {}'s sysroot in {} as read-write", triple, fs.display()))
72+
.chain_err(|| {
73+
format!(
74+
"couldn't lock {}'s sysroot in {} as read-write",
75+
triple,
76+
fs.display()
77+
)
78+
})
7479
}
7580
}
7681

0 commit comments

Comments
 (0)