Skip to content

Commit

Permalink
More informative 'multiple files' non-cacheable error log
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
sad-sage authored and sylvestre committed Sep 5, 2022
1 parent ecefa78 commit c8d0cbe
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 13 deletions.
25 changes: 22 additions & 3 deletions src/compiler/gcc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
}
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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!(
Expand Down
35 changes: 25 additions & 10 deletions src/compiler/msvc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ pub fn parse_arguments(
is_clang: bool,
) -> CompilerArguments<ParsedArguments> {
let mut output_arg = None;
let mut input_arg: Option<OsString> = None;
let mut input_arg = None;
let mut common_args = vec![];
let mut preprocessor_args = vec![];
let mut dependency_args = vec![];
Expand All @@ -475,6 +475,8 @@ pub fn parse_arguments(
let mut xclangs: Vec<OsString> = vec![];
let mut clangs: Vec<OsString> = 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");
Expand Down Expand Up @@ -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());
}
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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"])
);
}

Expand Down

0 comments on commit c8d0cbe

Please sign in to comment.