Skip to content

Commit 17ef91a

Browse files
authored
Merge pull request #420 from spl/gcc-shim-expect
Improve error reporting in gcc-shim
2 parents d2ba46f + 0aee3eb commit 17ef91a

File tree

1 file changed

+32
-7
lines changed

1 file changed

+32
-7
lines changed

src/bin/gcc-shim.rs

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,43 @@ use std::io::prelude::*;
66
use std::path::PathBuf;
77

88
fn main() {
9-
let out_dir = PathBuf::from(env::var_os("GCCTEST_OUT_DIR").unwrap());
9+
let mut args = env::args();
10+
let program = args.next().expect("Unexpected empty args");
11+
12+
let out_dir = PathBuf::from(
13+
env::var_os("GCCTEST_OUT_DIR").expect(&format!("{}: GCCTEST_OUT_DIR not found", program)),
14+
);
15+
16+
// Find the first nonexistent candidate file to which the program's args can be written.
1017
for i in 0.. {
11-
let candidate = out_dir.join(format!("out{}", i));
18+
let candidate = &out_dir.join(format!("out{}", i));
19+
20+
// If the file exists, commands have already run. Try again.
1221
if candidate.exists() {
1322
continue;
1423
}
15-
let mut f = File::create(candidate).unwrap();
16-
for arg in env::args().skip(1) {
17-
writeln!(f, "{}", arg).unwrap();
18-
}
1924

20-
File::create(out_dir.join("libfoo.a")).unwrap();
25+
// Create a file and record the args passed to the command.
26+
let mut f = File::create(candidate).expect(&format!(
27+
"{}: can't create candidate: {}",
28+
program,
29+
candidate.to_string_lossy()
30+
));
31+
for arg in args {
32+
writeln!(f, "{}", arg).expect(&format!(
33+
"{}: can't write to candidate: {}",
34+
program,
35+
candidate.to_string_lossy()
36+
));
37+
}
2138
break;
2239
}
40+
41+
// Create a file used by some tests.
42+
let path = &out_dir.join("libfoo.a");
43+
File::create(path).expect(&format!(
44+
"{}: can't create libfoo.a: {}",
45+
program,
46+
path.to_string_lossy()
47+
));
2348
}

0 commit comments

Comments
 (0)