@@ -16,7 +16,7 @@ use crate::{
16
16
Error , ErrorKind , OutputKind ,
17
17
} ;
18
18
19
- pub ( crate ) type CompilerFamilyLookupCache = HashMap < Box < Path > , ToolFamily > ;
19
+ pub ( crate ) type CompilerFamilyLookupCache = HashMap < Box < [ OsString ] > , ToolFamily > ;
20
20
21
21
/// Configuration used to represent an invocation of a C compiler.
22
22
///
@@ -116,21 +116,25 @@ impl Tool {
116
116
fn guess_family_from_stdout (
117
117
stdout : & str ,
118
118
path : & Path ,
119
+ args : & [ String ] ,
119
120
cargo_output : & CargoOutput ,
120
121
) -> Result < ToolFamily , Error > {
121
122
cargo_output. print_debug ( & stdout) ;
122
123
123
124
// https://gitlab.kitware.com/cmake/cmake/-/blob/69a2eeb9dff5b60f2f1e5b425002a0fd45b7cadb/Modules/CMakeDetermineCompilerId.cmake#L267-271
124
125
// stdin is set to null to ensure that the help output is never paginated.
125
- let accepts_cl_style_flags =
126
- run ( Command :: new ( path) . arg ( "-?" ) . stdin ( Stdio :: null ( ) ) , path, & {
126
+ let accepts_cl_style_flags = run (
127
+ Command :: new ( path) . args ( args) . arg ( "-?" ) . stdin ( Stdio :: null ( ) ) ,
128
+ path,
129
+ & {
127
130
// the errors are not errors!
128
131
let mut cargo_output = cargo_output. clone ( ) ;
129
132
cargo_output. warnings = cargo_output. debug ;
130
133
cargo_output. output = OutputKind :: Discard ;
131
134
cargo_output
132
- } )
133
- . is_ok ( ) ;
135
+ } ,
136
+ )
137
+ . is_ok ( ) ;
134
138
135
139
let clang = stdout. contains ( r#""clang""# ) ;
136
140
let gcc = stdout. contains ( r#""gcc""# ) ;
@@ -155,6 +159,7 @@ impl Tool {
155
159
156
160
fn detect_family_inner (
157
161
path : & Path ,
162
+ args : & [ String ] ,
158
163
cargo_output : & CargoOutput ,
159
164
out_dir : Option < & Path > ,
160
165
) -> Result < ToolFamily , Error > {
@@ -209,25 +214,30 @@ impl Tool {
209
214
& compiler_detect_output,
210
215
) ?;
211
216
let stdout = String :: from_utf8_lossy ( & stdout) ;
212
- guess_family_from_stdout ( & stdout, path, cargo_output)
217
+ guess_family_from_stdout ( & stdout, path, args , cargo_output)
213
218
} else {
214
- guess_family_from_stdout ( & stdout, path, cargo_output)
219
+ guess_family_from_stdout ( & stdout, path, args , cargo_output)
215
220
}
216
221
}
217
- let detect_family = |path : & Path | -> Result < ToolFamily , Error > {
218
- if let Some ( family) = cached_compiler_family. read ( ) . unwrap ( ) . get ( path) {
222
+ let detect_family = |path : & Path , args : & [ String ] | -> Result < ToolFamily , Error > {
223
+ let cache_key = [ path]
224
+ . iter ( )
225
+ . map ( |p| p. as_os_str ( ) . to_owned ( ) )
226
+ . chain ( args. iter ( ) . map ( |a| OsStr :: new ( a) . to_owned ( ) ) )
227
+ . collect ( ) ;
228
+ if let Some ( family) = cached_compiler_family. read ( ) . unwrap ( ) . get ( & cache_key) {
219
229
return Ok ( * family) ;
220
230
}
221
231
222
- let family = detect_family_inner ( path, cargo_output, out_dir) ?;
232
+ let family = { detect_family_inner ( path, args , cargo_output, out_dir) ? } ;
223
233
cached_compiler_family
224
234
. write ( )
225
235
. unwrap ( )
226
- . insert ( path . into ( ) , family) ;
236
+ . insert ( cache_key , family) ;
227
237
Ok ( family)
228
238
} ;
229
239
230
- let family = detect_family ( & path) . unwrap_or_else ( |e| {
240
+ let family = detect_family ( & path, & args ) . unwrap_or_else ( |e| {
231
241
cargo_output. print_warning ( & format_args ! (
232
242
"Compiler family detection failed due to error: {}" ,
233
243
e
0 commit comments