@@ -8,9 +8,11 @@ use std::env;
88use std:: fs:: File ;
99use std:: io:: { self , prelude:: * } ;
1010use std:: path:: PathBuf ;
11+ use std:: process:: ExitCode ;
1112
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 ( ) ;
1416 let program = args. next ( ) . expect ( "Unexpected empty args" ) ;
1517
1618 let out_dir = PathBuf :: from (
@@ -42,7 +44,7 @@ fn main() {
4244 let mut f = io:: BufWriter :: new ( f) ;
4345
4446 ( || {
45- for arg in args {
47+ for arg in args. clone ( ) {
4648 writeln ! ( f, "{}" , arg) ?;
4749 }
4850
@@ -61,6 +63,27 @@ fn main() {
6163 )
6264 } ) ;
6365
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+
6487 // Create a file used by some tests.
6588 let path = & out_dir. join ( "libfoo.a" ) ;
6689 File :: create ( path) . unwrap_or_else ( |e| {
@@ -71,4 +94,6 @@ fn main() {
7194 e
7295 )
7396 } ) ;
97+
98+ ExitCode :: SUCCESS
7499}
0 commit comments