1 // Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
11 // Test that the CompilerCalls interface to the compiler works.
13 // ignore-cross-compile
15 #![feature(rustc_private)]
19 extern crate rustc_driver;
20 extern crate rustc_codegen_utils;
22 extern crate rustc_errors as errors;
23 extern crate rustc_metadata;
25 use rustc::session::Session;
26 use rustc::session::config::{self, Input};
27 use rustc_driver::{driver, CompilerCalls, Compilation};
28 use rustc_codegen_utils::codegen_backend::CodegenBackend;
29 use rustc_metadata::cstore::CStore;
32 use std::path::PathBuf;
34 struct TestCalls<'a> {
38 impl<'a> CompilerCalls<'a> for TestCalls<'a> {
39 fn early_callback(&mut self,
43 _: &errors::registry::Registry,
44 _: config::ErrorOutputType)
50 fn late_callback(&mut self,
63 fn some_input(&mut self, input: Input, input_path: Option<PathBuf>)
64 -> (Input, Option<PathBuf>) {
69 fn no_input(&mut self,
75 _: &errors::registry::Registry)
76 -> Option<(Input, Option<PathBuf>)> {
77 panic!("This shouldn't happen");
80 fn build_controller(self: Box<Self>,
83 -> driver::CompileController<'a> {
84 panic!("This shouldn't be called");
92 let tc = TestCalls { count: &mut count };
93 // we should never get use this filename, but lets make sure they are valid args.
94 let args = vec!["compiler-calls".to_string(), "foo.rs".to_string()];
95 syntax::with_globals(|| {
96 rustc_driver::run_compiler(&args, Box::new(tc), None, None);
99 assert_eq!(count, 30);