in src/compiler/tasking_vx.rs [169:300]
fn parse_arguments<S>(
arguments: &[OsString],
_cwd: &Path,
arg_info: S,
) -> CompilerArguments<ParsedArguments>
where
S: SearchableArgInfo<ArgData>,
{
let mut common_args = vec![];
let mut compilation = false;
let mut input_arg = None;
let mut multiple_input = false;
let mut output_arg = None;
let mut preprocessor_args = vec![];
let mut depfile = None;
for arg in ArgsIter::new(arguments.iter().cloned(), arg_info) {
let arg = try_or_cannot_cache!(arg, "argument parse");
match arg.get_data() {
Some(TooHardFlag) | Some(TooHard(_)) => {
cannot_cache!(arg.flag_str().expect("Can't be Argument::Raw/UnknownFlag",))
}
Some(NotCompilationFlag) | Some(NotCompilation(_)) => {
return CompilerArguments::NotCompilation
}
Some(DoCompilation) => compilation = true,
Some(Output(p)) => output_arg = Some(p.clone()),
Some(DepFile(d)) => depfile = Some(d.clone()),
Some(PreprocessorArgument(_))
| Some(PreprocessorArgumentPath(_))
| Some(PassThrough(_)) => {}
None => match arg {
Argument::Raw(ref val) => {
if input_arg.is_some() {
multiple_input = true;
}
input_arg = Some(val.clone());
}
Argument::UnknownFlag(_) => {}
_ => unreachable!(),
},
}
let args = match arg.get_data() {
Some(PassThrough(_)) => &mut common_args,
Some(DepFile(_)) => continue,
Some(PreprocessorArgument(_)) | Some(PreprocessorArgumentPath(_)) => {
&mut preprocessor_args
}
Some(DoCompilation) | Some(Output(_)) => continue,
Some(TooHardFlag)
| Some(TooHard(_))
| Some(NotCompilationFlag)
| Some(NotCompilation(_)) => unreachable!(),
None => match arg {
Argument::Raw(_) => continue,
Argument::UnknownFlag(_) => &mut common_args,
_ => unreachable!(),
},
};
// Normalize attributes such as "-I foo", "-D FOO=bar", as
// "-Ifoo", "-DFOO=bar", etc. and "-includefoo", "idirafterbar" as
// "-include foo", "-idirafter bar", etc.
let norm = match arg.flag_str() {
Some(s) if s.len() == 2 => NormalizedDisposition::Concatenated,
_ => NormalizedDisposition::Separated,
};
args.extend(arg.normalize(norm).iter_os_strings());
}
// We only support compilation.
if !compilation {
return CompilerArguments::NotCompilation;
}
// Can't cache compilations with multiple inputs.
if multiple_input {
cannot_cache!("multiple input files");
}
let input = match input_arg {
Some(i) => i,
// We can't cache compilation without an input.
None => cannot_cache!("no input file"),
};
let language = match Language::from_file_name(Path::new(&input)) {
Some(l) => l,
None => cannot_cache!("unknown source language"),
};
// --dep-file without any argument is valid too and uses the source file name
// with extension .d as depfile name
depfile = depfile.map(|d| {
if d.as_os_str().is_empty() {
Path::new(&input).with_extension("d")
} else {
d
}
});
let output = output_arg
.map(PathBuf::from)
.unwrap_or_else(|| Path::new(&input).with_extension("o"));
let mut outputs = HashMap::with_capacity(1);
outputs.insert(
"obj",
ArtifactDescriptor {
path: output,
optional: false,
},
);
CompilerArguments::Ok(ParsedArguments {
input: input.into(),
double_dash_input: false,
language,
compilation_flag: "-c".into(),
depfile,
outputs,
dependency_args: vec![],
preprocessor_args,
common_args,
arch_args: vec![],
unhashed_args: vec![],
extra_dist_files: vec![],
extra_hash_files: vec![],
msvc_show_includes: false,
profile_generate: false,
color_mode: ColorMode::Auto,
suppress_rewrite_includes_only: false,
too_hard_for_preprocessor_cache_mode: None,
})
}