Skip to content

Commit

Permalink
Support -showIncludes on MSVC
Browse files Browse the repository at this point in the history
Track the `-showIncludes` flag being passed down to the compilation itself, and
then also be sure to thread the entire output of the preprocessor down to
compilations instead of just stdout. Once that was done support was implemented
by simply prepending the preprocessor stderr to the compiler stderr if the
`-showIncludes` flag was passed.
  • Loading branch information
alexcrichton committed Apr 10, 2017
1 parent 7b4c687 commit 8660519
Show file tree
Hide file tree
Showing 5 changed files with 409 additions and 195 deletions.
12 changes: 7 additions & 5 deletions src/compiler/c.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ pub struct ParsedArguments {
pub preprocessor_args: Vec<String>,
/// Commandline arguments for the preprocessor or the compiler.
pub common_args: Vec<String>,
/// Whether or not the `-showIncludes` argument is passed on MSVC
pub msvc_show_includes: bool,
}

impl ParsedArguments {
Expand All @@ -77,7 +79,7 @@ struct CCompilation<I: CCompilerImpl> {
parsed_args: ParsedArguments,
executable: String,
/// The output from running the preprocessor.
preprocessor_output: Vec<u8>,
preprocessor_result: process::Output,
compiler: I,
}

Expand Down Expand Up @@ -114,7 +116,7 @@ pub trait CCompilerImpl: Clone + fmt::Debug + Send + 'static {
fn compile<T>(&self,
creator: &T,
executable: &str,
preprocessor_output: Vec<u8>,
preprocessor_result: process::Output,
parsed_args: &ParsedArguments,
cwd: &str,
env_vars: &[(OsString, OsString)],
Expand Down Expand Up @@ -217,7 +219,7 @@ impl<T, I> CompilerHasher<T> for CCompilerHasher<I>
compilation: Box::new(CCompilation {
parsed_args: parsed_args,
executable: executable,
preprocessor_output: preprocessor_result.stdout,
preprocessor_result: preprocessor_result,
compiler: compiler,
}),
})
Expand All @@ -244,8 +246,8 @@ impl<T: CommandCreatorSync, I: CCompilerImpl> Compilation<T> for CCompilation<I>
-> SFuture<(Cacheable, process::Output)>
{
let me = *self;
let CCompilation { parsed_args, executable, preprocessor_output, compiler } = me;
compiler.compile(creator, &executable, preprocessor_output, &parsed_args, cwd, env_vars,
let CCompilation { parsed_args, executable, preprocessor_result, compiler } = me;
compiler.compile(creator, &executable, preprocessor_result, &parsed_args, cwd, env_vars,
pool)
}

Expand Down
15 changes: 9 additions & 6 deletions src/compiler/clang.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,15 @@ impl CCompilerImpl for Clang {
fn compile<T>(&self,
creator: &T,
executable: &str,
preprocessor_output: Vec<u8>,
preprocessor_result: process::Output,
parsed_args: &ParsedArguments,
cwd: &str,
env_vars: &[(OsString, OsString)],
pool: &CpuPool)
-> SFuture<(Cacheable, process::Output)>
where T: CommandCreatorSync
{
compile(creator, executable, preprocessor_output, parsed_args, cwd, env_vars, pool)
compile(creator, executable, preprocessor_result, parsed_args, cwd, env_vars, pool)
}
}

Expand All @@ -95,7 +95,7 @@ pub fn argument_takes_value(arg: &str) -> bool {

fn compile<T>(creator: &T,
executable: &str,
preprocessor_output: Vec<u8>,
preprocessor_result: process::Output,
parsed_args: &ParsedArguments,
cwd: &str,
env_vars: &[(OsString, OsString)],
Expand All @@ -111,7 +111,7 @@ fn compile<T>(creator: &T,
Some(name) => name,
None => return future::err("missing input filename".into()).boxed(),
};
write_temp_file(pool, filename.as_ref(), preprocessor_output)
write_temp_file(pool, filename.as_ref(), preprocessor_result.stdout)
};
let input = parsed_args.input.clone();
let out_file = match parsed_args.outputs.get("obj") {
Expand Down Expand Up @@ -193,6 +193,7 @@ mod test {
}
}


#[test]
fn test_parse_arguments_simple() {
let a = parses!("-c", "foo.c", "-o", "foo.o");
Expand Down Expand Up @@ -236,13 +237,14 @@ mod test {
outputs: vec![("obj", "foo.o".to_owned())].into_iter().collect::<HashMap<&'static str, String>>(),
preprocessor_args: vec!(),
common_args: vec!(),
msvc_show_includes: false,
};
let compiler = f.bins[0].to_str().unwrap();
// Compiler invocation.
next_command(&creator, Ok(MockChild::new(exit_status(0), "", "")));
let (cacheable, _) = compile(&creator,
&compiler,
vec!(),
empty_output(),
&parsed_args,
f.tempdir.path().to_str().unwrap(),
&[],
Expand All @@ -264,6 +266,7 @@ mod test {
outputs: vec![("obj", "foo.o".to_owned())].into_iter().collect::<HashMap<&'static str, String>>(),
preprocessor_args: vec!(),
common_args: stringvec!("-c", "-o", "foo.o", "-Werror=blah", "foo.c"),
msvc_show_includes: false,
};
let compiler = f.bins[0].to_str().unwrap();
// First compiler invocation fails.
Expand All @@ -272,7 +275,7 @@ mod test {
next_command(&creator, Ok(MockChild::new(exit_status(0), "", "")));
let (cacheable, output) = compile(&creator,
&compiler,
vec!(),
empty_output(),
&parsed_args,
f.tempdir.path().to_str().unwrap(),
&[],
Expand Down
Loading

0 comments on commit 8660519

Please sign in to comment.