@@ -8,14 +8,16 @@ use std::env;
8
8
use std:: fs:: File ;
9
9
use std:: io:: { self , prelude:: * } ;
10
10
use std:: path:: PathBuf ;
11
+ use std:: process:: ExitCode ;
11
12
12
- fn main ( ) {
13
- let mut args = env:: args ( ) ;
13
+ fn main ( ) -> ExitCode {
14
+ let args = env:: args ( ) . collect :: < Vec < _ > > ( ) ;
15
+ let mut args = args. iter ( ) ;
14
16
let program = args. next ( ) . expect ( "Unexpected empty args" ) ;
15
17
16
18
let out_dir = PathBuf :: from (
17
- env:: var_os ( "GCCTEST_OUT_DIR " )
18
- . unwrap_or_else ( || panic ! ( "{}: GCCTEST_OUT_DIR not found" , program) ) ,
19
+ env:: var_os ( "CC_SHIM_OUT_DIR " )
20
+ . unwrap_or_else ( || panic ! ( "{}: CC_SHIM_OUT_DIR not found" , program) ) ,
19
21
) ;
20
22
21
23
// Find the first nonexistent candidate file to which the program's args can be written.
@@ -42,7 +44,7 @@ fn main() {
42
44
let mut f = io:: BufWriter :: new ( f) ;
43
45
44
46
( || {
45
- for arg in args {
47
+ for arg in args. clone ( ) {
46
48
writeln ! ( f, "{}" , arg) ?;
47
49
}
48
50
@@ -61,6 +63,27 @@ fn main() {
61
63
)
62
64
} ) ;
63
65
66
+ if program. starts_with ( "clang" ) {
67
+ // Validate that we got no `-?` without a preceding `--driver-mode=cl`. Compiler family
68
+ // detection depends on this.
69
+ if let Some ( cl_like_help_option_idx) = args. clone ( ) . position ( |a| a == "-?" ) {
70
+ let has_cl_clang_driver_before_cl_like_help_option = args
71
+ . clone ( )
72
+ . take ( cl_like_help_option_idx)
73
+ . rev ( )
74
+ . find_map ( |a| a. strip_prefix ( "--driver-mode=" ) )
75
+ . is_some_and ( |a| a == "cl" ) ;
76
+ if has_cl_clang_driver_before_cl_like_help_option {
77
+ return ExitCode :: SUCCESS ;
78
+ } else {
79
+ eprintln ! (
80
+ "Found `-?` argument, but it was not preceded by a `--driver-mode=cl` argument."
81
+ ) ;
82
+ return ExitCode :: FAILURE ;
83
+ }
84
+ }
85
+ }
86
+
64
87
// Create a file used by some tests.
65
88
let path = & out_dir. join ( "libfoo.a" ) ;
66
89
File :: create ( path) . unwrap_or_else ( |e| {
@@ -71,4 +94,6 @@ fn main() {
71
94
e
72
95
)
73
96
} ) ;
97
+
98
+ ExitCode :: SUCCESS
74
99
}
0 commit comments