From c8d0cbe1dbd5d9d12dae588571335dfc0098f72e Mon Sep 17 00:00:00 2001 From: sad-sage <98813415+sad-sage@users.noreply.github.com> Date: Thu, 9 Jun 2022 09:16:49 +0000 Subject: [PATCH] More informative 'multiple files' non-cacheable error log Sccache tends to log non-cacheable reasons with only a generic message without providing any details as to what triggered the problem. This makes it harder to troubleshoot caching issues. This commit adds a list of compiler arguments that caused the *multiple files* non-cacheable result to the logged error message. --- src/compiler/gcc.rs | 25 ++++++++++++++++++++++--- src/compiler/msvc.rs | 35 +++++++++++++++++++++++++---------- 2 files changed, 47 insertions(+), 13 deletions(-) diff --git a/src/compiler/gcc.rs b/src/compiler/gcc.rs index 88702f441..1c6bea1ef 100644 --- a/src/compiler/gcc.rs +++ b/src/compiler/gcc.rs @@ -249,6 +249,7 @@ where let mut extra_hash_files = vec![]; let mut compilation = false; let mut multiple_input = false; + let mut multiple_input_files = Vec::new(); let mut pedantic_flag = false; let mut language_extensions = true; // by default, GCC allows extensions let mut split_dwarf = false; @@ -366,6 +367,7 @@ where Argument::Raw(ref val) => { if input_arg.is_some() { multiple_input = true; + multiple_input_files.push(val.clone()); } input_arg = Some(val.clone()); } @@ -484,7 +486,10 @@ where } // Can't cache compilations with multiple inputs. if multiple_input { - cannot_cache!("multiple input files"); + cannot_cache!( + "multiple input files", + format!("{:?}", multiple_input_files) + ); } let input = match input_arg { Some(i) => i, @@ -1545,13 +1550,27 @@ mod test { } #[test] - fn test_parse_arguments_too_many_inputs() { + fn test_parse_arguments_too_many_inputs_single() { assert_eq!( - CompilerArguments::CannotCache("multiple input files", None), + CompilerArguments::CannotCache("multiple input files", Some("[\"bar.c\"]".to_string())), parse_arguments_(stringvec!["-c", "foo.c", "-o", "foo.o", "bar.c"], false) ); } + #[test] + fn test_parse_arguments_too_many_inputs_multiple() { + assert_eq!( + CompilerArguments::CannotCache( + "multiple input files", + Some("[\"bar.c\", \"baz.c\"]".to_string()) + ), + parse_arguments_( + stringvec!["-c", "foo.c", "-o", "foo.o", "bar.c", "baz.c"], + false + ) + ); + } + #[test] fn test_parse_arguments_link() { assert_eq!( diff --git a/src/compiler/msvc.rs b/src/compiler/msvc.rs index 3b91440dd..3253f4488 100644 --- a/src/compiler/msvc.rs +++ b/src/compiler/msvc.rs @@ -461,7 +461,7 @@ pub fn parse_arguments( is_clang: bool, ) -> CompilerArguments { let mut output_arg = None; - let mut input_arg: Option = None; + let mut input_arg = None; let mut common_args = vec![]; let mut preprocessor_args = vec![]; let mut dependency_args = vec![]; @@ -475,6 +475,8 @@ pub fn parse_arguments( let mut xclangs: Vec = vec![]; let mut clangs: Vec = vec![]; let mut profile_generate = false; + let mut multiple_input = false; + let mut multiple_input_files = Vec::new(); for arg in ArgsIter::new(arguments.iter().cloned(), (&ARGS[..], &SLASH_ARGS[..])) { let arg = try_or_cannot_cache!(arg, "argument parse"); @@ -517,12 +519,10 @@ pub fn parse_arguments( None => { match arg { Argument::Raw(ref val) => { - if let Some(ref input_arg) = input_arg { + if input_arg.is_some() { // Can't cache compilations with multiple inputs. - cannot_cache!( - "multiple input files or unknown argument: ", - String::from(input_arg.to_string_lossy()) - ); + multiple_input = true; + multiple_input_files.push(val.clone()); } input_arg = Some(val.clone()); } @@ -658,6 +658,13 @@ pub fn parse_arguments( if !compilation { return CompilerArguments::NotCompilation; } + // Can't cache compilations with multiple inputs. + if multiple_input { + cannot_cache!( + "multiple input files", + format!("{:?}", multiple_input_files) + ); + } let (input, language) = match input_arg { Some(i) => match Language::from_file_name(Path::new(&i)) { Some(l) => (i.to_owned(), l), @@ -1450,13 +1457,21 @@ mod test { } #[test] - fn test_parse_arguments_too_many_inputs() { + fn test_parse_arguments_too_many_inputs_single() { + assert_eq!( + CompilerArguments::CannotCache("multiple input files", Some("[\"bar.c\"]".to_string())), + parse_arguments(ovec!["-c", "foo.c", "-Fofoo.obj", "bar.c"]) + ); + } + + #[test] + fn test_parse_arguments_too_many_inputs_multiple() { assert_eq!( CompilerArguments::CannotCache( - "multiple input files or unknown argument: ", - Some("foo.c".to_string()) + "multiple input files", + Some("[\"bar.c\", \"baz.c\"]".to_string()) ), - parse_arguments(ovec!["-c", "foo.c", "-Fofoo.obj", "bar.c"]) + parse_arguments(ovec!["-c", "foo.c", "-Fofoo.obj", "bar.c", "baz.c"]) ); }