@@ -6,18 +6,43 @@ use std::io::prelude::*;
6
6
use std:: path:: PathBuf ;
7
7
8
8
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.
10
17
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.
12
21
if candidate. exists ( ) {
13
22
continue ;
14
23
}
15
- let mut f = File :: create ( candidate) . unwrap ( ) ;
16
- for arg in env:: args ( ) . skip ( 1 ) {
17
- writeln ! ( f, "{}" , arg) . unwrap ( ) ;
18
- }
19
24
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
+ }
21
38
break ;
22
39
}
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
+ ) ) ;
23
48
}
0 commit comments