Skip to content

Commit

Permalink
Log when preprocessor cache cannot be used
Browse files Browse the repository at this point in the history
  • Loading branch information
glandium committed Jun 6, 2024
1 parent 31706d4 commit 02e4cb3
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 18 deletions.
12 changes: 10 additions & 2 deletions src/compiler/c.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ pub struct ParsedArguments {
/// arguments are incompatible with rewrite_includes_only
pub suppress_rewrite_includes_only: bool,
/// Arguments are incompatible with preprocessor cache mode
pub too_hard_for_preprocessor_cache_mode: bool,
pub too_hard_for_preprocessor_cache_mode: Option<OsString>,
}

impl ParsedArguments {
Expand Down Expand Up @@ -382,10 +382,18 @@ where
// Try to look for a cached preprocessing step for this compilation
// request.
let preprocessor_cache_mode_config = storage.preprocessor_cache_mode_config();
let too_hard_for_preprocessor_cache_mode =
parsed_args.too_hard_for_preprocessor_cache_mode.is_some();
if let Some(arg) = &parsed_args.too_hard_for_preprocessor_cache_mode {
debug!(
"parse_arguments: Cannot use preprocessor cache because of {:?}",
arg
);
}
// Disable preprocessor cache when doing distributed compilation
let mut preprocessor_key = if !may_dist
&& preprocessor_cache_mode_config.use_preprocessor_cache_mode
&& !parsed_args.too_hard_for_preprocessor_cache_mode
&& !too_hard_for_preprocessor_cache_mode
{
preprocessor_cache_entry_hash_key(
&executable_digest,
Expand Down
4 changes: 2 additions & 2 deletions src/compiler/diab.rs
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ where
// FIXME: Implement me.
color_mode: ColorMode::Auto,
suppress_rewrite_includes_only: false,
too_hard_for_preprocessor_cache_mode: false,
too_hard_for_preprocessor_cache_mode: None,
})
}

Expand Down Expand Up @@ -768,7 +768,7 @@ mod test {
profile_generate: false,
color_mode: ColorMode::Auto,
suppress_rewrite_includes_only: false,
too_hard_for_preprocessor_cache_mode: false,
too_hard_for_preprocessor_cache_mode: None,
};
let compiler = &f.bins[0];
// Compiler invocation.
Expand Down
22 changes: 14 additions & 8 deletions src/compiler/gcc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ where
// and interpreting it as a list of more arguments.
let it = ExpandIncludeFile::new(cwd, arguments);

let mut too_hard_for_preprocessor_cache_mode = false;
let mut too_hard_for_preprocessor_cache_mode = None;

let mut args_iter = ArgsIter::new(it, arg_info);
if kind == CCompilerKind::Clang {
Expand Down Expand Up @@ -350,7 +350,7 @@ where
}
Some(Output(p)) => output_arg = Some(p.clone()),
Some(NeedDepTarget) => {
too_hard_for_preprocessor_cache_mode = true;
too_hard_for_preprocessor_cache_mode = Some(arg.to_os_string());
need_explicit_dep_target = true;
if let DepArgumentRequirePath::NotNeeded = need_explicit_dep_argument_path {
need_explicit_dep_argument_path = DepArgumentRequirePath::Missing;
Expand Down Expand Up @@ -437,8 +437,8 @@ where
}
Some(PreprocessorArgument(_)) => {
too_hard_for_preprocessor_cache_mode = match arg.flag_str() {
Some(s) => s == "-Xpreprocessor" || s == "-Wp",
_ => false,
Some(s) if s == "-Xpreprocessor" || s == "-Wp" => Some(arg.to_os_string()),
_ => None,
};
&mut preprocessor_args
}
Expand Down Expand Up @@ -2031,7 +2031,7 @@ mod test {
profile_generate: false,
color_mode: ColorMode::Auto,
suppress_rewrite_includes_only: false,
too_hard_for_preprocessor_cache_mode: false,
too_hard_for_preprocessor_cache_mode: None,
};
let compiler = &f.bins[0];
// Compiler invocation.
Expand Down Expand Up @@ -2194,20 +2194,26 @@ mod test {
CompilerArguments::Ok(args) => args,
o => panic!("Got unexpected parse result: {:?}", o),
};
assert!(!parsed_args.too_hard_for_preprocessor_cache_mode);
assert!(parsed_args.too_hard_for_preprocessor_cache_mode.is_none());

let args = stringvec!["-c", "foo.c", "-o", "foo.o", "-Xpreprocessor", "-M"];
let parsed_args = match parse_arguments_(args, false) {
CompilerArguments::Ok(args) => args,
o => panic!("Got unexpected parse result: {:?}", o),
};
assert!(parsed_args.too_hard_for_preprocessor_cache_mode);
assert_eq!(
parsed_args.too_hard_for_preprocessor_cache_mode,
Some("-Xpreprocessor".into())
);

let args = stringvec!["-c", "foo.c", "-o", "foo.o", r#"-Wp,-DFOO="something""#];
let parsed_args = match parse_arguments_(args, false) {
CompilerArguments::Ok(args) => args,
o => panic!("Got unexpected parse result: {:?}", o),
};
assert!(parsed_args.too_hard_for_preprocessor_cache_mode);
assert_eq!(
parsed_args.too_hard_for_preprocessor_cache_mode,
Some("-Wp".into())
);
}
}
6 changes: 3 additions & 3 deletions src/compiler/msvc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -823,7 +823,7 @@ pub fn parse_arguments(
// FIXME: implement color_mode for msvc.
color_mode: ColorMode::Auto,
suppress_rewrite_includes_only: false,
too_hard_for_preprocessor_cache_mode: false,
too_hard_for_preprocessor_cache_mode: None,
})
}

Expand Down Expand Up @@ -2445,7 +2445,7 @@ mod test {
profile_generate: false,
color_mode: ColorMode::Auto,
suppress_rewrite_includes_only: false,
too_hard_for_preprocessor_cache_mode: false,
too_hard_for_preprocessor_cache_mode: None,
};
let compiler = &f.bins[0];
// Compiler invocation.
Expand Down Expand Up @@ -2530,7 +2530,7 @@ mod test {
profile_generate: false,
color_mode: ColorMode::Auto,
suppress_rewrite_includes_only: false,
too_hard_for_preprocessor_cache_mode: false,
too_hard_for_preprocessor_cache_mode: None,
};
let compiler = &f.bins[0];
// Compiler invocation.
Expand Down
6 changes: 3 additions & 3 deletions src/compiler/tasking_vx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ where
profile_generate: false,
color_mode: ColorMode::Auto,
suppress_rewrite_includes_only: false,
too_hard_for_preprocessor_cache_mode: false,
too_hard_for_preprocessor_cache_mode: None,
})
}

Expand Down Expand Up @@ -707,7 +707,7 @@ mod test {
profile_generate: false,
color_mode: ColorMode::Auto,
suppress_rewrite_includes_only: false,
too_hard_for_preprocessor_cache_mode: false,
too_hard_for_preprocessor_cache_mode: None,
};
let compiler = &f.bins[0];
// Compiler invocation.
Expand Down Expand Up @@ -756,7 +756,7 @@ mod test {
profile_generate: false,
color_mode: ColorMode::Auto,
suppress_rewrite_includes_only: false,
too_hard_for_preprocessor_cache_mode: false,
too_hard_for_preprocessor_cache_mode: None,
};
let compiler = &f.bins[0];
// Compiler invocation.
Expand Down

0 comments on commit 02e4cb3

Please sign in to comment.