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, path)]
20 extern crate rustc_driver;
21 extern crate rustc_codegen_utils;
23 extern crate rustc_errors as errors;
24 extern crate rustc_metadata;
26 use rustc::session::Session;
27 use rustc::session::config::{self, Input};
28 use rustc_driver::{driver, CompilerCalls, Compilation};
29 use rustc_codegen_utils::codegen_backend::CodegenBackend;
30 use rustc_metadata::cstore::CStore;
33 use std::path::PathBuf;
35 struct TestCalls<'a> {
39 impl<'a> CompilerCalls<'a> for TestCalls<'a> {
40 fn early_callback(&mut self,
44 _: &errors::registry::Registry,
45 _: config::ErrorOutputType)
51 fn late_callback(&mut self,
64 fn some_input(&mut self, input: Input, input_path: Option<PathBuf>)
65 -> (Input, Option<PathBuf>) {
70 fn no_input(&mut self,
76 _: &errors::registry::Registry)
77 -> Option<(Input, Option<PathBuf>)> {
78 panic!("This shouldn't happen");
81 fn build_controller(self: Box<Self>,
84 -> driver::CompileController<'a> {
85 panic!("This shouldn't be called");
93 let tc = TestCalls { count: &mut count };
94 // we should never get use this filename, but lets make sure they are valid args.
95 let args = vec!["compiler-calls".to_string(), "foo.rs".to_string()];
96 rustc_driver::run_compiler(&args, Box::new(tc), None, None);
98 assert_eq!(count, 30);